From 33c2f8bf8ab8181fc83712c8810686c07db683b3 Mon Sep 17 00:00:00 2001 From: grata Date: Thu, 27 Apr 2023 14:18:00 +0200 Subject: [PATCH] Set better path for rest --- .../controller/LocationController.java | 16 ++++++++-------- .../progetto152/controller/UserController.java | 16 ++++++++-------- .../controller/WaypointController.java | 14 +++++++------- .../controller/WaypointVisitedController.java | 16 ++++++++-------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/ch/progetto152/controller/LocationController.java b/src/main/java/ch/progetto152/controller/LocationController.java index d70e30b..48d5a8e 100644 --- a/src/main/java/ch/progetto152/controller/LocationController.java +++ b/src/main/java/ch/progetto152/controller/LocationController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/api/locations") +@RequestMapping("/progetto152/locations") public class LocationController { private final LocationService locationService; @@ -19,13 +19,13 @@ public class LocationController { this.locationService = locationService; } - @GetMapping("/get/all") + @GetMapping("") public ResponseEntity> getAllLocations() { List Locations = locationService.getAllLocations(); return new ResponseEntity<>(Locations, HttpStatus.OK); } - @GetMapping("/get/{id}") + @GetMapping("/{id}") public ResponseEntity getLocationById(@PathVariable("id") Long id) { LocationEntity location = locationService.getLocationById(id); if (location != null) { @@ -35,8 +35,8 @@ public class LocationController { } } - @GetMapping("/get/name/{name}") - public ResponseEntity getLocationByName(@PathVariable("name") String name) { + @GetMapping("?name={name}") + public ResponseEntity getLocationByName(@PathVariable("location") String name) { LocationEntity location = locationService.getLocationByName(name); if (location != null) { return new ResponseEntity<>(location, HttpStatus.OK); @@ -45,13 +45,13 @@ public class LocationController { } } - @PostMapping("/create/{id}") + @PostMapping("") public ResponseEntity createLocation(@RequestBody LocationEntity location) { LocationEntity createdLocation = locationService.createLocation(location); return new ResponseEntity<>(createdLocation, HttpStatus.CREATED); } - @PutMapping("/put/{id}") + @PutMapping("{id}") public ResponseEntity updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) { LocationEntity location1 = locationService.updateLocation(id, location); if (location1 != null) { @@ -61,7 +61,7 @@ public class LocationController { } } - @DeleteMapping("/delete/{id}") + @DeleteMapping("{id}") public ResponseEntity deleteLocation(@PathVariable("id") Long id) { boolean deleted = locationService.deleteLocation(id); if (deleted) { diff --git a/src/main/java/ch/progetto152/controller/UserController.java b/src/main/java/ch/progetto152/controller/UserController.java index 5292a7c..af0d154 100644 --- a/src/main/java/ch/progetto152/controller/UserController.java +++ b/src/main/java/ch/progetto152/controller/UserController.java @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/api/users") +@RequestMapping("/progetto152/users") public class UserController { private final UserService userService; @@ -21,13 +21,13 @@ public class UserController { this.userService = userService; } - @GetMapping("/get/all") + @GetMapping("") public ResponseEntity> getAllUsers() { List users = userService.getAllUsers(); return new ResponseEntity<>(users, HttpStatus.OK); } - @GetMapping("/get/{id}") + @GetMapping("/{id}") public ResponseEntity getUserById(@PathVariable("id") Long id) { UserEntity user = userService.getUserById(id); if (user != null) { @@ -37,7 +37,7 @@ public class UserController { } } - @GetMapping("/get/name/{name}") + @GetMapping("?name={name}") public ResponseEntity getUserByName(@PathVariable("name") String name) { UserEntity user = userService.getUserByName(name); if (user != null) { @@ -47,7 +47,7 @@ public class UserController { } } - @GetMapping("/get/username/{username}") + @GetMapping("?username={username}") public ResponseEntity getUserByUsername(@PathVariable("username") String username) { UserEntity user = userService.getUserByUsername(username); if (user != null) { @@ -57,13 +57,13 @@ public class UserController { } } - @PostMapping("/create/{id}") + @PostMapping("") public ResponseEntity createUser(@RequestBody UserEntity user) { UserEntity createdUser = userService.createUser(user); return new ResponseEntity<>(createdUser, HttpStatus.CREATED); } - @PutMapping("/put/{id}") + @PutMapping("/{id}") public ResponseEntity updateUser(@PathVariable("id") Long id, @RequestBody UserEntity user) { UserEntity updatedUser = userService.updateUser(id, user); if (updatedUser != null) { @@ -73,7 +73,7 @@ public class UserController { } } - @DeleteMapping("/delete/{id}") + @DeleteMapping("/{id}") public ResponseEntity deleteUser(@PathVariable("id") Long id) { boolean deleted = userService.deleteUser(id); if (deleted) { diff --git a/src/main/java/ch/progetto152/controller/WaypointController.java b/src/main/java/ch/progetto152/controller/WaypointController.java index 5d09dd5..6d6df7c 100644 --- a/src/main/java/ch/progetto152/controller/WaypointController.java +++ b/src/main/java/ch/progetto152/controller/WaypointController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/api/waypoints") +@RequestMapping("/progetto152/waypoints") public class WaypointController { private final WaypointService waypointService; @@ -19,13 +19,13 @@ public class WaypointController { this.waypointService = waypointService; } - @GetMapping("/get/all") + @GetMapping("") public ResponseEntity> getAllWaypoints() { List waypoint = waypointService.getAllWaypoints(); return new ResponseEntity<>(waypoint, HttpStatus.OK); } - @GetMapping("/get/{id}") + @GetMapping("/{id}") public ResponseEntity getWaypointById(@PathVariable("id") Long id) { WaypointsEntity waypoint = waypointService.getWaypointById(id); if (waypoint != null) { @@ -35,7 +35,7 @@ public class WaypointController { } } - @GetMapping("/get/name/{name}") + @GetMapping("?name={name}") public ResponseEntity getWaypointByName(@PathVariable("name") String name) { WaypointsEntity waypoint = waypointService.getWaypointByName(name); if (waypoint != null) { @@ -45,13 +45,13 @@ public class WaypointController { } } - @PostMapping("/create/{id}") + @PostMapping("") public ResponseEntity createWaypoint(@RequestBody WaypointsEntity waypoint) { WaypointsEntity createdWaypoint = waypointService.createWaypoint(waypoint); return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED); } - @PutMapping("/put/{id}") + @PutMapping("/{id}") public ResponseEntity updateWaypoint(@PathVariable("id") Long id, @RequestBody WaypointsEntity waypoint) { WaypointsEntity updatedWaypoint = waypointService.updateWaypoint(id, waypoint); if (updatedWaypoint != null) { @@ -61,7 +61,7 @@ public class WaypointController { } } - @DeleteMapping("/delete/{id}") + @DeleteMapping("/{id}") public ResponseEntity deleteWaypoint(@PathVariable("id") Long id) { boolean deleted = waypointService.deleteWaypoint(id); if (deleted) { diff --git a/src/main/java/ch/progetto152/controller/WaypointVisitedController.java b/src/main/java/ch/progetto152/controller/WaypointVisitedController.java index 5f5edcf..551e9e3 100644 --- a/src/main/java/ch/progetto152/controller/WaypointVisitedController.java +++ b/src/main/java/ch/progetto152/controller/WaypointVisitedController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/api/users") +@RequestMapping("/progetto152/waypointsvisited") public class WaypointVisitedController { private final WaypointVisitedService waypointVisitedService; @@ -19,13 +19,13 @@ public class WaypointVisitedController { this.waypointVisitedService = waypointVisitedService; } - @GetMapping("/get/all") + @GetMapping("") public ResponseEntity> getAllWaypointsVisited() { List waypointVisited = waypointVisitedService.getAllWaypointsVisited(); return new ResponseEntity<>(waypointVisited, HttpStatus.OK); } - @GetMapping("/get/{id}") + @GetMapping("/{id}") public ResponseEntity getWaypointVisitedById(@PathVariable("id") Long id) { WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointById(id); if (waypointVisited != null) { @@ -35,7 +35,7 @@ public class WaypointVisitedController { } } - @GetMapping("/get/name/{id}") + @GetMapping("?userid={id}") public ResponseEntity getWaypointVisitedByUserId(@PathVariable("id") Long id) { WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByUserId(id); if (waypointVisited != null) { @@ -45,7 +45,7 @@ public class WaypointVisitedController { } } - @GetMapping("/get/name/{id}") + @GetMapping("?waypointid={id}") public ResponseEntity getWaypointVisitedByWaypointId(@PathVariable("id") Long id) { WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByWaypointId(id); if (waypointVisited != null) { @@ -55,13 +55,13 @@ public class WaypointVisitedController { } } - @PostMapping("/create/{id}") + @PostMapping("") public ResponseEntity createWaypointVisited(@RequestBody WaypointsVisitedEntity waypointVisited) { WaypointsVisitedEntity createdWaypoint = waypointVisitedService.createWaypoint(waypointVisited); return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED); } - @PutMapping("/put/{id}") + @PutMapping("/{id}") public ResponseEntity updateWaypointVisited(@PathVariable("id") Long id, @RequestBody WaypointsVisitedEntity waypointVisited) { WaypointsVisitedEntity updatedWaypoint = waypointVisitedService.updateWaypoint(id, waypointVisited); if (updatedWaypoint != null) { @@ -71,7 +71,7 @@ public class WaypointVisitedController { } } - @DeleteMapping("/delete/{id}") + @DeleteMapping("/{id}") public ResponseEntity deleteWaypointVisited(@PathVariable("id") Long id) { boolean deleted = waypointVisitedService.deleteWaypoint(id); if (deleted) {