US01, US03: Fix bug where all whitespaces were considered valid input on horse create and update
This commit is contained in:
parent
a01405e3cc
commit
8e3736848d
@ -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());
|
||||
|
@ -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) {
|
||||
|
@ -17,12 +17,12 @@
|
||||
<form (ngSubmit)="addHorse()" #horseForm="ngForm">
|
||||
<div class="form-group">
|
||||
<label for="name">Name</label>
|
||||
<input type="text" class="form-control" name="name" [(ngModel)]="horse.name" required>
|
||||
<input type="text" class="form-control" name="name" pattern="\S+.*" [(ngModel)]="horse.name" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="description">Description</label>
|
||||
<textarea class="form-control" name="description" [(ngModel)]="horse.description" value=""></textarea>
|
||||
<textarea class="form-control" name="description" pattern="\S+.*" [(ngModel)]="horse.description" value=""></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
@ -17,12 +17,12 @@
|
||||
<form (ngSubmit)="updateHorse()" #horseForm="ngForm">
|
||||
<div class="form-group">
|
||||
<label for="name">Name</label>
|
||||
<input type="text" class="form-control" name="name" [(ngModel)]="horse.name" required>
|
||||
<input type="text" class="form-control" name="name" [(ngModel)]="horse.name" pattern="\S+.*" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="description">Description</label>
|
||||
<textarea class="form-control" name="description" [(ngModel)]="horse.description"></textarea>
|
||||
<textarea class="form-control" name="description" pattern="\S+.*" [(ngModel)]="horse.description"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
Reference in New Issue
Block a user