Add route for updating parties
This commit is contained in:
parent
818a756f28
commit
9d4706b741
3 changed files with 22 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
class Api::V1::PartiesController < Api::V1::ApiController
|
class Api::V1::PartiesController < Api::V1::ApiController
|
||||||
before_action :set, except: ['create']
|
before_action :set_from_slug, except: ['create', 'update']
|
||||||
|
before_action :set, only: ['update', 'destroy']
|
||||||
|
|
||||||
def index
|
def index
|
||||||
parties = Party.all
|
parties = Party.all
|
||||||
|
|
@ -21,6 +22,12 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
if @party.user != current_user
|
||||||
|
render_unauthorized_response
|
||||||
|
else
|
||||||
|
@party.extra = party_params['is_extra']
|
||||||
|
render :update, status: :ok if @party.save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
@ -49,10 +56,15 @@ class Api::V1::PartiesController < Api::V1::ApiController
|
||||||
return (0...numChars).map { o[rand(o.length)] }.join
|
return (0...numChars).map { o[rand(o.length)] }.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def set
|
def set_from_slug
|
||||||
@party = Party.where("shortcode = ?", params[:id]).first
|
@party = Party.where("shortcode = ?", params[:id]).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set
|
||||||
|
ap params
|
||||||
|
@party = Party.where("id = ?", params[:id]).first
|
||||||
|
end
|
||||||
|
|
||||||
def party_params
|
def party_params
|
||||||
params.require(:party).permit(:user_id, :is_extra)
|
params.require(:party).permit(:user_id, :is_extra)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
7
app/views/api/v1/parties/update.json.rabl
Normal file
7
app/views/api/v1/parties/update.json.rabl
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
object @party
|
||||||
|
|
||||||
|
attributes :id, :user_id, :shortcode
|
||||||
|
|
||||||
|
node :is_extra do |p|
|
||||||
|
p.extra
|
||||||
|
end
|
||||||
|
|
@ -6,7 +6,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
namespace :api, defaults: { format: :json } do
|
namespace :api, defaults: { format: :json } do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :parties, only: [:index, :create, :show, :destroy]
|
resources :parties, only: [:index, :create, :show, :update, :destroy]
|
||||||
resources :users, only: [:create, :show]
|
resources :users, only: [:create, :show]
|
||||||
|
|
||||||
get 'parties/:id/weapons', to: 'parties#weapons'
|
get 'parties/:id/weapons', to: 'parties#weapons'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue