Success! Owner {{ success }} has been successfully added.
+
+
+
+
+
Add new owner
+
+
\ No newline at end of file
diff --git a/frontend/wendys-friends/src/app/component/add-owner/add-owner.component.scss b/frontend/wendys-friends/src/app/component/add-owner/add-owner.component.scss
new file mode 100644
index 0000000..e69de29
diff --git a/frontend/wendys-friends/src/app/component/add-owner/add-owner.component.ts b/frontend/wendys-friends/src/app/component/add-owner/add-owner.component.ts
new file mode 100644
index 0000000..7db603c
--- /dev/null
+++ b/frontend/wendys-friends/src/app/component/add-owner/add-owner.component.ts
@@ -0,0 +1,66 @@
+import { Component, OnInit } from '@angular/core';
+import { Owner } from '../../dto/owner';
+import { OwnerService } from 'src/app/service/owner.service';
+
+@Component({
+ selector: 'app-add-owner',
+ templateUrl: './add-owner.component.html',
+ styleUrls: ['./add-owner.component.scss']
+})
+export class AddOwnerComponent implements OnInit {
+ error = false;
+ success: string;
+ errorMessage = '';
+ owner: Owner = new Owner(null, null);
+
+ constructor(private ownerService: OwnerService) { }
+
+ ngOnInit(): void {
+ }
+
+ /**
+ * Will be called on a click on the success alert close button
+ */
+ public vanishAlert() {
+ this.success = null;
+ }
+
+ /**
+ * Will be called on a click on the error alert close button
+ */
+ public vanishError() {
+ this.errorMessage = null;
+ }
+
+ /**
+ * Creates a new owner and loads it
+ * @param owner
+ */
+ public addOwner() {
+ console.log("POST owner to API")
+ console.log(this.owner);
+ // TODO: Make it possible for the owner to be added with an owner
+ this.ownerService.addOwner(this.owner).subscribe(
+ (result: Owner) => {
+ this.success = result.name;
+ },
+ error => {
+ this.defaultServiceErrorHandling(error);
+ }
+ );
+ }
+
+ private defaultServiceErrorHandling(error: any) {
+ console.log(error);
+ this.error = true;
+ if (error.status === 0) {
+ // If status is 0, the backend is probably down
+ this.errorMessage = 'The backend seems not to be reachable';
+ } else if (error.error.message === 'No message available') {
+ // If no detailed error message is provided, fall back to the simple error name
+ this.errorMessage = error.error.error;
+ } else {
+ this.errorMessage = error.error.message;
+ }
+ }
+}
diff --git a/frontend/wendys-friends/src/app/service/owner.service.ts b/frontend/wendys-friends/src/app/service/owner.service.ts
index ed45379..c8ee159 100644
--- a/frontend/wendys-friends/src/app/service/owner.service.ts
+++ b/frontend/wendys-friends/src/app/service/owner.service.ts
@@ -23,4 +23,12 @@ export class OwnerService {
return this.httpClient.get(this.messageBaseUri + '/' + id);
}
+ /**
+ * Adds a specific owner to the backend and loads it if successful
+ * @param owner
+ */
+ addOwner(owner: Owner): Observable {
+ console.log('Add new owner ' + JSON.stringify(owner));
+ return this.httpClient.post(this.messageBaseUri, owner);
+ }
}