From 3cc36466df015415fe199a8ae2676f98cd5b1cb6 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Sat, 28 Mar 2020 09:27:59 +0100 Subject: [PATCH] US10: Show a list of the owned horses on the owner view page --- .../list-owners/list-owners.component.html | 1 + .../app/component/owner/owner.component.html | 34 +++++++++++++------ .../app/component/owner/owner.component.ts | 24 +++++++++++-- .../src/app/service/owner.service.ts | 10 ++++++ 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html b/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html index 8322421..ed10cb3 100644 --- a/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html +++ b/frontend/wendys-friends/src/app/component/list-owners/list-owners.component.html @@ -29,6 +29,7 @@ {{ id + 1 }} {{ owner.name }} + diff --git a/frontend/wendys-friends/src/app/component/owner/owner.component.html b/frontend/wendys-friends/src/app/component/owner/owner.component.html index f2ceeb4..d1bdd5a 100644 --- a/frontend/wendys-friends/src/app/component/owner/owner.component.html +++ b/frontend/wendys-friends/src/app/component/owner/owner.component.html @@ -6,14 +6,28 @@
- +

Owner Info for {{ owner.name }}

+
+

Horses:

+ + + + + + + + + + + + + + + +
#NameActions
{{ id + 1 }}{{ horse.name }} + +
+ +

Owner has no horses assigned.

+
- - diff --git a/frontend/wendys-friends/src/app/component/owner/owner.component.ts b/frontend/wendys-friends/src/app/component/owner/owner.component.ts index 95d40fa..2684766 100644 --- a/frontend/wendys-friends/src/app/component/owner/owner.component.ts +++ b/frontend/wendys-friends/src/app/component/owner/owner.component.ts @@ -1,6 +1,8 @@ import {Component, OnInit} from '@angular/core'; import {OwnerService} from '../../service/owner.service'; import {Owner} from '../../dto/owner'; +import { ActivatedRoute } from '@angular/router'; +import { Horse } from 'src/app/dto/horse'; @Component({ selector: 'app-owner', @@ -12,12 +14,15 @@ export class OwnerComponent implements OnInit { error = false; errorMessage = ''; owner: Owner; + horses: Array - constructor(private ownerService: OwnerService) { + constructor(private ownerService: OwnerService, private route: ActivatedRoute) { } ngOnInit() { - this.loadOwner(1); + const ownerId: string = this.route.snapshot.paramMap.get('id'); + this.loadOwner(parseInt(ownerId)); + this.loadOwnerHorses(parseInt(ownerId)); } /** @@ -42,6 +47,21 @@ export class OwnerComponent implements OnInit { ); } + /** + * Load the horses of the owner + * @param id of the owner + */ + private loadOwnerHorses(id: number) { + this.ownerService.getOwnerHorses(id).subscribe( + (horses: Array) => { + this.horses = horses; + }, + error => { + console.log(error); + } + ); + } + private defaultServiceErrorHandling(error: any) { console.log(error); this.error = true; diff --git a/frontend/wendys-friends/src/app/service/owner.service.ts b/frontend/wendys-friends/src/app/service/owner.service.ts index 67811db..e0072d4 100644 --- a/frontend/wendys-friends/src/app/service/owner.service.ts +++ b/frontend/wendys-friends/src/app/service/owner.service.ts @@ -3,6 +3,7 @@ import {HttpClient, HttpParams} from '@angular/common/http'; import {Globals} from '../global/globals'; import {Observable} from 'rxjs'; import {Owner} from '../dto/owner'; +import { Horse } from '../dto/horse'; @Injectable({ providedIn: 'root' @@ -40,6 +41,15 @@ export class OwnerService { return this.httpClient.get>(this.messageBaseUri, { params: filter }); } + /** + * Load all horses, owned by the specified owner, from the backend + * @param id + */ + getOwnerHorses(id: number): Observable> { + console.log('Load all horses for owner ' + id); + return this.httpClient.get>(this.messageBaseUri + '/' + id + '/horses'); + } + /** * Adds a specific owner to the backend and loads it if successful * @param owner