US03: Fix bug where the horse jdbc dao returned a false updated_at value, add additional exception handling to horse update endpoint

This commit is contained in:
Ivaylo Ivanov 2020-03-24 15:12:18 +01:00
parent 62bbb0644b
commit 6376282cbd
3 changed files with 6 additions and 2 deletions

View File

@ -103,6 +103,10 @@ public class HorseEndpoint {
LOGGER.error(e.getMessage());
throw new ResponseStatusException(HttpStatus.PARTIAL_CONTENT,
"Operation completed with errors: image could not be saved");
} catch (NotFoundException e) {
LOGGER.error(e.getMessage());
throw new ResponseStatusException(HttpStatus.NOT_FOUND,
"The horse requested could not be found");
}
}

View File

@ -197,7 +197,7 @@ public class HorseJdbcDao implements HorseDao {
if (changes == 0)
throw new DataAccessException("Updating horse failed, no rows affected") {};
horse.setUpdatedAt(oldHorse.getUpdatedAt());
horse.setCreatedAt(oldHorse.getCreatedAt());
fileDao.delete(oldHorse.getImagePath());

View File

@ -132,7 +132,7 @@ public abstract class HorseDaoTestBase {
newHorse.setRace(null);
newHorse.setImagePath(null);
newHorse.setOwner(null);
assertThrows(DataAccessException.class, () -> horseDao.addHorse(newHorse));
assertThrows(DataAccessException.class, () -> horseDao.updateHorse(newHorse));
}
@Test