edit and delete with error

This commit is contained in:
2023-05-07 12:03:22 +02:00
parent fa8b1b739b
commit ceec6218fa
3 changed files with 11 additions and 26 deletions

View File

@@ -25,7 +25,6 @@ public class LocationController {
return new ResponseEntity<>(Locations, HttpStatus.OK); return new ResponseEntity<>(Locations, HttpStatus.OK);
} }
@GetMapping("/{name}") @GetMapping("/{name}")
public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("name") String name) { public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("name") String name) {
LocationEntity location = locationService.getLocationByName(name); LocationEntity location = locationService.getLocationByName(name);
@@ -36,16 +35,6 @@ public class LocationController {
} }
} }
@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 {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@PostMapping("") @PostMapping("")
public ResponseEntity<LocationEntity> createLocation(@RequestBody LocationEntity location) { public ResponseEntity<LocationEntity> createLocation(@RequestBody LocationEntity location) {
LocationEntity createdLocation = locationService.createLocation(location); LocationEntity createdLocation = locationService.createLocation(location);
@@ -55,9 +44,9 @@ public class LocationController {
return new ResponseEntity<>(createdLocation, HttpStatus.CREATED); return new ResponseEntity<>(createdLocation, HttpStatus.CREATED);
} }
@PutMapping("/{id}") @PutMapping("/{name}")
public ResponseEntity<LocationEntity> updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) { public ResponseEntity<LocationEntity> updateLocation(@PathVariable("name") String name, @RequestBody LocationEntity location) {
LocationEntity location1 = locationService.updateLocation(id, location); LocationEntity location1 = locationService.updateLocation(name, location);
if (location1 != null) { if (location1 != null) {
return new ResponseEntity<>(location1, HttpStatus.OK); return new ResponseEntity<>(location1, HttpStatus.OK);
} else { } else {
@@ -65,9 +54,9 @@ public class LocationController {
} }
} }
@DeleteMapping("/{id}") @DeleteMapping("/{name}")
public ResponseEntity<Void> deleteLocation(@PathVariable("id") Long id) { public ResponseEntity<Void> deleteLocation(@PathVariable("name") String name) {
boolean deleted = locationService.deleteLocation(id); boolean deleted = locationService.deleteLocation(name);
if (deleted) { if (deleted) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else { } else {

View File

@@ -49,7 +49,7 @@ public class WaypointVisitedController {
if (waypointVisited == null) { if (waypointVisited == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} else if (!waypointVisited) { } else if (!waypointVisited) {
return new ResponseEntity<>(false, HttpStatus.NOT_FOUND); return new ResponseEntity<>(false, HttpStatus.OK);
} else { } else {
return new ResponseEntity<>(true, HttpStatus.OK); return new ResponseEntity<>(true, HttpStatus.OK);
} }

View File

@@ -23,10 +23,6 @@ public class LocationService {
return locationRepository.findAll(); return locationRepository.findAll();
} }
public LocationEntity getLocationById(Long id) {
return locationRepository.findById(id).orElse(null);
}
public LocationEntity getLocationByName(String name){ public LocationEntity getLocationByName(String name){
return locationRepository.findLocationByLocation(name).orElse(null); return locationRepository.findLocationByLocation(name).orElse(null);
} }
@@ -39,8 +35,8 @@ public class LocationService {
} }
} }
public LocationEntity updateLocation(Long id, LocationEntity Location) { public LocationEntity updateLocation(String name, LocationEntity Location) {
LocationEntity location1 = getLocationById(id); LocationEntity location1 = getLocationByName(name);
if (location1 != null) { if (location1 != null) {
location1.setLocation(Location.getLocation()); location1.setLocation(Location.getLocation());
location1.setRegion(Location.getRegion()); 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); boolean exists = locationRepository.existsById(id);
if(!exists){ if(!exists){
return false; return false;
} }
locationRepository.deleteById(id); locationRepository.deleteByName(name);
return true; return true;
} }
} }