Merge pull request 'Define an endpoint to create new guests' (#137) from api-create-guest into main
Some checks failed
Check usage of free licenses / check-licenses (push) Successful in 1m1s
Run unit tests / unit_tests (push) Successful in 2m54s
Build Nginx-based docker image / build-static-assets (push) Failing after 15m35s

Reviewed-on: #137
This commit is contained in:
bustikiller 2024-11-17 10:51:01 +00:00
commit 29c9764450
4 changed files with 38 additions and 1 deletions

View File

@ -10,6 +10,11 @@ class GuestsController < ApplicationController
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
end
def create
Guest.create!(params.require(:guest).permit(:name, :group_id, :status))
render json: {}, status: :created
end
def update
Guest.find(params[:id]).update!(params.require(:guest).permit(:name))
render json: {}, status: :ok

View File

@ -4,7 +4,7 @@ Rails.application.routes.draw do
mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs'
resources :groups, only: :index
resources :guests, only: %i[index update] do
resources :guests, only: %i[index create update] do
post :bulk_update, on: :collection
end
resources :expenses, only: %i[index update] do

View File

@ -52,6 +52,30 @@ RSpec.describe 'guests', type: :request do
xit
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
path '/guests/{id}' do

View File

@ -17,6 +17,14 @@ module SwaggerResponseHelper
end
end
def response_empty_201
response(201, 'Created') do
produces 'application/json'
schema type: :object
xit
end
end
def response_404
response(404, 'Record not found') do
produces 'application/json'