Add models, controllers and templates for Character objects
This commit is contained in:
parent
33cd9a9ce1
commit
4bf7249d41
7 changed files with 127 additions and 2 deletions
32
app/controllers/api/v1/grid_characters_controller.rb
Normal file
32
app/controllers/api/v1/grid_characters_controller.rb
Normal 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
11
app/models/character.rb
Normal 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
|
||||||
7
app/models/grid_character.rb
Normal file
7
app/models/grid_character.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
class GridCharacter < ApplicationRecord
|
||||||
|
belongs_to :party
|
||||||
|
|
||||||
|
def character
|
||||||
|
Character.find(self.character_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
65
app/views/api/v1/characters/base.json.rabl
Normal file
65
app/views/api/v1/characters/base.json.rabl
Normal 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
|
||||||
7
app/views/api/v1/grid_characters/base.json.rabl
Normal file
7
app/views/api/v1/grid_characters/base.json.rabl
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
attributes :id,
|
||||||
|
:party_id,
|
||||||
|
:position
|
||||||
|
|
||||||
|
node :character do |c|
|
||||||
|
partial("characters/base", :object => c.character)
|
||||||
|
end
|
||||||
3
app/views/api/v1/grid_characters/show.json.rabl
Normal file
3
app/views/api/v1/grid_characters/show.json.rabl
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
object @character
|
||||||
|
|
||||||
|
extends 'api/v1/grid_characters/base'
|
||||||
|
|
@ -4,6 +4,6 @@ attributes :id,
|
||||||
:friend,
|
:friend,
|
||||||
:position
|
:position
|
||||||
|
|
||||||
node :summon do |w|
|
node :summon do |s|
|
||||||
partial('summons/base', :object => w.summon)
|
partial('summons/base', :object => s.summon)
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue