Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Wendys Racing Horses
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
tu-wien
Wendys Racing Horses
Commits
01268263
Commit
01268263
authored
Mar 18, 2020
by
Ivaylo Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
US01: Make it possible for the user to add a horse through the web UI, add additional validations
parent
df76acce
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
16 additions
and
21 deletions
+16
-21
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java
...ssignment/individual/service/impl/SimpleHorseService.java
+2
-1
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/util/Validator.java
.../ac/tuwien/sepm/assignment/individual/util/Validator.java
+3
-0
frontend/wendys-friends/src/app/app-routing.module.ts
frontend/wendys-friends/src/app/app-routing.module.ts
+2
-0
frontend/wendys-friends/src/app/app.module.ts
frontend/wendys-friends/src/app/app.module.ts
+7
-3
frontend/wendys-friends/src/app/component/horse/horse.component.ts
...wendys-friends/src/app/component/horse/horse.component.ts
+0
-15
frontend/wendys-friends/src/app/global/globals.ts
frontend/wendys-friends/src/app/global/globals.ts
+1
-1
frontend/wendys-friends/src/app/service/horse.service.ts
frontend/wendys-friends/src/app/service/horse.service.ts
+1
-1
No files found.
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java
View file @
01268263
...
@@ -12,6 +12,7 @@ import org.springframework.dao.DataAccessException;
...
@@ -12,6 +12,7 @@ import org.springframework.dao.DataAccessException;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.lang.invoke.MethodHandles
;
import
java.lang.invoke.MethodHandles
;
import
java.text.SimpleDateFormat
;
@Service
@Service
public
class
SimpleHorseService
implements
HorseService
{
public
class
SimpleHorseService
implements
HorseService
{
...
@@ -33,8 +34,8 @@ public class SimpleHorseService implements HorseService {
...
@@ -33,8 +34,8 @@ public class SimpleHorseService implements HorseService {
@Override
@Override
public
Horse
addHorse
(
Horse
horse
)
throws
ValidationException
,
DataAccessException
{
public
Horse
addHorse
(
Horse
horse
)
throws
ValidationException
,
DataAccessException
{
LOGGER
.
trace
(
"addHorse({})"
,
horse
.
toString
());
this
.
validator
.
validateNewHorse
(
horse
);
this
.
validator
.
validateNewHorse
(
horse
);
LOGGER
.
trace
(
"addHorse({})"
,
horse
.
toString
());
return
horseDao
.
addHorse
(
horse
);
return
horseDao
.
addHorse
(
horse
);
}
}
}
}
backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/util/Validator.java
View file @
01268263
...
@@ -16,6 +16,9 @@ public class Validator {
...
@@ -16,6 +16,9 @@ public class Validator {
}
}
public
void
validateNewHorse
(
Horse
horse
)
throws
ValidationException
{
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
)
{
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"
);
throw
new
ValidationException
(
"Score value "
+
horse
.
getScore
()
+
" not allowed. The score must be an integer between 1 and 5"
);
}
}
...
...
frontend/wendys-friends/src/app/app-routing.module.ts
View file @
01268263
...
@@ -2,12 +2,14 @@ import { NgModule } from '@angular/core';
...
@@ -2,12 +2,14 @@ import { NgModule } from '@angular/core';
import
{
Routes
,
RouterModule
}
from
'
@angular/router
'
;
import
{
Routes
,
RouterModule
}
from
'
@angular/router
'
;
import
{
OwnerComponent
}
from
'
./component/owner/owner.component
'
;
import
{
OwnerComponent
}
from
'
./component/owner/owner.component
'
;
import
{
HorseComponent
}
from
'
./component/horse/horse.component
'
;
import
{
HorseComponent
}
from
'
./component/horse/horse.component
'
;
import
{
AddHorseComponent
}
from
'
./component/add-horse/add-horse.component
'
;
const
routes
:
Routes
=
[
const
routes
:
Routes
=
[
{
path
:
''
,
redirectTo
:
'
owner
'
,
pathMatch
:
'
full
'
},
{
path
:
''
,
redirectTo
:
'
owner
'
,
pathMatch
:
'
full
'
},
{
path
:
'
owner
'
,
component
:
OwnerComponent
},
{
path
:
'
owner
'
,
component
:
OwnerComponent
},
{
path
:
'
horse
'
,
component
:
HorseComponent
},
{
path
:
'
horse
'
,
component
:
HorseComponent
},
{
path
:
'
horse/add
'
,
component
:
AddHorseComponent
},
];
];
@
NgModule
({
@
NgModule
({
...
...
frontend/wendys-friends/src/app/app.module.ts
View file @
01268263
import
{
BrowserModule
}
from
'
@angular/platform-browser
'
;
import
{
BrowserModule
}
from
'
@angular/platform-browser
'
;
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
FormsModule
}
from
'
@angular/forms
'
;
import
{
HttpClientModule
}
from
'
@angular/common/http
'
;
import
{
AppRoutingModule
}
from
'
./app-routing.module
'
;
import
{
AppRoutingModule
}
from
'
./app-routing.module
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
import
{
AppComponent
}
from
'
./app.component
'
;
import
{
HeaderComponent
}
from
'
./component/header/header.component
'
;
import
{
HeaderComponent
}
from
'
./component/header/header.component
'
;
import
{
OwnerComponent
}
from
'
./component/owner/owner.component
'
;
import
{
OwnerComponent
}
from
'
./component/owner/owner.component
'
;
import
{
HttpClientModule
}
from
'
@angular/common/http
'
;
import
{
HorseComponent
}
from
'
./component/horse/horse.component
'
;
import
{
HorseComponent
}
from
'
./component/horse/horse.component
'
;
import
{
AddHorseComponent
}
from
'
./component/add-horse/add-horse.component
'
;
@
NgModule
({
@
NgModule
({
declarations
:
[
declarations
:
[
AppComponent
,
AppComponent
,
HeaderComponent
,
HeaderComponent
,
OwnerComponent
,
OwnerComponent
,
HorseComponent
HorseComponent
,
AddHorseComponent
],
],
imports
:
[
imports
:
[
BrowserModule
,
BrowserModule
,
AppRoutingModule
,
AppRoutingModule
,
HttpClientModule
HttpClientModule
,
FormsModule
],
],
providers
:
[],
providers
:
[],
bootstrap
:
[
AppComponent
]
bootstrap
:
[
AppComponent
]
...
...
frontend/wendys-friends/src/app/component/horse/horse.component.ts
View file @
01268263
...
@@ -41,21 +41,6 @@ export class HorseComponent implements OnInit {
...
@@ -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
)
{
private
defaultServiceErrorHandling
(
error
:
any
)
{
console
.
log
(
error
);
console
.
log
(
error
);
this
.
error
=
true
;
this
.
error
=
true
;
...
...
frontend/wendys-friends/src/app/global/globals.ts
View file @
01268263
...
@@ -4,5 +4,5 @@ import {Injectable} from '@angular/core';
...
@@ -4,5 +4,5 @@ import {Injectable} from '@angular/core';
providedIn
:
'
root
'
providedIn
:
'
root
'
})
})
export
class
Globals
{
export
class
Globals
{
readonly
backendUri
:
string
=
'
http://localhost:8080
/
'
;
readonly
backendUri
:
string
=
'
http://localhost:8080
'
;
}
}
frontend/wendys-friends/src/app/service/horse.service.ts
View file @
01268263
...
@@ -27,7 +27,7 @@ export class HorseService {
...
@@ -27,7 +27,7 @@ export class HorseService {
* @param horse
* @param horse
*/
*/
addHorse
(
horse
:
Horse
):
Observable
<
Horse
>
{
addHorse
(
horse
:
Horse
):
Observable
<
Horse
>
{
console
.
log
(
'
Add new horse
'
+
horse
);
console
.
log
(
'
Add new horse
'
+
JSON
.
stringify
(
horse
)
);
return
this
.
httpClient
.
post
<
Horse
>
(
this
.
messageBaseUri
,
horse
);
return
this
.
httpClient
.
post
<
Horse
>
(
this
.
messageBaseUri
,
horse
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment