Skip to content

Commit

Permalink
get version from path instead of query
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Ceni <[email protected]>
  • Loading branch information
lceni committed Oct 18, 2024
1 parent 03f8432 commit 443e3cf
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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.");
Expand Down

0 comments on commit 443e3cf

Please sign in to comment.