Success! Horse {{ success }} has been successfully added.
+
+
+
+
+
Add new horse
+
+
\ No newline at end of file
diff --git a/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.scss b/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.scss
new file mode 100644
index 0000000..e69de29
diff --git a/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.ts b/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.ts
new file mode 100644
index 0000000..1ec47ca
--- /dev/null
+++ b/frontend/wendys-friends/src/app/component/add-horse/add-horse.component.ts
@@ -0,0 +1,65 @@
+import { Component, OnInit } from '@angular/core';
+import { Horse } from '../../dto/horse';
+import { HorseService } from '../../service/horse.service';
+
+@Component({
+ selector: 'app-add-horse',
+ templateUrl: './add-horse.component.html',
+ styleUrls: ['./add-horse.component.scss']
+})
+export class AddHorseComponent implements OnInit {
+ error = false;
+ success: string;
+ errorMessage = '';
+ horse: Horse = new Horse(null, null, null, null, null, null, null);
+
+ constructor(private horseService: HorseService) { }
+
+ 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 horse and loads it
+ * @param horse
+ */
+ public addHorse() {
+ console.log("POST horse to API")
+ console.log(this.horse);
+ // TODO: Make it possible for the horse to be added with an owner
+ this.horseService.addHorse(this.horse).subscribe(
+ (result: Horse) => {
+ 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;
+ }
+ }
+}