2 class NoteSubscriptionsController < ApiController
3 before_action :check_api_writable
4 before_action :authorize
9 note_id = params[:note_id].to_i
10 note = Note.find(note_id)
11 note.subscribers << current_user
12 rescue ActiveRecord::RecordNotFound
13 report_error "Note #{note_id} not found.", :not_found
14 rescue ActiveRecord::RecordNotUnique
15 report_error "You are already subscribed to note #{note_id}.", :conflict
19 note_id = params[:note_id].to_i
20 note = Note.find(note_id)
21 count = note.subscriptions.where(:user => current_user).delete_all
22 report_error "You are not subscribed to note #{note_id}.", :not_found if count.zero?
23 rescue ActiveRecord::RecordNotFound
24 report_error "Note #{note_id} not found.", :not_found