Add Summon and GridSummons model and controllers

This commit is contained in:
Justin Edmund 2020-10-18 22:24:28 -07:00
parent 4e3c628c8d
commit 132f676e2a
9 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,32 @@
class Api::V1::GridSummonsController < Api::V1::ApiController
def create
party = Party.find(summon_params[:party_id])
canonical_summon = Summon.find(summon_params[:summon_id])
if current_user
if party.user != current_user
render_unauthorized_response
end
end
if grid_summon = GridSummon.where(
party_id: party.id,
position: summon_params[:position]
).first
GridSummon.destroy(grid_summon.id)
end
@summon = GridSummon.create!(summon_params.merge(party_id: party.id, summon_id: canonical_summon.id))
render :show, status: :created if @summon.save!
end
def destroy
end
private
# Specify whitelisted properties that can be modified.
def summon_params
params.require(:summon).permit(:party_id, :summon_id, :position, :main, :friend)
end
end

View file

@ -0,0 +1,7 @@
class GridSummon < ApplicationRecord
belongs_to :party
def summon
Summon.find(self.summon_id)
end
end

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

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

View file

@ -0,0 +1,9 @@
attributes :id,
:party_id,
:main,
:friend,
:position
node :summon do |w|
partial('summons/base', :object => w.summon)
end

View file

@ -0,0 +1,3 @@
object @summon
extends 'api/v1/grid_summons/base'

View file

@ -0,0 +1,3 @@
collection @summons, :object_root => false
extends 'summons/base'

View file

@ -0,0 +1,39 @@
object :summon
attributes :id,
:granblue_id,
:element,
:rarity,
:max_level
node :name do |w|
{
:en => w.name_en,
:jp => w.name_jp
}
end
node :uncap do |w|
{
:flb => w.flb,
:ulb => w.ulb
}
end
node :hp do |w|
{
:min_hp => w.min_hp,
:max_hp => w.max_hp,
:max_hp_flb => w.max_hp_flb,
:max_hp_ulb => w.max_hp_ulb
}
end
node :atk do |w|
{
:min_atk => w.min_atk,
:max_atk => w.max_atk,
:max_atk_flb => w.max_atk_flb,
:max_atk_ulb => w.max_atk_ulb
}
end

View file

@ -0,0 +1,26 @@
class CreateSummons < ActiveRecord::Migration[6.0]
def change
create_table :summons, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
t.string :name_en
t.string :name_jp
t.integer :granblue_id
t.integer :rarity
t.integer :element
t.string :series
t.boolean :flb
t.boolean :ulb
t.integer :max_level
t.integer :min_hp
t.integer :max_hp
t.integer :max_hp_flb
t.integer :max_hp_ulb
t.integer :min_atk
t.integer :max_atk
t.integer :max_atk_flb
t.integer :max_atk_ulb
end
end
end

View file

@ -0,0 +1,15 @@
class CreateGridSummons < ActiveRecord::Migration[6.0]
def change
create_table :grid_summons, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
t.references :party, type: :uuid
t.references :summon, type: :uuid
t.integer :uncap_level
t.boolean :main
t.boolean :friend
t.integer :position
t.timestamps
end
end
end