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);
}
@GetMapping("/{name}")
public ResponseEntity<LocationEntity> getLocationByName(@PathVariable("name") String 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("")
public ResponseEntity<LocationEntity> 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<LocationEntity> updateLocation(@PathVariable("id") Long id, @RequestBody LocationEntity location) {
LocationEntity location1 = locationService.updateLocation(id, location);
@PutMapping("/{name}")
public ResponseEntity<LocationEntity> 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<Void> deleteLocation(@PathVariable("id") Long id) {
boolean deleted = locationService.deleteLocation(id);
@DeleteMapping("/{name}")
public ResponseEntity<Void> deleteLocation(@PathVariable("name") String name) {
boolean deleted = locationService.deleteLocation(name);
if (deleted) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {