US07: Fix bug where all whitespaces were considered valid input on owner update

This commit is contained in:
Ivaylo Ivanov 2020-04-05 18:37:08 +02:00
parent 8e3736848d
commit 3b1bae0902
4 changed files with 25 additions and 25 deletions

View File

@ -165,7 +165,7 @@ public class OwnerJdbcDao implements OwnerDao {
int changes = jdbcTemplate.update(connection -> { int changes = jdbcTemplate.update(connection -> {
PreparedStatement ps = connection.prepareStatement(sql); PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, owner.getName()); ps.setString(1, owner.getName().trim());
ps.setObject(2, owner.getUpdatedAt()); ps.setObject(2, owner.getUpdatedAt());
ps.setObject(3, owner.getId()); ps.setObject(3, owner.getId());
return ps; return ps;

View File

@ -21,7 +21,7 @@ public class Validator {
if(owner.getId() == null || owner.getId() == 0) { if(owner.getId() == null || owner.getId() == 0) {
throw new ValidationException("Owner Id cannot be null or 0"); throw new ValidationException("Owner Id cannot be null or 0");
} }
if(owner.getName() == null || owner.getName().isEmpty()) { if(owner.getName() == null || owner.getName().isEmpty() || owner.getName().isBlank()) {
throw new ValidationException("Required value for owner missing: name"); throw new ValidationException("Required value for owner missing: name");
} }
} }

View File

@ -17,7 +17,7 @@
<form (ngSubmit)="addOwner()" #ownerForm="ngForm"> <form (ngSubmit)="addOwner()" #ownerForm="ngForm">
<div class="form-group"> <div class="form-group">
<label for="name">Name</label> <label for="name">Name</label>
<input type="text" class="form-control" name="name" [(ngModel)]="owner.name" pattern="\s*\S+.*" required> <input type="text" class="form-control" name="name" [(ngModel)]="owner.name" pattern="\S+.*" required>
</div> </div>
<button type="submit" class="btn btn-success" [disabled]="!ownerForm.form.valid" (submit)="addOwner()">Submit</button> <button type="submit" class="btn btn-success" [disabled]="!ownerForm.form.valid" (submit)="addOwner()">Submit</button>

View File

@ -1,26 +1,26 @@
<div *ngIf="error" class="alert alert-danger alert-dismissible fade show" role="alert"> <div *ngIf="error" class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error! </strong> {{ errorMessage }} <strong>Error! </strong> {{ errorMessage }}
<button type="button" (click)="vanishError()" class="close" data-dismiss="alert" aria-label="Close"> <button type="button" (click)="vanishError()" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div *ngIf="success" class="alert alert-success alert-dismissible fade show" role="alert"> <div *ngIf="success" class="alert alert-success alert-dismissible fade show" role="alert">
<p><strong>Success! </strong> Owner {{ success }} has been successfully updated. </p> <p><strong>Success! </strong> Owner {{ success }} has been successfully updated. </p>
<button type="button" (click)="vanishAlert()" class="close" data-dismiss="alert" aria-label="Close"> <button type="button" (click)="vanishAlert()" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="container"> <div class="container">
<h1>Update owner</h1> <h1>Update owner</h1>
<form (ngSubmit)="updateOwner()" #ownerForm="ngForm"> <form (ngSubmit)="updateOwner()" #ownerForm="ngForm">
<div class="form-group"> <div class="form-group">
<label for="name">Name</label> <label for="name">Name</label>
<input type="text" class="form-control" name="name" [(ngModel)]="owner.name" required> <input type="text" class="form-control" name="name" pattern="\S+.*" [(ngModel)]="owner.name" required>
</div> </div>
<button type="submit" class="btn btn-success float-left" [disabled]="!ownerForm.form.valid" (submit)="updateOwner()">Submit</button> <button type="submit" class="btn btn-success float-left" [disabled]="!ownerForm.form.valid" (submit)="updateOwner()">Submit</button>
<a class="btn btn-light float-right" href="owner">Cancel</a> <a class="btn btn-light float-right" href="owner">Cancel</a>
</form> </form>
</div> </div>