diff --git a/app/controllers/api/v1/grid_characters_controller.rb b/app/controllers/api/v1/grid_characters_controller.rb new file mode 100644 index 0000000..8a682ed --- /dev/null +++ b/app/controllers/api/v1/grid_characters_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/character.rb b/app/models/character.rb new file mode 100644 index 0000000..cced1fd --- /dev/null +++ b/app/models/character.rb @@ -0,0 +1,11 @@ +class Character < ApplicationRecord + include PgSearch::Model + + pg_search_scope :search, + against: [:name_en, :name_jp], + using: { + tsearch: { + prefix: true + } + } +end diff --git a/app/models/grid_character.rb b/app/models/grid_character.rb new file mode 100644 index 0000000..6ac365c --- /dev/null +++ b/app/models/grid_character.rb @@ -0,0 +1,7 @@ +class GridCharacter < ApplicationRecord + belongs_to :party + + def character + Character.find(self.character_id) + end +end diff --git a/app/views/api/v1/characters/base.json.rabl b/app/views/api/v1/characters/base.json.rabl new file mode 100644 index 0000000..572660a --- /dev/null +++ b/app/views/api/v1/characters/base.json.rabl @@ -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 \ No newline at end of file diff --git a/app/views/api/v1/grid_characters/base.json.rabl b/app/views/api/v1/grid_characters/base.json.rabl new file mode 100644 index 0000000..20bb2d3 --- /dev/null +++ b/app/views/api/v1/grid_characters/base.json.rabl @@ -0,0 +1,7 @@ +attributes :id, + :party_id, + :position + +node :character do |c| + partial("characters/base", :object => c.character) +end \ No newline at end of file diff --git a/app/views/api/v1/grid_characters/show.json.rabl b/app/views/api/v1/grid_characters/show.json.rabl new file mode 100644 index 0000000..ca858d8 --- /dev/null +++ b/app/views/api/v1/grid_characters/show.json.rabl @@ -0,0 +1,3 @@ +object @character + +extends 'api/v1/grid_characters/base' \ No newline at end of file diff --git a/app/views/api/v1/grid_summons/base.json.rabl b/app/views/api/v1/grid_summons/base.json.rabl index 696d7be..c947c54 100644 --- a/app/views/api/v1/grid_summons/base.json.rabl +++ b/app/views/api/v1/grid_summons/base.json.rabl @@ -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 \ No newline at end of file