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 {

View File

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

View File

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