Skip to content
Snippets Groups Projects
Verified Commit caf2f9a3 authored by Adam Krídl's avatar Adam Krídl
Browse files

Make CountryFacadeImpl to use new exception handling mechanism

parent 6e76ae57
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ public class CountryFacadeImpl implements CountryFacade<Long> {
@Override
public Optional<CountryDto> findById(Long id) {
Country foundEntity = countryService.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Country with id " + id + " not found."));
.orElseThrow(ResourceNotFoundException::new);
return Optional.of(countryMapper.toDto(foundEntity));
}
......@@ -48,6 +48,9 @@ public class CountryFacadeImpl implements CountryFacade<Long> {
@Override
public void deleteById(Long id) {
if (!countryService.existsById(id)) {
throw new ResourceNotFoundException();
}
countryService.deleteById(id);
}
......@@ -58,10 +61,12 @@ public class CountryFacadeImpl implements CountryFacade<Long> {
@Override
public CountryDto update(Long id, NewCountryDtoRequest newCountryDtoRequest) {
Country updatedEntity = countryService.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Country with id " + id + " not found."));
updatedEntity.setName(newCountryDtoRequest.getName());
countryService.save(updatedEntity);
if (!countryService.existsById(id)) {
throw new ResourceNotFoundException();
}
Country newEntity = countryMapper.toEntityFromNewRequest(newCountryDtoRequest);
Country updatedEntity = countryService.update(id, newEntity);
return countryMapper.toDto(updatedEntity);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment