Add models, controllers and templates for Character objects

This commit is contained in:
Justin Edmund 2020-10-19 03:55:53 -07:00
parent 33cd9a9ce1
commit 4bf7249d41
7 changed files with 127 additions and 2 deletions

View file

@ -0,0 +1,32 @@
class Api::V1::GridCharactersController < Api::V1::ApiController
def create
party = Party.find(character_params[:party_id])
canonical_charactercter = Character.find(character_params[:character_id])
if current_user
if party.user != current_user
render_unauthorized_response
end
end
if grid_character = GridCharacter.where(
party_id: party.id,
position: character_params[:position]
).first
GridCharacter.destroy(grid_character.id)
end
@character = GridCharacter.create!(character_params.merge(party_id: party.id, character_id: canonical_character.id))
render :show, status: :created if @character.save!
end
def destroy
end
private
# Specify whitelisted properties that can be modified.
def character_params
params.require(:character).permit(:party_id, :character_id, :position)
end
end

11
app/models/character.rb Normal file
View file

@ -0,0 +1,11 @@
class Character < ApplicationRecord
include PgSearch::Model
pg_search_scope :search,
against: [:name_en, :name_jp],
using: {
tsearch: {
prefix: true
}
}
end

View file

@ -0,0 +1,7 @@
class GridCharacter < ApplicationRecord
belongs_to :party
def character
Character.find(self.character_id)
end
end

View file

@ -0,0 +1,65 @@
object :summon
attributes :id,
:granblue_id,
:rarity,
:element,
:gender,
:max_level
node :name do |w|
{
:en => w.name_en,
:jp => w.name_jp
}
end
node :uncap do |w|
{
:flb => w.flb
}
end
node :hp do |w|
{
:min_hp => w.min_hp,
:max_hp => w.max_hp,
:max_hp_flb => w.max_hp_flb
}
end
node :atk do |w|
{
:min_atk => w.min_atk,
:max_atk => w.max_atk,
:max_atk_flb => w.max_atk_flb
}
end
node :race do |w|
[
w.race1,
w.race2
]
end
node :proficiency do |w|
[
w.proficiency1,
w.proficiency2
]
end
node :data do |w|
{
:base_da => w.base_da,
:base_ta => w.base_ta,
}
end
node :ougi_ratio do |w|
{
:ougi_ratio => w.ougi_ratio,
:ougi_ratio_flb => w.ougi_ratio_flb
}
end

View file

@ -0,0 +1,7 @@
attributes :id,
:party_id,
:position
node :character do |c|
partial("characters/base", :object => c.character)
end

View file

@ -0,0 +1,3 @@
object @character
extends 'api/v1/grid_characters/base'

View file

@ -4,6 +4,6 @@ attributes :id,
:friend,
:position
node :summon do |w|
partial('summons/base', :object => w.summon)
node :summon do |s|
partial('summons/base', :object => s.summon)
end