modif console.log & modif maj

This commit is contained in:
ExostFlash 2025-05-14 13:29:01 +02:00
parent 1e8610182c
commit 99e109b056
3 changed files with 14 additions and 5 deletions

View file

@ -106,5 +106,8 @@
} }
} }
} }
},
"cli": {
"analytics": false
} }
} }

View file

@ -30,9 +30,6 @@ export class CarFormComponent {
} }
saveCar() { saveCar() {
// 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 // Récupération de l'image via l'API
const { marque, modele, couleur } = this.car; const { marque, modele, couleur } = this.car;
this.carService.getCarImage(marque, modele, couleur).subscribe((imageUrl) => { this.carService.getCarImage(marque, modele, couleur).subscribe((imageUrl) => {

View file

@ -18,6 +18,10 @@ export class CarService {
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
private capitalizeFirstLetter(text: string): string {
return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
}
getCars(): Car[] { getCars(): Car[] {
return this.cars; return this.cars;
} }
@ -34,7 +38,6 @@ export class CarService {
return this.http.get<any>(apiUrl).pipe( return this.http.get<any>(apiUrl).pipe(
map((res) => { map((res) => {
console.log('Réponse de l\'API Google Custom Search:', res); // Ajout d'un log pour vérifier la réponse de l'API
return res.items?.[0]?.link || 'https://via.placeholder.com/100x60?text=Voiture'; return res.items?.[0]?.link || 'https://via.placeholder.com/100x60?text=Voiture';
}), }),
catchError((error: HttpErrorResponse) => { catchError((error: HttpErrorResponse) => {
@ -47,12 +50,18 @@ export class CarService {
addCar(car: Car) { addCar(car: Car) {
car.id = Date.now(); car.id = Date.now();
car.marque = this.capitalizeFirstLetter(car.marque);
car.modele = this.capitalizeFirstLetter(car.modele);
car.couleur = this.capitalizeFirstLetter(car.couleur);
this.cars.push(car); this.cars.push(car);
} }
updateCar(updatedCar: Car) { updateCar(updatedCar: Car) {
const index = this.cars.findIndex(c => c.id === updatedCar.id); const index = this.cars.findIndex(c => c.id === updatedCar.id);
if (index !== -1) { if (index !== -1) {
updatedCar.marque = this.capitalizeFirstLetter(updatedCar.marque);
updatedCar.modele = this.capitalizeFirstLetter(updatedCar.modele);
updatedCar.couleur = this.capitalizeFirstLetter(updatedCar.couleur);
this.cars[index] = updatedCar; this.cars[index] = updatedCar;
} }
} }