diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java index c9e42e5..6bd057b 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java @@ -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); } } 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 f74ed78..ebf8d97 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 @@ -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"); } diff --git a/frontend/wendys-friends/src/app/app-routing.module.ts b/frontend/wendys-friends/src/app/app-routing.module.ts index c39cb3d..a742756 100644 --- a/frontend/wendys-friends/src/app/app-routing.module.ts +++ b/frontend/wendys-friends/src/app/app-routing.module.ts @@ -2,12 +2,14 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import {OwnerComponent} from './component/owner/owner.component'; import { HorseComponent } from './component/horse/horse.component'; +import { AddHorseComponent } from './component/add-horse/add-horse.component'; const routes: Routes = [ {path: '', redirectTo: 'owner', pathMatch: 'full'}, {path: 'owner', component: OwnerComponent}, {path: 'horse', component: HorseComponent}, + {path: 'horse/add', component: AddHorseComponent}, ]; @NgModule({ diff --git a/frontend/wendys-friends/src/app/app.module.ts b/frontend/wendys-friends/src/app/app.module.ts index 028f53d..7de480e 100644 --- a/frontend/wendys-friends/src/app/app.module.ts +++ b/frontend/wendys-friends/src/app/app.module.ts @@ -1,24 +1,28 @@ import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import {HttpClientModule} from '@angular/common/http'; import {AppRoutingModule} from './app-routing.module'; import {AppComponent} from './app.component'; import {HeaderComponent} from './component/header/header.component'; import {OwnerComponent} from './component/owner/owner.component'; -import {HttpClientModule} from '@angular/common/http'; import { HorseComponent } from './component/horse/horse.component'; +import { AddHorseComponent } from './component/add-horse/add-horse.component'; @NgModule({ declarations: [ AppComponent, HeaderComponent, OwnerComponent, - HorseComponent + HorseComponent, + AddHorseComponent ], imports: [ BrowserModule, AppRoutingModule, - HttpClientModule + HttpClientModule, + FormsModule ], providers: [], bootstrap: [AppComponent] diff --git a/frontend/wendys-friends/src/app/component/horse/horse.component.ts b/frontend/wendys-friends/src/app/component/horse/horse.component.ts index da82d7f..3e92b80 100644 --- a/frontend/wendys-friends/src/app/component/horse/horse.component.ts +++ b/frontend/wendys-friends/src/app/component/horse/horse.component.ts @@ -41,21 +41,6 @@ export class HorseComponent implements OnInit { ); } - /** - * Creates a new horse and loads it - * @param horse - */ - private addHorse(horse: Horse) { - this.horseService.addHorse(horse).subscribe( - (horse: Horse) => { - this.horse = horse; - }, - error => { - this.defaultServiceErrorHandling(error); - } - ); - } - private defaultServiceErrorHandling(error: any) { console.log(error); this.error = true; diff --git a/frontend/wendys-friends/src/app/global/globals.ts b/frontend/wendys-friends/src/app/global/globals.ts index a80e06e..6b90751 100644 --- a/frontend/wendys-friends/src/app/global/globals.ts +++ b/frontend/wendys-friends/src/app/global/globals.ts @@ -4,5 +4,5 @@ import {Injectable} from '@angular/core'; providedIn: 'root' }) export class Globals { - readonly backendUri: string = 'http://localhost:8080/'; + readonly backendUri: string = 'http://localhost:8080'; } diff --git a/frontend/wendys-friends/src/app/service/horse.service.ts b/frontend/wendys-friends/src/app/service/horse.service.ts index 1f0871c..ecfb9ac 100644 --- a/frontend/wendys-friends/src/app/service/horse.service.ts +++ b/frontend/wendys-friends/src/app/service/horse.service.ts @@ -27,7 +27,7 @@ export class HorseService { * @param horse */ addHorse(horse: Horse): Observable { - console.log('Add new horse ' + horse); + console.log('Add new horse ' + JSON.stringify(horse)); return this.httpClient.post(this.messageBaseUri, horse); } }