]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/api/notes_controller.rb
Don't expose technical terms to the user
[rails.git] / app / controllers / api / notes_controller.rb
index 23ea4e9553cb1390cde7e3d69ff099b7c2142272..703f275aa5a2a5c018250d5b3ae88764b34954ca 100644 (file)
@@ -298,10 +298,21 @@ module Api
       end
 
       # Find the notes we want to return
-      sort_by = params[:sort_by] == "created_at" ? "created_at" : "updated_at"
-      order_by = params[:order_by] == "ASC" ? "ASC" : "DESC"
+      @notes = if params[:sort] == "created_at"
+                 if params[:order] == "oldest"
+                   @notes.order("created_at ASC")
+                 else
+                   @notes.order("created_at DESC")
+                 end
+               else
+                 if params[:order] == "oldest"
+                   @notes.order("updated_at ASC")
+                 else
+                   @notes.order("updated_at DESC")
+                 end
+               end
 
-      @notes = @notes.order("#{sort_by} #{order_by}").limit(result_limit).preload(:comments)
+      @notes = @notes.distinct.limit(result_limit).preload(:comments)
 
       # Render the result
       respond_to do |format|