From 8e3736848dd04fb7721a62aaeec4f6ca9716fc85 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Sun, 5 Apr 2020 18:30:31 +0200 Subject: [PATCH] US01, US03: Fix bug where all whitespaces were considered valid input on horse create and update --- .../assignment/individual/persistence/impl/HorseJdbcDao.java | 4 ++-- .../ac/tuwien/sepm/assignment/individual/util/Validator.java | 4 ++-- .../src/app/component/add-horse/add-horse.component.html | 4 ++-- .../app/component/update-horse/update-horse.component.html | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java index 5c40f46..bf0bb6b 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java @@ -131,7 +131,7 @@ public class HorseJdbcDao implements HorseDao { int changes = jdbcTemplate.update(connection -> { PreparedStatement ps = connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS); - ps.setString(1, horse.getName()); + ps.setString(1, horse.getName().trim()); ps.setString(2, horse.getDescription()); ps.setInt(3, horse.getScore()); ps.setDate(4, horse.getBirthday()); @@ -179,7 +179,7 @@ public class HorseJdbcDao implements HorseDao { int changes = jdbcTemplate.update(connection -> { PreparedStatement ps = connection.prepareStatement(sql); - ps.setString(1, horse.getName()); + ps.setString(1, horse.getName().trim()); ps.setString(2, horse.getDescription()); ps.setInt(3, horse.getScore()); ps.setDate(4, horse.getBirthday()); diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/util/Validator.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/util/Validator.java index 7c19ead..2ab9e1f 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/util/Validator.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/util/Validator.java @@ -33,7 +33,7 @@ public class Validator { } public void validateNewHorse(Horse horse) throws ValidationException { - if(horse.getName() == null || horse.getScore() == 0 || horse.getBirthday() == null || horse.getRace() == null || horse.getImagePath() == null){ + if(horse.getName() == null || horse.getName().isEmpty() || horse.getName().isBlank() || horse.getScore() == 0 || horse.getBirthday() == null || horse.getRace() == null || horse.getImagePath() == null){ throw new ValidationException("All or some required values missing: name, score, birthday, race, imagePath"); } if(horse.getScore() > 5 || horse.getScore() < 1) { @@ -48,7 +48,7 @@ public class Validator { if(horse.getId() == null || horse.getId() == 0) { throw new ValidationException("Horse Id cannot be null or 0"); } - if(horse.getName() == null || horse.getScore() == 0 || horse.getBirthday() == null || horse.getRace() == null || horse.getImagePath() == null){ + if(horse.getName() == null || horse.getName().isEmpty() || horse.getName().isBlank() || horse.getScore() == 0 || horse.getBirthday() == null || horse.getRace() == null || horse.getImagePath() == null){ throw new ValidationException("All or some required values missing: name, score, birthday, race. imagePath"); } if(horse.getScore() > 5 || horse.getScore() < 1) { diff --git a/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.html b/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.html index 5395959..22d1860 100644 --- a/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.html +++ b/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.html @@ -17,12 +17,12 @@
- +
- +
diff --git a/frontend/wendys-friends/src/app/component/update-horse/update-horse.component.html b/frontend/wendys-friends/src/app/component/update-horse/update-horse.component.html index 88c52e6..963135d 100644 --- a/frontend/wendys-friends/src/app/component/update-horse/update-horse.component.html +++ b/frontend/wendys-friends/src/app/component/update-horse/update-horse.component.html @@ -17,12 +17,12 @@
- +
- +