From 443e3cf6fd37e2e44d2be058a4aaf1c85b2ec2f7 Mon Sep 17 00:00:00 2001 From: Lucas Ceni Date: Fri, 18 Oct 2024 14:34:29 +0200 Subject: [PATCH] get version from path instead of query Signed-off-by: Lucas Ceni --- .../java/com/here/xyz/hub/rest/ChangesetApi.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java index b08670e53..7b6444237 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java @@ -22,6 +22,7 @@ import static com.here.xyz.events.PropertyQuery.QueryOperation.LESS_THAN; import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND; +import com.google.common.primitives.Longs; import com.here.xyz.events.DeleteChangesetsEvent; import com.here.xyz.events.GetChangesetStatisticsEvent; import com.here.xyz.events.IterateChangesetsEvent; @@ -111,9 +112,8 @@ private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext validateVersion(endVersion, false); validateVersions(startVersion, endVersion); } else { - final Long version = Query.getLong(context, Query.VERSION, null); + final Long version = getVersionFromPath(context); validateVersion(version, true); - startVersion = version; endVersion = version; } @@ -127,6 +127,14 @@ private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext .withLimit(limit); } + private Long getVersionFromPath(RoutingContext context) throws HttpException { + final Long version = Longs.tryParse(context.pathParam(Path.VERSION)); + if (version == null) + throw new HttpException(HttpResponseStatus.BAD_REQUEST, "Invalid version specified."); + + return version; + } + private void validateVersion(Long version, boolean required) throws HttpException { if (required && version == null) throw new HttpException(HttpResponseStatus.BAD_REQUEST, "The parameter version is required.");