US01: Make it possible for the user to add a horse through the web UI, add additional validations

This commit is contained in:
2020-03-18 19:32:23 +01:00
parent df76acceeb
commit 01268263de
7 changed files with 16 additions and 21 deletions

View File

@@ -12,6 +12,7 @@ import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import java.lang.invoke.MethodHandles;
import java.text.SimpleDateFormat;
@Service
public class SimpleHorseService implements HorseService {
@@ -33,8 +34,8 @@ public class SimpleHorseService implements HorseService {
@Override
public Horse addHorse(Horse horse) throws ValidationException, DataAccessException {
LOGGER.trace("addHorse({})", horse.toString());
this.validator.validateNewHorse(horse);
LOGGER.trace("addHorse({})", horse.toString());
return horseDao.addHorse(horse);
}
}

View File

@@ -16,6 +16,9 @@ public class Validator {
}
public void validateNewHorse(Horse horse) throws ValidationException {
if(horse.getName() == null || horse.getScore() == 0 || horse.getBirthday() == null || horse.getDescription() == null){
throw new ValidationException("All or some required values missing: name, description, score, birthday");
}
if(horse.getScore() > 5 || horse.getScore() < 1) {
throw new ValidationException("Score value " + horse.getScore() + " not allowed. The score must be an integer between 1 and 5");
}