diff --git a/src/main/java/ch/progetto152/controller/LocationController.java b/src/main/java/ch/progetto152/controller/LocationController.java index 69a37dd..7a2cdfb 100644 --- a/src/main/java/ch/progetto152/controller/LocationController.java +++ b/src/main/java/ch/progetto152/controller/LocationController.java @@ -25,7 +25,6 @@ public class LocationController { return new ResponseEntity<>(Locations, HttpStatus.OK); } - @GetMapping("/{name}") public ResponseEntity getLocationByName(@PathVariable("name") String name) { LocationEntity location = locationService.getLocationByName(name); @@ -36,16 +35,6 @@ public class LocationController { } } - @GetMapping("id/{id}") - public ResponseEntity getLocationById(@PathVariable("id") Long id) { - LocationEntity location = locationService.getLocationById(id); - if (location != null) { - return new ResponseEntity<>(location, HttpStatus.OK); - } else { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - } - @PostMapping("") public ResponseEntity createLocation(@RequestBody LocationEntity location) { LocationEntity createdLocation = locationService.createLocation(location); @@ -55,9 +44,9 @@ public class LocationController { return new ResponseEntity<>(createdLocation, HttpStatus.CREATED); } - @PutMapping("/{id}") - public ResponseEntity updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) { - LocationEntity location1 = locationService.updateLocation(id, location); + @PutMapping("/{name}") + public ResponseEntity updateLocation(@PathVariable("name") String name, @RequestBody LocationEntity location) { + LocationEntity location1 = locationService.updateLocation(name, location); if (location1 != null) { return new ResponseEntity<>(location1, HttpStatus.OK); } else { @@ -65,9 +54,9 @@ public class LocationController { } } - @DeleteMapping("/{id}") - public ResponseEntity deleteLocation(@PathVariable("id") Long id) { - boolean deleted = locationService.deleteLocation(id); + @DeleteMapping("/{name}") + public ResponseEntity deleteLocation(@PathVariable("name") String name) { + boolean deleted = locationService.deleteLocation(name); if (deleted) { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } else { diff --git a/src/main/java/ch/progetto152/controller/WaypointVisitedController.java b/src/main/java/ch/progetto152/controller/WaypointVisitedController.java index d5db627..b4358bb 100644 --- a/src/main/java/ch/progetto152/controller/WaypointVisitedController.java +++ b/src/main/java/ch/progetto152/controller/WaypointVisitedController.java @@ -49,7 +49,7 @@ public class WaypointVisitedController { if (waypointVisited == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } else if (!waypointVisited) { - return new ResponseEntity<>(false, HttpStatus.NOT_FOUND); + return new ResponseEntity<>(false, HttpStatus.OK); } else { return new ResponseEntity<>(true, HttpStatus.OK); } diff --git a/src/main/java/ch/progetto152/services/LocationService.java b/src/main/java/ch/progetto152/services/LocationService.java index edd14a8..9e5167e 100644 --- a/src/main/java/ch/progetto152/services/LocationService.java +++ b/src/main/java/ch/progetto152/services/LocationService.java @@ -23,10 +23,6 @@ public class LocationService { return locationRepository.findAll(); } - public LocationEntity getLocationById(Long id) { - return locationRepository.findById(id).orElse(null); - } - public LocationEntity getLocationByName(String name){ return locationRepository.findLocationByLocation(name).orElse(null); } @@ -39,8 +35,8 @@ public class LocationService { } } - public LocationEntity updateLocation(Long id, LocationEntity Location) { - LocationEntity location1 = getLocationById(id); + public LocationEntity updateLocation(String name, LocationEntity Location) { + LocationEntity location1 = getLocationByName(name); if (location1 != null) { location1.setLocation(Location.getLocation()); location1.setRegion(Location.getRegion()); @@ -52,12 +48,12 @@ public class LocationService { } } - public boolean deleteLocation(Long id) { + public boolean deleteLocation(String name) { boolean exists = locationRepository.existsById(id); if(!exists){ return false; } - locationRepository.deleteById(id); + locationRepository.deleteByName(name); return true; } }