added comment
This commit is contained in:
@@ -12,6 +12,8 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/location")
|
||||
public class LocationController {
|
||||
|
||||
// Inject the LocationService
|
||||
private final LocationService locationService;
|
||||
|
||||
@Autowired
|
||||
@@ -19,12 +21,14 @@ public class LocationController {
|
||||
this.locationService = locationService;
|
||||
}
|
||||
|
||||
// Handle GET request to get all locations
|
||||
@GetMapping("")
|
||||
public ResponseEntity<List<LocationEntity>> getAllLocations() {
|
||||
List<LocationEntity> Locations = locationService.getAllLocations();
|
||||
return new ResponseEntity<>(Locations, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// Handle GET request to get a specific location by name
|
||||
@GetMapping("/{name}")
|
||||
public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("name") String name) {
|
||||
LocationEntity location = locationService.getLocationByName(name);
|
||||
@@ -35,6 +39,7 @@ public class LocationController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle POST request to create a new location
|
||||
@PostMapping("")
|
||||
public ResponseEntity<LocationEntity> createLocation(@RequestBody LocationEntity location) {
|
||||
LocationEntity createdLocation = locationService.createLocation(location);
|
||||
@@ -44,6 +49,7 @@ public class LocationController {
|
||||
return new ResponseEntity<>(createdLocation, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// Handle PUT request to update an existing location
|
||||
@PutMapping("/{name}")
|
||||
public ResponseEntity<LocationEntity> updateLocation(@PathVariable("name") String name, @RequestBody LocationEntity location) {
|
||||
LocationEntity location1 = locationService.updateLocation(name, location);
|
||||
@@ -54,6 +60,7 @@ public class LocationController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle DELETE request to delete an existing location by name
|
||||
@DeleteMapping("/{name}")
|
||||
public ResponseEntity<Void> deleteLocation(@PathVariable("name") String name) {
|
||||
boolean deleted = locationService.deleteLocation(name);
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.util.List;
|
||||
@RequestMapping("/progetto152/user")
|
||||
public class UserController {
|
||||
|
||||
|
||||
// Inject the UserService
|
||||
private final UserService userService;
|
||||
|
||||
@Autowired
|
||||
@@ -21,12 +23,14 @@ public class UserController {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
// Handle GET request to get all users
|
||||
@GetMapping("")
|
||||
public ResponseEntity<List<UserEntity>> getAllUsers() {
|
||||
List<UserEntity> users = userService.getAllUsers();
|
||||
return new ResponseEntity<>(users, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// Handle GET request to get user by id
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<UserEntity> getUserById(@PathVariable("id") Long id) {
|
||||
UserEntity user = userService.getUserById(id);
|
||||
@@ -37,6 +41,7 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle GET request to get user by username
|
||||
@GetMapping("/{username}")
|
||||
public ResponseEntity<UserEntity> getUserByUsername(@PathVariable("username") String username) {
|
||||
UserEntity user = userService.getUserByUsername(username);
|
||||
@@ -47,6 +52,7 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle POST request to create a new user
|
||||
@PostMapping("")
|
||||
public ResponseEntity<UserEntity> createUser(@RequestBody UserEntity user) {
|
||||
UserEntity createdUser = userService.createUser(user);
|
||||
@@ -57,6 +63,7 @@ public class UserController {
|
||||
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// Handle PUT request to update an existing user
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<UserEntity> updateUser(@PathVariable("id") Long id, @RequestBody UserEntity user) {
|
||||
UserEntity updatedUser = userService.updateUser(id, user);
|
||||
@@ -67,6 +74,7 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle DELETE request to delete an existing user
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteUser(@PathVariable("id") Long id) {
|
||||
boolean deleted = userService.deleteUser(id);
|
||||
|
||||
@@ -12,6 +12,8 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/waypoint")
|
||||
public class WaypointController {
|
||||
|
||||
// Iject the WaypointService instance
|
||||
private final WaypointService waypointService;
|
||||
|
||||
@Autowired
|
||||
@@ -19,12 +21,14 @@ public class WaypointController {
|
||||
this.waypointService = waypointService;
|
||||
}
|
||||
|
||||
// Handle the GET request to get all waypoints
|
||||
@GetMapping("")
|
||||
public ResponseEntity<List<WaypointsEntity>> getAllWaypoints() {
|
||||
List<WaypointsEntity> waypoint = waypointService.getAllWaypoints();
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
}
|
||||
|
||||
// Handle the GET request to get all waypoints by location
|
||||
@GetMapping("/{location}")
|
||||
public ResponseEntity<List<WaypointsEntity>> getAllWaypoints(@PathVariable("location") String location) {
|
||||
System.out.println(waypointService.getAllWaypointsByLocation(location));
|
||||
@@ -32,6 +36,8 @@ public class WaypointController {
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
// Handle the GET request to get a specific waypoint by id
|
||||
@GetMapping("/{location}/{id}")
|
||||
public ResponseEntity<WaypointsEntity> getWaypoint(@PathVariable("location") String location, @PathVariable("id") Long id) {
|
||||
WaypointsEntity waypoint = waypointService.getWaypointById(id);
|
||||
@@ -46,6 +52,7 @@ public class WaypointController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the GET request to get a specific waypoint by id
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<WaypointsEntity> getWaypointById(@PathVariable("id") Long id) {
|
||||
WaypointsEntity waypoint = waypointService.getWaypointById(id);
|
||||
@@ -56,6 +63,7 @@ public class WaypointController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the POST request to create a new waypoint
|
||||
@PostMapping("")
|
||||
public ResponseEntity<WaypointsEntity> createWaypoint(@RequestBody WaypointsEntity waypoint) {
|
||||
WaypointsEntity createdWaypoint = waypointService.createWaypoint(waypoint);
|
||||
@@ -65,6 +73,7 @@ public class WaypointController {
|
||||
return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// Handle the PUT request to update an existing waypoint
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<WaypointsEntity> updateWaypoint(@PathVariable("id") Long id, @RequestBody WaypointsEntity waypoint) {
|
||||
WaypointsEntity updatedWaypoint = waypointService.updateWaypoint(id, waypoint);
|
||||
@@ -75,6 +84,7 @@ public class WaypointController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the DELETE request to delete an existing waypoint
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteWaypoint(@PathVariable("id") Long id) {
|
||||
boolean deleted = waypointService.deleteWaypoint(id);
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/waypoint/visited")
|
||||
public class WaypointVisitedController {
|
||||
|
||||
// Iject the WaypointVisitedService and UserService
|
||||
private final WaypointVisitedService waypointVisitedService;
|
||||
|
||||
private final UserService userService;
|
||||
@@ -24,14 +26,14 @@ public class WaypointVisitedController {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
// Handle GET request to get all waypoints visited
|
||||
@GetMapping("")
|
||||
public ResponseEntity<List<WaypointsVisitedEntity>> getAllWaypointsVisited() {
|
||||
List<WaypointsVisitedEntity> waypointVisited = waypointVisitedService.getAllWaypointsVisited();
|
||||
return new ResponseEntity<>(waypointVisited, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Handle GET request to get all waypoints visited by user
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> getWaypointVisitedByWaypointId(@PathVariable("id") Long id) {
|
||||
WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByWaypointId(id);
|
||||
@@ -42,6 +44,7 @@ public class WaypointVisitedController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle GET request to get all waypoints visited by user
|
||||
@GetMapping("/{user}/{id}")
|
||||
public ResponseEntity<Boolean> getWaypointVisitedByWaypointIdAndUserId(@PathVariable("user") String username, @PathVariable("id") Long waypointId) {
|
||||
UserEntity user = userService.getUserByUsername(username);
|
||||
@@ -55,6 +58,7 @@ public class WaypointVisitedController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle GET request to get all waypoints visited by user
|
||||
@GetMapping("/user/{id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> getWaypointVisitedByUserId(@PathVariable("id") Long id) {
|
||||
WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByUserId(id);
|
||||
@@ -65,6 +69,7 @@ public class WaypointVisitedController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle POST request to create a new waypoint visited
|
||||
@PostMapping("")
|
||||
public ResponseEntity<WaypointsVisitedEntity> createWaypointVisited(@RequestBody WaypointsVisitedEntity waypointVisited) {
|
||||
WaypointsVisitedEntity createdWaypoint = waypointVisitedService.createWaypoint(waypointVisited);
|
||||
@@ -74,6 +79,7 @@ public class WaypointVisitedController {
|
||||
return new ResponseEntity<>(createdWaypoint, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// Handle PUT request to update a waypoint visited
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> updateWaypointVisited(@PathVariable("id") Long id, @RequestBody WaypointsVisitedEntity waypointVisited) {
|
||||
WaypointsVisitedEntity updatedWaypoint = waypointVisitedService.updateWaypoint(id, waypointVisited);
|
||||
@@ -84,6 +90,7 @@ public class WaypointVisitedController {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle DELETE request to delete a waypoint visited
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteWaypointVisited(@PathVariable("id") Long id) {
|
||||
boolean deleted = waypointVisitedService.deleteWaypoint(id);
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
@Service
|
||||
public class LocationService {
|
||||
|
||||
private ErrorChecking errorChecking = new ErrorChecking();
|
||||
private final ErrorChecking errorChecking = new ErrorChecking();
|
||||
private final LocationRepository locationRepository;
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ch.progetto152.services;
|
||||
|
||||
import ch.progetto152.entity.UserEntity;
|
||||
import ch.progetto152.entity.WaypointsVisitedEntity;
|
||||
import ch.progetto152.repository.WaypointVisitedRepository;
|
||||
import ch.progetto152.utility.ErrorChecking;
|
||||
@@ -63,13 +62,8 @@ public class WaypointVisitedService {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Boolean getWaypointsVisitedByWaypointIdAndUserId(Long waypointId, Long userId) {
|
||||
WaypointsVisitedEntity waypointsVisited = waypointVisitedRepository.findWaypointsVisitedEntitiesByUserIdAndWaypointId(userId, waypointId).orElse(null);
|
||||
if (waypointsVisited != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return waypointsVisited != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import ch.progetto152.entity.UserEntity;
|
||||
import ch.progetto152.entity.WaypointsEntity;
|
||||
import ch.progetto152.entity.WaypointsVisitedEntity;
|
||||
|
||||
|
||||
// This class is used to check if the data received from the client is valid
|
||||
public class ErrorChecking {
|
||||
|
||||
public boolean checkUser(UserEntity user){
|
||||
|
||||
Reference in New Issue
Block a user