]> git.openstreetmap.org Git - rails.git/commitdiff
Add 'from' and 'to' changeset query parameters
authorAnton Khorev <tony29@yandex.ru>
Tue, 15 Aug 2023 16:12:11 +0000 (19:12 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 15 Aug 2023 16:29:06 +0000 (19:29 +0300)
app/controllers/api/changesets_controller.rb

index 7a798be633dfaea5698b5b807adbc1f498ef564c..84f1ccdb526b41be0d338f533f3c05b6e09f2212 100644 (file)
@@ -168,6 +168,7 @@ module Api
       changesets = conditions_bbox(changesets, bbox)
       changesets = conditions_user(changesets, params["user"], params["display_name"])
       changesets = conditions_time(changesets, params["time"])
+      changesets = conditions_from_to(changesets, params["from"], params["to"])
       changesets = conditions_open(changesets, params["open"])
       changesets = conditions_closed(changesets, params["closed"])
       changesets = conditions_ids(changesets, params["changesets"])
@@ -353,6 +354,33 @@ module Api
       raise OSM::APIBadUserInput, e.message.to_s
     end
 
+    ##
+    # restrict changesets to those opened during a particular time period
+    # works similar to from..to of notes controller, including the requirement of 'from' when specifying 'to'
+    def conditions_from_to(changesets, from, to)
+      if from
+        begin
+          from = Time.parse(from).utc
+        rescue ArgumentError
+          raise OSM::APIBadUserInput, "Date #{from} is in a wrong format"
+        end
+
+        begin
+          to = if to
+                 Time.parse(to).utc
+               else
+                 Time.now.utc
+               end
+        rescue ArgumentError
+          raise OSM::APIBadUserInput, "Date #{to} is in a wrong format"
+        end
+
+        changesets.where(:created_at => from..to)
+      else
+        changesets
+      end
+    end
+
     ##
     # return changesets which are open (haven't been closed yet)
     # we do this by seeing if the 'closed at' time is in the future. Also if we've