]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/note_subscriptions_controller.rb
348b428b6394e8122e3640ccee11b9e8d37421aa
[rails.git] / app / controllers / api / note_subscriptions_controller.rb
1 module Api
2   class NoteSubscriptionsController < ApiController
3     before_action :check_api_writable
4     before_action :authorize
5
6     authorize_resource
7
8     def create
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
16     end
17   end
18 end