Add create note subscription api endpoint

This commit is contained in:
Anton Khorev 2024-10-24 04:11:37 +03:00
parent a25b7953b3
commit edd12c6995
4 changed files with 98 additions and 0 deletions

View file

@ -0,0 +1,18 @@
module Api
class NoteSubscriptionsController < ApiController
before_action :check_api_writable
before_action :authorize
authorize_resource
def create
note_id = params[:note_id].to_i
note = Note.find(note_id)
note.subscribers << current_user
rescue ActiveRecord::RecordNotFound
report_error "Note #{note_id} not found.", :not_found
rescue ActiveRecord::RecordNotUnique
report_error "You are already subscribed to note #{note_id}.", :conflict
end
end
end