]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/api/note_subscriptions_controller.rb
Merge remote-tracking branch 'upstream/pull/5346'
[rails.git] / app / controllers / api / note_subscriptions_controller.rb
index 348b428b6394e8122e3640ccee11b9e8d37421aa..c416dd803647112b337e22e137917c69206bd552 100644 (file)
@@ -14,5 +14,14 @@ module Api
     rescue ActiveRecord::RecordNotUnique
       report_error "You are already subscribed to note #{note_id}.", :conflict
     end
     rescue ActiveRecord::RecordNotUnique
       report_error "You are already subscribed to note #{note_id}.", :conflict
     end
+
+    def destroy
+      note_id = params[:note_id].to_i
+      note = Note.find(note_id)
+      count = note.subscriptions.where(:user => current_user).delete_all
+      report_error "You are not subscribed to note #{note_id}.", :not_found if count.zero?
+    rescue ActiveRecord::RecordNotFound
+      report_error "Note #{note_id} not found.", :not_found
+    end
   end
 end
   end
 end