2adff3966a
#297 #297 #297 #297 #297 Merge remote-tracking branch 'origin/main' into feature/297 #297 #297 #297 #297 #297 #297 #297 #297 #297 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #299
33 lines
897 B
Ruby
33 lines
897 B
Ruby
class TheatreCommentsController < ApplicationController
|
|
def index
|
|
no_gt = params[:no_gt].to_i
|
|
no_gt = 0 if no_gt.negative?
|
|
|
|
comments = TheatreComment
|
|
.where(theatre_id: params[:theatre_id])
|
|
.where('no > ?', no_gt)
|
|
.order(no: :desc)
|
|
|
|
render json: comments.as_json(include: { user: { only: [:id, :name] } })
|
|
end
|
|
|
|
def create
|
|
return head :unauthorized unless current_user
|
|
|
|
content = params[:content]
|
|
return head :unprocessable_entity if content.blank?
|
|
|
|
theatre = Theatre.find_by(id: params[:theatre_id])
|
|
return head :not_found unless theatre
|
|
|
|
comment = nil
|
|
theatre.with_lock do
|
|
no = theatre.next_comment_no
|
|
comment = TheatreComment.create!(theatre:, no:, user: current_user, content:)
|
|
theatre.update!(next_comment_no: no + 1)
|
|
end
|
|
|
|
render json: comment, status: :created
|
|
end
|
|
end
|