上映会のし組み作り(#295) (#296)
#295 #295 #295 #295 #295 #295 #295 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #296
This commit was merged in pull request #296.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
class TheatresController < ApplicationController
|
||||
def show
|
||||
theatre = Theatre.find_by(id: params[:id])
|
||||
return head :not_found unless theatre
|
||||
|
||||
render json: TheatreRepr.base(theatre)
|
||||
end
|
||||
|
||||
def watching
|
||||
return head :unauthorized unless current_user
|
||||
|
||||
theatre = Theatre.find_by(id: params[:id])
|
||||
return head :not_found unless theatre
|
||||
|
||||
host_flg = false
|
||||
post_id = nil
|
||||
post_started_at = nil
|
||||
|
||||
theatre.with_lock do
|
||||
TheatreWatchingUser.find_or_initialize_by(theatre:, user: current_user).tap {
|
||||
_1.expires_at = 30.seconds.from_now
|
||||
}.save!
|
||||
|
||||
if (!(theatre.host_user_id?) ||
|
||||
!(theatre.watching_users.exists?(id: theatre.host_user_id)))
|
||||
theatre.update!(host_user_id: current_user.id)
|
||||
end
|
||||
|
||||
host_flg = theatre.host_user_id == current_user.id
|
||||
post_id = theatre.current_post_id
|
||||
post_started_at = theatre.current_post_started_at
|
||||
end
|
||||
|
||||
render json: { host_flg:, post_id:, post_started_at: }
|
||||
end
|
||||
|
||||
def next_post
|
||||
return head :unauthorized unless current_user
|
||||
|
||||
theatre = Theatre.find_by(id: params[:id])
|
||||
return head :not_found unless theatre
|
||||
return head :forbidden if theatre.host_user != current_user
|
||||
|
||||
post = Post.where("url LIKE '%nicovideo.jp%'")
|
||||
.or(Post.where("url LIKE '%youtube.com%'"))
|
||||
.order('RAND()')
|
||||
.first
|
||||
theatre.update!(current_post: post, current_post_started_at: Time.current)
|
||||
|
||||
head :no_content
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user