Define an endpoint to create new guests
This commit is contained in:
parent
b008777c20
commit
1b2c0f0d0a
@ -10,6 +10,11 @@ class GuestsController < ApplicationController
|
|||||||
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
|
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
Guest.create!(params.require(:guest).permit(:name, :group_id, :status))
|
||||||
|
render json: {}, status: :created
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
Guest.find(params[:id]).update!(params.require(:guest).permit(:name))
|
Guest.find(params[:id]).update!(params.require(:guest).permit(:name))
|
||||||
render json: {}, status: :ok
|
render json: {}, status: :ok
|
||||||
|
@ -4,7 +4,7 @@ Rails.application.routes.draw do
|
|||||||
mount Rswag::Ui::Engine => '/api-docs'
|
mount Rswag::Ui::Engine => '/api-docs'
|
||||||
mount Rswag::Api::Engine => '/api-docs'
|
mount Rswag::Api::Engine => '/api-docs'
|
||||||
resources :groups, only: :index
|
resources :groups, only: :index
|
||||||
resources :guests, only: %i[index update] do
|
resources :guests, only: %i[index create update] do
|
||||||
post :bulk_update, on: :collection
|
post :bulk_update, on: :collection
|
||||||
end
|
end
|
||||||
resources :expenses, only: %i[index update] do
|
resources :expenses, only: %i[index update] do
|
||||||
|
@ -52,6 +52,30 @@ RSpec.describe 'guests', type: :request do
|
|||||||
xit
|
xit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
post('create guest') do
|
||||||
|
tags 'Guests'
|
||||||
|
consumes 'application/json'
|
||||||
|
produces 'application/json'
|
||||||
|
parameter name: :body, in: :body, schema: {
|
||||||
|
type: :object,
|
||||||
|
required: %i[guest],
|
||||||
|
properties: {
|
||||||
|
guest: {
|
||||||
|
type: :object,
|
||||||
|
required: %i[name group_id status],
|
||||||
|
properties: {
|
||||||
|
name: { type: :string },
|
||||||
|
group_id: { type: :string, format: :uuid },
|
||||||
|
status: { type: :string, enum: Guest.statuses.keys }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response_empty_201
|
||||||
|
response_422
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
path '/guests/{id}' do
|
path '/guests/{id}' do
|
||||||
|
@ -17,6 +17,14 @@ module SwaggerResponseHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def response_empty_201
|
||||||
|
response(201, 'Created') do
|
||||||
|
produces 'application/json'
|
||||||
|
schema type: :object
|
||||||
|
xit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def response_404
|
def response_404
|
||||||
response(404, 'Record not found') do
|
response(404, 'Record not found') do
|
||||||
produces 'application/json'
|
produces 'application/json'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user