Merge pull request #3 from jedmund/team-details

Add the ability to add details to teams
This commit is contained in:
Justin Edmund 2022-02-26 16:00:03 -08:00 committed by GitHub
commit 58173606ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 87 additions and 8 deletions

View file

@ -25,7 +25,7 @@ class Api::V1::PartiesController < Api::V1::ApiController
if @party.user != current_user
render_unauthorized_response
else
@party.extra = party_params['is_extra']
@party.attributes = party_params
render :update, status: :ok if @party.save!
end
end
@ -71,6 +71,6 @@ class Api::V1::PartiesController < Api::V1::ApiController
end
def party_params
params.require(:party).permit(:user_id, :is_extra)
params.require(:party).permit(:user_id, :extra, :name, :description, :raid_id)
end
end

View file

@ -0,0 +1,6 @@
class Api::V1::RaidsController < Api::V1::ApiController
def all
@raids = Raid.all()
render :all, status: :ok
end
end

View file

@ -1,6 +1,7 @@
class Party < ApplicationRecord
##### ActiveRecord Associations
belongs_to :user, optional: true
belongs_to :raid, optional: true
has_many :characters, foreign_key: "party_id", class_name: "GridCharacter", dependent: :destroy
has_many :weapons, foreign_key: "party_id", class_name: "GridWeapon", dependent: :destroy
has_many :summons, foreign_key: "party_id", class_name: "GridSummon", dependent: :destroy

2
app/models/raid.rb Normal file
View file

@ -0,0 +1,2 @@
class Raid < ApplicationRecord
end

View file

@ -1,11 +1,15 @@
object :party
attributes :id, :user_id, :shortcode
attributes :id, :user_id, :name, :description, :shortcode
node :is_extra do |p|
p.extra
end
node :raid do |p|
partial('raids/base', :object => p.raid)
end
node :characters do |p|
partial('grid_characters/base', :object => p.characters)
end

View file

@ -1,6 +1,10 @@
object @party
attributes :id, :user_id, :shortcode
attributes :id, :user_id, :name, :description, :shortcode
node :raid do |p|
partial('raids/base', :object => p.raid)
end
node :characters do |p|
partial('grid_characters/base', :object => p.characters)

View file

@ -1,6 +1,10 @@
object @party
attributes :id, :user_id, :shortcode
attributes :id, :user_id, :name, :description, :shortcode
node :raid do |p|
partial('raids/base', :object => p.raid)
end
node :summons do |p|
partial('grid_summons/base', :object => p.summons)

View file

@ -1,6 +1,10 @@
object @party
attributes :id, :user_id, :shortcode
attributes :id, :user_id, :name, :description, :shortcode
node :raid do |p|
partial('raids/base', :object => p.raid)
end
node :is_extra do |p|
p.extra

View file

@ -0,0 +1,3 @@
collection @raids
extends 'raids/base'

View file

@ -0,0 +1,10 @@
object :raid
attributes :id, :level, :group, :element
node :name do |r|
{
:en => r.name_en,
:jp => r.name_jp
}
end

View file

@ -20,6 +20,8 @@ Rails.application.routes.draw do
get 'search/weapons', to: 'search#weapons'
get 'search/summons', to: 'search#summons'
get 'raids', to: 'raids#all'
post 'characters', to: 'grid_characters#create'
post 'characters/update_uncap', to: 'grid_characters#update_uncap_level'
delete 'characters', to: 'grid_characters#destroy'

View file

@ -0,0 +1,13 @@
class AddDetailsToParty < ActiveRecord::Migration[6.1]
def change
create_table :raids, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
t.string :name_en
t.string :name_jp
t.integer :level
end
add_column :parties, :name, :string
add_column :parties, :description, :text
add_reference :parties, :raids, index: true
end
end

View file

@ -0,0 +1,5 @@
class AddGroupToRaids < ActiveRecord::Migration[6.1]
def change
add_column :raids, :group, :integer
end
end

View file

@ -0,0 +1,6 @@
class FixRaidAssociationOnParties < ActiveRecord::Migration[6.1]
def change
add_column :parties, :raid_id, :uuid
remove_column :parties, :raids_id, :bigint
end
end

View file

@ -0,0 +1,5 @@
class AddElementToRaids < ActiveRecord::Migration[6.1]
def change
add_column :raids, :element, :integer
end
end

View file

@ -10,12 +10,11 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_02_23_213548) do
ActiveRecord::Schema.define(version: 2022_02_25_014523) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
enable_extension "timescaledb"
create_table "characters", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name_en"
@ -129,9 +128,20 @@ ActiveRecord::Schema.define(version: 2022_02_23_213548) do
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.boolean "extra", default: false, null: false
t.string "name"
t.text "description"
t.uuid "raid_id"
t.index ["user_id"], name: "index_parties_on_user_id"
end
create_table "raids", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name_en"
t.string "name_jp"
t.integer "level"
t.integer "group"
t.integer "element"
end
create_table "summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name_en"
t.string "name_jp"