ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

33 lines
891 B

  1. class TheatreCommentsController < ApplicationController
  2. def index
  3. no_gt = params[:no_gt].to_i
  4. no_gt = 0 if no_gt.negative?
  5. comments = TheatreComment
  6. .where(theatre_id: params[:theatre_id])
  7. .where('no > ?', no_gt)
  8. .order(:no)
  9. render json: comments.as_json(include: { user: { only: [:id, :name] } })
  10. end
  11. def create
  12. return head :unauthorized unless current_user
  13. content = params[:content]
  14. return head :unprocessable_entity if content.blank?
  15. theatre = Theatre.find_by(id: params[:theatre_id])
  16. return head :not_found unless theatre
  17. comment = nil
  18. theatre.with_lock do
  19. no = theatre.next_comment_no
  20. comment = TheatreComment.create!(theatre:, no:, user: current_user, content:)
  21. theatre.update!(next_comment_no: no + 1)
  22. end
  23. render json: comment, status: :created
  24. end
  25. end