Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参加イベントの一覧、詳細、キャンセルの追加 #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ client_user GET /client/users/:id(.:format)
PUT /client/users/:id(.:format) client/users#update
DELETE /client/users/:id(.:format) client/users#destroy
```
### ユーザーの参加イベント管理
※Client::JoinSchedules#index ユーザーの参加イベント一覧
※Client::JoinSchedules#show ユーザーの参加イベント詳細
※Client::JoinSchedules#destroy イベントの参加キャンセル
```
client_user_join_schedules GET /client/users/:user_id/join_schedules(.:format) client/join_schedules#index {:format=>:json}
client_user_join_schedule GET /client/users/:user_id/join_schedules/:id(.:format) client/join_schedules#show {:format=>:json}
DELETE /client/users/:user_id/join_schedules/:id(.:format) client/join_schedules#destroy {:format=>:json}
```
### イベント
※パラメータはコードを読んでね
```
Expand Down
31 changes: 31 additions & 0 deletions app/controllers/client/join_schedules_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Client::JoinSchedulesController < Client::ApplicationController
before_action :set_user, only: %i(index show destroy)

def index
render json: @user.join_schedules
end

def show
join_schedule = @user.join_schedules.find(params[:id])
render json: join_schedule
end

def destroy
begin
user_to_event_schedule = @user.user_to_event_schedules.find_by(event_schedule_id: params[:id])
user_to_event_schedule.destroy
rescue => e
puts e
result = 'Error'
else
result = 'OK'
end
render json: result
end

private

def set_user
@user = User.with_relation.find(params[:user_id])
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Rails.application.routes.draw do
namespace :client, defaults: { format: :json } do
resources :users do
resources :join_schedules, only: %i(index show destroy)
member do
put :password
end
Expand Down