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