From 6175c909ee036f5f926dca11ce64684a17d58ad3 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 18:00:12 -0800 Subject: [PATCH 1/9] Add new fields to parties table and raids table --- db/migrate/20220224015505_add_details_to_party.rb | 13 +++++++++++++ db/schema.rb | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20220224015505_add_details_to_party.rb diff --git a/db/migrate/20220224015505_add_details_to_party.rb b/db/migrate/20220224015505_add_details_to_party.rb new file mode 100644 index 0000000..3292af1 --- /dev/null +++ b/db/migrate/20220224015505_add_details_to_party.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index beafda1..6b52864 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_24_015505) 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,19 @@ 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.bigint "raids_id" + t.index ["raids_id"], name: "index_parties_on_raids_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" + end + create_table "summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name_en" t.string "name_jp" From bb736ce084567c7185bbf1b77ceceba4b6af2615 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 18:11:03 -0800 Subject: [PATCH 2/9] Add Raid model and add Parties as belonging to Raids --- app/models/party.rb | 1 + app/models/raid.rb | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 app/models/raid.rb diff --git a/app/models/party.rb b/app/models/party.rb index a9a0e23..f11eebc 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -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 diff --git a/app/models/raid.rb b/app/models/raid.rb new file mode 100644 index 0000000..c1065ee --- /dev/null +++ b/app/models/raid.rb @@ -0,0 +1,2 @@ +class Raid < ApplicationRecord +end From ace4fb856895e997a5615ee8814d0409a30c7250 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 18:11:19 -0800 Subject: [PATCH 3/9] Permit detail attributes and update all attributes instead of just extra --- app/controllers/api/v1/parties_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index e182104..77c6f61 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -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, :is_extra, :name, :description, :raid_id) end end \ No newline at end of file From 3cb18aa8efcddaec0da5f902b6f148403343b641 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 19:04:12 -0800 Subject: [PATCH 4/9] Add group to raids This is so that we can group them easier on the front end instead of receiving a long list --- db/migrate/20220224024415_add_group_to_raids.rb | 5 +++++ db/schema.rb | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20220224024415_add_group_to_raids.rb diff --git a/db/migrate/20220224024415_add_group_to_raids.rb b/db/migrate/20220224024415_add_group_to_raids.rb new file mode 100644 index 0000000..b256a6b --- /dev/null +++ b/db/migrate/20220224024415_add_group_to_raids.rb @@ -0,0 +1,5 @@ +class AddGroupToRaids < ActiveRecord::Migration[6.1] + def change + add_column :raids, :group, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 6b52864..dff7168 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_24_015505) do +ActiveRecord::Schema.define(version: 2022_02_24_024415) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -139,6 +139,7 @@ ActiveRecord::Schema.define(version: 2022_02_24_015505) do t.string "name_en" t.string "name_jp" t.integer "level" + t.integer "group" end create_table "summons", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| From edf489ce310efe14e939fb1fbb7700b5b9e539dc Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 19:04:34 -0800 Subject: [PATCH 5/9] Add route to get all raids --- app/controllers/api/v1/raids_controller.rb | 6 ++++++ app/views/api/v1/raids/all.json.rabl | 3 +++ app/views/api/v1/raids/base.json.rabl | 10 ++++++++++ config/routes.rb | 2 ++ 4 files changed, 21 insertions(+) create mode 100644 app/controllers/api/v1/raids_controller.rb create mode 100644 app/views/api/v1/raids/all.json.rabl create mode 100644 app/views/api/v1/raids/base.json.rabl diff --git a/app/controllers/api/v1/raids_controller.rb b/app/controllers/api/v1/raids_controller.rb new file mode 100644 index 0000000..cac3b93 --- /dev/null +++ b/app/controllers/api/v1/raids_controller.rb @@ -0,0 +1,6 @@ +class Api::V1::RaidsController < Api::V1::ApiController + def all + @raids = Raid.all() + render :all, status: :ok + end +end \ No newline at end of file diff --git a/app/views/api/v1/raids/all.json.rabl b/app/views/api/v1/raids/all.json.rabl new file mode 100644 index 0000000..b6abde3 --- /dev/null +++ b/app/views/api/v1/raids/all.json.rabl @@ -0,0 +1,3 @@ +collection @raids + +extends 'raids/base' diff --git a/app/views/api/v1/raids/base.json.rabl b/app/views/api/v1/raids/base.json.rabl new file mode 100644 index 0000000..b0909f9 --- /dev/null +++ b/app/views/api/v1/raids/base.json.rabl @@ -0,0 +1,10 @@ +object :raid + +attributes :id, :level, :group + +node :name do |r| + { + :en => r.name_en, + :jp => r.name_jp + } +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index caf5ca9..0134515 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' From 09a009ccfba3aa58a85338df059c48ca29d6bbfd Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 19:04:54 -0800 Subject: [PATCH 6/9] Add team details to all existing templates --- app/views/api/v1/parties/base.json.rabl | 6 +++++- app/views/api/v1/parties/characters.json.rabl | 6 +++++- app/views/api/v1/parties/summons.json.rabl | 6 +++++- app/views/api/v1/parties/weapons.json.rabl | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/views/api/v1/parties/base.json.rabl b/app/views/api/v1/parties/base.json.rabl index 59a493e..ff8ccea 100644 --- a/app/views/api/v1/parties/base.json.rabl +++ b/app/views/api/v1/parties/base.json.rabl @@ -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 diff --git a/app/views/api/v1/parties/characters.json.rabl b/app/views/api/v1/parties/characters.json.rabl index 0490ff6..f786b24 100644 --- a/app/views/api/v1/parties/characters.json.rabl +++ b/app/views/api/v1/parties/characters.json.rabl @@ -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) diff --git a/app/views/api/v1/parties/summons.json.rabl b/app/views/api/v1/parties/summons.json.rabl index 2728452..e2ee1c6 100644 --- a/app/views/api/v1/parties/summons.json.rabl +++ b/app/views/api/v1/parties/summons.json.rabl @@ -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) diff --git a/app/views/api/v1/parties/weapons.json.rabl b/app/views/api/v1/parties/weapons.json.rabl index 5f225bf..e64587f 100644 --- a/app/views/api/v1/parties/weapons.json.rabl +++ b/app/views/api/v1/parties/weapons.json.rabl @@ -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 From 374e294a337537f9979bf1f70337b6c74948ea9e Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 23 Feb 2022 19:22:42 -0800 Subject: [PATCH 7/9] Change permitted param for extra toggle --- app/controllers/api/v1/parties_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb index 77c6f61..d7e37e6 100644 --- a/app/controllers/api/v1/parties_controller.rb +++ b/app/controllers/api/v1/parties_controller.rb @@ -71,6 +71,6 @@ class Api::V1::PartiesController < Api::V1::ApiController end def party_params - params.require(:party).permit(:user_id, :is_extra, :name, :description, :raid_id) + params.require(:party).permit(:user_id, :extra, :name, :description, :raid_id) end end \ No newline at end of file From 49c8f55b6c8c79eb653ba729668b2f08fd164f01 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 26 Feb 2022 15:59:33 -0800 Subject: [PATCH 8/9] Add element to raids for sorting and fix raid id --- .../20220224044930_fix_raid_association_on_parties.rb | 6 ++++++ db/migrate/20220225014523_add_element_to_raids.rb | 5 +++++ db/schema.rb | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20220224044930_fix_raid_association_on_parties.rb create mode 100644 db/migrate/20220225014523_add_element_to_raids.rb diff --git a/db/migrate/20220224044930_fix_raid_association_on_parties.rb b/db/migrate/20220224044930_fix_raid_association_on_parties.rb new file mode 100644 index 0000000..3cb03c9 --- /dev/null +++ b/db/migrate/20220224044930_fix_raid_association_on_parties.rb @@ -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 diff --git a/db/migrate/20220225014523_add_element_to_raids.rb b/db/migrate/20220225014523_add_element_to_raids.rb new file mode 100644 index 0000000..752588c --- /dev/null +++ b/db/migrate/20220225014523_add_element_to_raids.rb @@ -0,0 +1,5 @@ +class AddElementToRaids < ActiveRecord::Migration[6.1] + def change + add_column :raids, :element, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index dff7168..50a3e79 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_02_24_024415) 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" @@ -130,8 +130,7 @@ ActiveRecord::Schema.define(version: 2022_02_24_024415) do t.boolean "extra", default: false, null: false t.string "name" t.text "description" - t.bigint "raids_id" - t.index ["raids_id"], name: "index_parties_on_raids_id" + t.uuid "raid_id" t.index ["user_id"], name: "index_parties_on_user_id" end @@ -140,6 +139,7 @@ ActiveRecord::Schema.define(version: 2022_02_24_024415) do 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| From 5dd25e1953d2fd7d2bb9ff57c8e0f23a07761ca7 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 26 Feb 2022 15:59:41 -0800 Subject: [PATCH 9/9] Add element to raid json template --- app/views/api/v1/raids/base.json.rabl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/raids/base.json.rabl b/app/views/api/v1/raids/base.json.rabl index b0909f9..416b978 100644 --- a/app/views/api/v1/raids/base.json.rabl +++ b/app/views/api/v1/raids/base.json.rabl @@ -1,6 +1,6 @@ object :raid -attributes :id, :level, :group +attributes :id, :level, :group, :element node :name do |r| {