From 9f4bd0d898520581d5e9de72be2d7f633df09af3 Mon Sep 17 00:00:00 2001 From: Lukas Connolly Date: Thu, 22 Aug 2024 19:26:15 +0200 Subject: [PATCH] ENH: NAV-141 - Include check if source and target coordinates are identical. --- .../java/ch/naviqore/app/controller/RoutingController.java | 1 + .../naviqore/app/controller/RoutingRequestValidator.java | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/ch/naviqore/app/controller/RoutingController.java b/src/main/java/ch/naviqore/app/controller/RoutingController.java index 46b2fd04..4ba0573f 100644 --- a/src/main/java/ch/naviqore/app/controller/RoutingController.java +++ b/src/main/java/ch/naviqore/app/controller/RoutingController.java @@ -102,6 +102,7 @@ public List getConnections(@RequestParam(required = false) String so } else if (targetStop != null) { return map(service.getConnections(sourceCoordinate, targetStop, dateTime, map(timeType), config)); } else { + RoutingRequestValidator.validateCoordinates(sourceCoordinate, targetCoordinate); return map(service.getConnections(sourceCoordinate, targetCoordinate, dateTime, map(timeType), config)); } } catch (ConnectionRoutingException e) { diff --git a/src/main/java/ch/naviqore/app/controller/RoutingRequestValidator.java b/src/main/java/ch/naviqore/app/controller/RoutingRequestValidator.java index d3dc520b..6ff2da2e 100644 --- a/src/main/java/ch/naviqore/app/controller/RoutingRequestValidator.java +++ b/src/main/java/ch/naviqore/app/controller/RoutingRequestValidator.java @@ -100,4 +100,11 @@ public static void validateStops(String sourceStopId, String targetStopId) { } } + public static void validateCoordinates(GeoCoordinate sourceCoordinate, GeoCoordinate targetCoordinate) { + if (sourceCoordinate.equals(targetCoordinate)) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, + "The source and target coordinates cannot be the same. Please provide different coordinates for the source and target."); + } + } + }