From be9e510a94e8082338d0c97238bab5ca3e5373a3 Mon Sep 17 00:00:00 2001
From: HarmandI <isabelle44.74@gmail.com>
Date: Tue, 22 Mar 2022 11:47:05 +0100
Subject: [PATCH] erreur

---
 .../formulaire/formulaire.component.html      |  2 +-
 .../formulaire/formulaire.component.ts        | 15 +++++++++------
 .../page-ajouter/page-ajouter.component.html  |  2 +-
 .../page-ajouter/page-ajouter.component.ts    | 19 ++++++++++---------
 .../modules/admin/services/admin.service.ts   |  2 +-
 5 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.html b/src/app/modules/admin/components/formulaire/formulaire.component.html
index e8d5b46..3bdb12d 100644
--- a/src/app/modules/admin/components/formulaire/formulaire.component.html
+++ b/src/app/modules/admin/components/formulaire/formulaire.component.html
@@ -1,5 +1,5 @@
 <div class="form-plant">
-      <form [formGroup]="plantForm">
+      <form [formGroup]="plantForm"(ngSubmit)="onSubmit()">
         <div class="form-floating">
           <input
             type="text"
diff --git a/src/app/modules/admin/components/formulaire/formulaire.component.ts b/src/app/modules/admin/components/formulaire/formulaire.component.ts
index 9bce5b6..78dc9ea 100644
--- a/src/app/modules/admin/components/formulaire/formulaire.component.ts
+++ b/src/app/modules/admin/components/formulaire/formulaire.component.ts
@@ -1,4 +1,4 @@
-import { Component, Input, OnInit } from '@angular/core';
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
 import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
 import { Plant } from '../../models/plant';
 import { AdminService } from '../../services/admin.service';
@@ -13,6 +13,7 @@ export class FormulaireComponent implements OnInit {
 
   @Input() plantInfos!: Plant;
   @Input()buttonLabel!:String;
+  @Output()submitted= new EventEmitter<Plant>();
   constructor(private fb : FormBuilder, private adminService: AdminService) {
 
   }
@@ -28,10 +29,12 @@ export class FormulaireComponent implements OnInit {
     });
   }
 
-  
-
-  addPlant(){}
-
-  updatePlant(){}
+  public onSubmit(): void {
+    this.submitted.emit(this.plantForm.value);
+  }
+}
+
+function newEventEmitter() {
+  throw new Error('Function not implemented.');
 }
 
diff --git a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html
index 2521453..650250d 100644
--- a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html
+++ b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.html
@@ -1,2 +1,2 @@
 <h1>Ajouter une plante</h1>
-<app-formulaire [buttonLabel]="'Ajouter une plante'"></app-formulaire>
+<app-formulaire (submitted)="onSubmitted($event)" [buttonLabel]="'Ajouter une plante'"></app-formulaire>
diff --git a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts
index bda58f2..63662d3 100644
--- a/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts
+++ b/src/app/modules/admin/pages/page-ajouter/page-ajouter.component.ts
@@ -21,6 +21,7 @@ import { AdminService } from '../../services/admin.service';
 export class PageAjouterComponent implements OnInit {
   public plantForm: FormGroup;
   public isAdd: boolean = false;
+  public newplant = new Plant();
 
 
   constructor(private fb: FormBuilder, private router: Router, private adminService: AdminService) {
@@ -32,7 +33,7 @@ export class PageAjouterComponent implements OnInit {
 
   }
 
-  public onSubmit(): void {
+  public onSubmitted(submittedPlant: Plant): void {
     const nameValue = this.plantForm.value['nameFC'];
     const priceValue = this.plantForm.value['priceFc'];
     const quantityValue = this.plantForm.value['quantityFc'];
@@ -43,18 +44,18 @@ export class PageAjouterComponent implements OnInit {
     const idValue = this.plantForm.value[''];
 
     const plant : Plant = {
-      name: nameValue,
-      price: priceValue,
-      quantity: quantityValue,
-      inStock: [inStockValue],
-      category: [categoryValue],
-      urlPicture: 'https//picsum.photos/id/18/200/300',
-      rating: ratingValue,
+      product_name: nameValue,
+      product_price: priceValue,
+      product_qty: quantityValue,
+      product_instock: [inStockValue],
+      product_breadcrumb_label: [categoryValue],
+      product_url_picture: 'https//picsum.photos/id/18/200/300',
+      product_rating: ratingValue,
       id: idValue,
     };
     console.log("coco",plant);
 
-    this.adminService.addPlant(plant)?.subscribe((resp)=>{
+    this.adminService.addPlant(submittedPlant)?.subscribe((resp)=>{
     })
     this.router.navigate(['admin']);
   }
diff --git a/src/app/modules/admin/services/admin.service.ts b/src/app/modules/admin/services/admin.service.ts
index aa94aa9..9b34b5b 100644
--- a/src/app/modules/admin/services/admin.service.ts
+++ b/src/app/modules/admin/services/admin.service.ts
@@ -38,7 +38,7 @@ export class AdminService {
   }
 
   addPlant(plant: Plant): Observable<any> | void {
-    return this.httpClient.post(`${this.apiUrl}`, plant);
+    return this.httpClient.post(`${this.apiUrl}/list_products`, plant);
   }
   onClickDelete(id: number): Observable<any> {
     return this.httpClient.delete<any>(`${this.apiUrl}/list_products/${id}`).pipe(