]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/note_subscriptions_controller.rb
Add frozen_string_literal comments to ruby files
[rails.git] / app / controllers / api / note_subscriptions_controller.rb
1 # frozen_string_literal: true
2
3 module Api
4   class NoteSubscriptionsController < ApiController
5     before_action :check_api_writable
6     before_action :authorize
7
8     authorize_resource
9
10     def create
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
18     end
19
20     def destroy
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
27     end
28   end
29 end