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 @@ -
Visualisez et gérez vos véhicules enregistrés
+| Image | +Marque | +Modèle | +Couleur | +Actions | +
|---|---|---|---|---|
|
+ |
+ {{ car.marque }} | +{{ car.modele }} | ++ {{ car.couleur }} + | ++ + + | +