From 1e8610182c5bd2bb642c8a8cfa2455ff4c6b1eb2 Mon Sep 17 00:00:00 2001 From: ExostFlash Date: Thu, 10 Apr 2025 22:00:35 +0200 Subject: [PATCH] Add api --- src/app/app.module.ts | 4 +- .../cars/car-form/car-form.component.ts | 30 +++++++++--- .../cars/car-list/car-list.component.html | 46 ++++++++++++++++--- .../essentials/footer/footer.component.html | 21 +++++---- .../essentials/header/header.component.html | 2 +- src/app/interfaces/car.ts | 1 + src/app/services/car.service.ts | 35 +++++++++++--- src/styles.css | 4 ++ 8 files changed, 113 insertions(+), 30 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 592d076..e173b21 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,6 +4,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { FormsModule } from '@angular/forms'; +import { HttpClientModule } from '@angular/common/http'; /* Essentials */ import { HeaderComponent } from './components/essentials/header/header.component'; @@ -30,7 +31,8 @@ import { CarItemComponent } from './components/cars/car-item/car-item.component' imports: [ BrowserModule, AppRoutingModule, - FormsModule + FormsModule, + HttpClientModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/components/cars/car-form/car-form.component.ts b/src/app/components/cars/car-form/car-form.component.ts index 6f9a0e4..c2af2ec 100644 --- a/src/app/components/cars/car-form/car-form.component.ts +++ b/src/app/components/cars/car-form/car-form.component.ts @@ -30,11 +30,29 @@ export class CarFormComponent { } saveCar() { - if (this.editMode) { - this.carService.updateCar(this.car); - } else { - this.carService.addCar(this.car); - } - this.router.navigate(['/list']); + // Vérifie que l'objet car a les bonnes propriétés + console.log('Car avant image:', this.car); + + // Récupération de l'image via l'API + const { marque, modele, couleur } = this.car; + this.carService.getCarImage(marque, modele, couleur).subscribe((imageUrl) => { + + // Mise à jour de l'objet car avec l'image + const carWithImage = { ...this.car, image: imageUrl }; + + if (this.editMode) { + // Mise à jour de la voiture + this.carService.updateCar(carWithImage); + } else { + // Ajout de la nouvelle voiture + this.carService.addCar(carWithImage); + } + + // Redirection après l'ajout/mise à jour + this.router.navigate(['/list']); + }, error => { + // Gestion des erreurs + console.error('Erreur lors de la récupération de l\'image:', error); + }); } } diff --git a/src/app/components/cars/car-list/car-list.component.html b/src/app/components/cars/car-list/car-list.component.html index a33becf..b0fce30 100644 --- a/src/app/components/cars/car-list/car-list.component.html +++ b/src/app/components/cars/car-list/car-list.component.html @@ -1,6 +1,40 @@ -

Liste des Voitures

-
-
{{ car.marque }} - {{ car.modele }} - {{ car.couleur }}
- - -
\ No newline at end of file +
+
+

Liste des Voitures

+

Visualisez et gérez vos véhicules enregistrés

+
+ +
+ + + + + + + + + + + + + + + + + + + +
ImageMarqueModèleCouleurActions
+ Image voiture + {{ car.marque }}{{ car.modele }} + {{ car.couleur }} + + + +
+
+
diff --git a/src/app/components/essentials/footer/footer.component.html b/src/app/components/essentials/footer/footer.component.html index 1eb5912..50f515d 100644 --- a/src/app/components/essentials/footer/footer.component.html +++ b/src/app/components/essentials/footer/footer.component.html @@ -1,13 +1,14 @@ - + \ No newline at end of file diff --git a/src/app/components/essentials/header/header.component.html b/src/app/components/essentials/header/header.component.html index 239147e..44a912c 100644 --- a/src/app/components/essentials/header/header.component.html +++ b/src/app/components/essentials/header/header.component.html @@ -1,5 +1,5 @@ -