Commit 6376282c authored by Ivaylo Ivanov's avatar Ivaylo Ivanov

US03: Fix bug where the horse jdbc dao returned a false updated_at value, add...

US03: Fix bug where the horse jdbc dao returned a false updated_at value, add additional exception handling to horse update endpoint
parent 62bbb064
...@@ -103,6 +103,10 @@ public class HorseEndpoint { ...@@ -103,6 +103,10 @@ public class HorseEndpoint {
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());
throw new ResponseStatusException(HttpStatus.PARTIAL_CONTENT, throw new ResponseStatusException(HttpStatus.PARTIAL_CONTENT,
"Operation completed with errors: image could not be saved"); "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");
} }
} }
......
...@@ -197,7 +197,7 @@ public class HorseJdbcDao implements HorseDao { ...@@ -197,7 +197,7 @@ public class HorseJdbcDao implements HorseDao {
if (changes == 0) if (changes == 0)
throw new DataAccessException("Updating horse failed, no rows affected") {}; throw new DataAccessException("Updating horse failed, no rows affected") {};
horse.setUpdatedAt(oldHorse.getUpdatedAt()); horse.setCreatedAt(oldHorse.getCreatedAt());
fileDao.delete(oldHorse.getImagePath()); fileDao.delete(oldHorse.getImagePath());
......
...@@ -132,7 +132,7 @@ public abstract class HorseDaoTestBase { ...@@ -132,7 +132,7 @@ public abstract class HorseDaoTestBase {
newHorse.setRace(null); newHorse.setRace(null);
newHorse.setImagePath(null); newHorse.setImagePath(null);
newHorse.setOwner(null); newHorse.setOwner(null);
assertThrows(DataAccessException.class, () -> horseDao.addHorse(newHorse)); assertThrows(DataAccessException.class, () -> horseDao.updateHorse(newHorse));
} }
@Test @Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment