Add create note subscription api endpoint
This commit is contained in:
parent
a25b7953b3
commit
edd12c6995
4 changed files with 98 additions and 0 deletions
18
app/controllers/api/note_subscriptions_controller.rb
Normal file
18
app/controllers/api/note_subscriptions_controller.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue