Api changes, error with findAllByLocationName
This commit is contained in:
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/locations")
|
||||
@RequestMapping("/progetto152/location")
|
||||
public class LocationController {
|
||||
private final LocationService locationService;
|
||||
|
||||
@@ -25,9 +25,10 @@ public class LocationController {
|
||||
return new ResponseEntity<>(Locations, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<LocationEntity> getLocationById(@PathVariable("id") Long id) {
|
||||
LocationEntity location = locationService.getLocationById(id);
|
||||
|
||||
@GetMapping("/{name}")
|
||||
public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("name") String name) {
|
||||
LocationEntity location = locationService.getLocationByName(name);
|
||||
if (location != null) {
|
||||
return new ResponseEntity<>(location, HttpStatus.OK);
|
||||
} else {
|
||||
@@ -35,9 +36,9 @@ public class LocationController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("?name={name}")
|
||||
public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("location") String name) {
|
||||
LocationEntity location = locationService.getLocationByName(name);
|
||||
@GetMapping("id/{id}")
|
||||
public ResponseEntity<LocationEntity> getLocationById(@PathVariable("id") Long id) {
|
||||
LocationEntity location = locationService.getLocationById(id);
|
||||
if (location != null) {
|
||||
return new ResponseEntity<>(location, HttpStatus.OK);
|
||||
} else {
|
||||
@@ -54,7 +55,7 @@ public class LocationController {
|
||||
return new ResponseEntity<>(createdLocation, HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("{id}")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<LocationEntity> updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) {
|
||||
LocationEntity location1 = locationService.updateLocation(id, location);
|
||||
if (location1 != null) {
|
||||
@@ -64,7 +65,7 @@ public class LocationController {
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteLocation(@PathVariable("id") Long id) {
|
||||
boolean deleted = locationService.deleteLocation(id);
|
||||
if (deleted) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/users")
|
||||
@RequestMapping("/progetto152/user")
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
@@ -27,7 +27,7 @@ public class UserController {
|
||||
return new ResponseEntity<>(users, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<UserEntity> getUserById(@PathVariable("id") Long id) {
|
||||
UserEntity user = userService.getUserById(id);
|
||||
if (user != null) {
|
||||
@@ -37,17 +37,7 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("?name={name}")
|
||||
public ResponseEntity<UserEntity> getUserByName(@PathVariable("name") String name) {
|
||||
UserEntity user = userService.getUserByName(name);
|
||||
if (user != null) {
|
||||
return new ResponseEntity<>(user, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("?username={username}")
|
||||
@GetMapping("/{username}")
|
||||
public ResponseEntity<UserEntity> getUserByUsername(@PathVariable("username") String username) {
|
||||
UserEntity user = userService.getUserByUsername(username);
|
||||
if (user != null) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/waypoints")
|
||||
@RequestMapping("/progetto152/waypoint")
|
||||
public class WaypointController {
|
||||
private final WaypointService waypointService;
|
||||
|
||||
@@ -19,25 +19,29 @@ public class WaypointController {
|
||||
this.waypointService = waypointService;
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
public ResponseEntity<List<WaypointsEntity>> getAllWaypoints() {
|
||||
List<WaypointsEntity> waypoint = waypointService.getAllWaypoints();
|
||||
@GetMapping("/{location}")
|
||||
public ResponseEntity<List<WaypointsEntity>> getAllWaypoints(@PathVariable("location") String location) {
|
||||
List<WaypointsEntity> waypoint = waypointService.getAllWaypointsByLocation(location);
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<WaypointsEntity> getWaypointById(@PathVariable("id") Long id) {
|
||||
@GetMapping("/{location}/{id}")
|
||||
public ResponseEntity<WaypointsEntity> getWaypointById(@PathVariable("location") String location, @PathVariable("id") Long id) {
|
||||
WaypointsEntity waypoint = waypointService.getWaypointById(id);
|
||||
if (waypoint != null) {
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
if (waypoint.getLocationName().equals(location)) {
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("?name={name}")
|
||||
public ResponseEntity<WaypointsEntity> getWaypointByName(@PathVariable("name") String name) {
|
||||
WaypointsEntity waypoint = waypointService.getWaypointByName(name);
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<WaypointsEntity> getWaypointById(@PathVariable("id") Long id) {
|
||||
WaypointsEntity waypoint = waypointService.getWaypointById(id);
|
||||
if (waypoint != null) {
|
||||
return new ResponseEntity<>(waypoint, HttpStatus.OK);
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/progetto152/waypointsvisited")
|
||||
@RequestMapping("/progetto152/waypoint/visited")
|
||||
public class WaypointVisitedController {
|
||||
private final WaypointVisitedService waypointVisitedService;
|
||||
|
||||
@@ -26,26 +26,6 @@ public class WaypointVisitedController {
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> getWaypointVisitedById(@PathVariable("id") Long id) {
|
||||
WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointById(id);
|
||||
if (waypointVisited != null) {
|
||||
return new ResponseEntity<>(waypointVisited, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("?userid={id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> getWaypointVisitedByUserId(@PathVariable("id") Long id) {
|
||||
WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByUserId(id);
|
||||
if (waypointVisited != null) {
|
||||
return new ResponseEntity<>(waypointVisited, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("?waypointid={id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> getWaypointVisitedByWaypointId(@PathVariable("id") Long id) {
|
||||
WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByWaypointId(id);
|
||||
if (waypointVisited != null) {
|
||||
@@ -55,6 +35,16 @@ public class WaypointVisitedController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
public ResponseEntity<WaypointsVisitedEntity> getWaypointVisitedByUserId(@PathVariable("id") Long id) {
|
||||
WaypointsVisitedEntity waypointVisited = waypointVisitedService.getWaypointsVisitedByUserId(id);
|
||||
if (waypointVisited != null) {
|
||||
return new ResponseEntity<>(waypointVisited, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("")
|
||||
public ResponseEntity<WaypointsVisitedEntity> createWaypointVisited(@RequestBody WaypointsVisitedEntity waypointVisited) {
|
||||
WaypointsVisitedEntity createdWaypoint = waypointVisitedService.createWaypoint(waypointVisited);
|
||||
|
||||
@@ -61,4 +61,8 @@ public class WaypointsEntity {
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, lat, lon, description, img, locationName);
|
||||
}
|
||||
|
||||
public String getLocationName() {
|
||||
return locationName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@ package ch.progetto152.repository;
|
||||
import ch.progetto152.entity.WaypointsEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface WaypointRepository extends JpaRepository<WaypointsEntity, Long> {
|
||||
|
||||
Optional<WaypointsEntity> findWaypointByName(String name);
|
||||
|
||||
List<WaypointsEntity> findAllByLocationName(String locationName);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,13 +23,20 @@ public class WaypointService {
|
||||
return waypointRepository.findAll();
|
||||
}
|
||||
|
||||
public List<WaypointsEntity> getAllWaypointsByLocation(String locationName) {
|
||||
List<WaypointsEntity> waypoints = waypointRepository.findAllByLocationName(locationName);
|
||||
if (waypoints.isEmpty()) {
|
||||
return null;
|
||||
}else {
|
||||
return waypoints;
|
||||
}
|
||||
}
|
||||
|
||||
public WaypointsEntity getWaypointById(Long id) {
|
||||
return waypointRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public WaypointsEntity getWaypointByName(String name) {
|
||||
return waypointRepository.findWaypointByName(name).orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public WaypointsEntity createWaypoint(WaypointsEntity waypoint) {
|
||||
if (errorChecking.checkWaypoint(waypoint)) {
|
||||
|
||||
@@ -68,7 +68,11 @@ insert into Waypoints (name, lat, lon, description, img, LocationName) values ('
|
||||
'Descrizione del punto 3, un grandissimo',
|
||||
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
|
||||
'Lugano');
|
||||
insert into Waypoints (id, name, lat, lon, description, img, locationName) values (4, 'Punto 2', 46.123, 8.123,
|
||||
'Descrizione del punto 4',
|
||||
'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png',
|
||||
'Locarno');
|
||||
|
||||
insert into User (name, username, password) values ('Mario Rossi', 'mario.rossi', 'password');
|
||||
insert into User (name, username, password) values ('Luca Bianchi', 'luca.bianchi', 'password');
|
||||
insert into User (name, username, password) values ('Giovanni Verdi', 'giovanni.verdi', 'password');
|
||||
insert into User (name, username, password) values ('Giovanni Verdi', 'giovanni.verdi', 'password');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
get:
|
||||
progetto152/location
|
||||
progetto152/location/{location}
|
||||
progetto152/location/id/{id}
|
||||
progetto152/waypoint/{location}
|
||||
progetto152/waypoint/{location}/{id}
|
||||
maybe:
|
||||
|
||||
Reference in New Issue
Block a user