commit
3841c4f76c
10 changed files with 52 additions and 11 deletions
|
|
@ -17,6 +17,12 @@ class Api::V1::GridWeaponsController < Api::V1::ApiController
|
|||
end
|
||||
|
||||
@weapon = GridWeapon.create!(weapon_params.merge(party_id: party.id, weapon_id: canonical_weapon.id))
|
||||
|
||||
if (@weapon.position == -1)
|
||||
party.element = @weapon.weapon.element
|
||||
party.save!
|
||||
end
|
||||
|
||||
render :show, status: :created if @weapon.save!
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
class Api::V1::PartiesController < Api::V1::ApiController
|
||||
before_action :set_from_slug, except: ['create', 'update']
|
||||
before_action :set_from_slug, except: ['create', 'update', 'index']
|
||||
before_action :set, only: ['update', 'destroy']
|
||||
|
||||
def index
|
||||
parties = Party.all
|
||||
end
|
||||
|
||||
def create
|
||||
@party = Party.new(shortcode: random_string)
|
||||
@party.extra = party_params['extra']
|
||||
|
|
@ -53,6 +49,20 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
|||
render :characters, status: :ok
|
||||
end
|
||||
|
||||
def index
|
||||
now = DateTime.current
|
||||
start_time = (now - params['recency'].to_i.seconds).to_datetime.beginning_of_day unless request.params['recency'].blank?
|
||||
|
||||
conditions = {}
|
||||
conditions[:element] = request.params['element'] unless request.params['element'].blank?
|
||||
conditions[:raid] = request.params['raid'] unless request.params['raid'].blank?
|
||||
conditions[:created_at] = start_time..now unless request.params['recency'].blank?
|
||||
|
||||
@parties = Party.where(conditions)
|
||||
|
||||
render :all, status: :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def random_string
|
||||
|
|
|
|||
3
app/views/api/v1/parties/all.json.rabl
Normal file
3
app/views/api/v1/parties/all.json.rabl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
collection @parties
|
||||
|
||||
extends 'parties/base'
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
object :party
|
||||
|
||||
attributes :id, :user_id, :name, :description, :shortcode, :created_at, :updated_at
|
||||
attributes :id, :name, :description, :element, :shortcode, :created_at, :updated_at
|
||||
|
||||
node :is_extra do |p|
|
||||
p.extra
|
||||
end
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
end
|
||||
|
||||
node :raid do |p|
|
||||
partial('raids/base', :object => p.raid)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
object @party
|
||||
|
||||
attributes :id, :user_id, :name, :description, :shortcode
|
||||
attributes :id, :name, :description, :shortcode
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
end
|
||||
|
||||
node :raid do |p|
|
||||
partial('raids/base', :object => p.raid)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
object @party
|
||||
|
||||
attributes :id, :user_id, :name, :description, :shortcode
|
||||
attributes :id, :name, :description, :shortcode
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
end
|
||||
|
||||
node :raid do |p|
|
||||
partial('raids/base', :object => p.raid)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
object @party
|
||||
|
||||
attributes :id, :user_id, :name, :description, :shortcode
|
||||
attributes :id, :name, :description, :shortcode
|
||||
|
||||
node :user do |p|
|
||||
partial('users/base', :object => p.user)
|
||||
end
|
||||
|
||||
node :raid do |p|
|
||||
partial('raids/base', :object => p.raid)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ Rails.application.routes.draw do
|
|||
get 'parties/:id/weapons', to: 'parties#weapons'
|
||||
get 'parties/:id/summons', to: 'parties#summons'
|
||||
get 'parties/:id/characters', to: 'parties#characters'
|
||||
get 'parties/all', to: 'parties#all'
|
||||
|
||||
post 'check/email', to: 'users#check_email'
|
||||
post 'check/username', to: 'users#check_username'
|
||||
|
|
|
|||
5
db/migrate/20220227042147_add_element_to_parties.rb
Normal file
5
db/migrate/20220227042147_add_element_to_parties.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddElementToParties < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :parties, :element, :integer
|
||||
end
|
||||
end
|
||||
|
|
@ -10,12 +10,11 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_02_25_014523) do
|
||||
ActiveRecord::Schema.define(version: 2022_02_27_042147) 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"
|
||||
|
|
@ -132,6 +131,7 @@ ActiveRecord::Schema.define(version: 2022_02_25_014523) do
|
|||
t.string "name"
|
||||
t.text "description"
|
||||
t.uuid "raid_id"
|
||||
t.integer "element"
|
||||
t.index ["user_id"], name: "index_parties_on_user_id"
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue