Merge pull request #6 from HarmandI/feature/ajouter

Feature/ajouter
This commit is contained in:
HarmandI 2022-03-22 12:09:42 +01:00 committed by GitHub
commit a2cf4f55ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 111 deletions

194
db.json
View File

@ -1,104 +1,107 @@
{ {
"list_products": [ "list_products": [
{ {
"id": "910744", "id": "801427",
"product_name": "bibi", "product_name": "Strelitzia Nicolai : D.21-H.75",
"product_price": "5", "product_price": "59,99",
"product_qty": 5, "product_instock": "disponible",
"product_rating": 5, "product_discount_code": "",
"product_color": "Blanc",
"product_unitprice_ati": "59.99",
"product_unitprice_tf": "54.5",
"product_discount_tf": "0.00",
"product_discount_ati": "0.00",
"product_qty": 0,
"product_rating": 3,
"product_breadcrumb_label": "plantes fleuries", "product_breadcrumb_label": "plantes fleuries",
"product_instock": [ "product_url_page": "https://www.truffaut.com/strelitzia-nicolai-d-21-h-75-801427.html",
[ "product_url_picture": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0801000/801427_001.jpg",
[ "product_shipping_method": null,
[ "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0801000/801427_001.jpg",
"disponible" "product_seller": "market place",
] "product_web_only": "non"
] },
] {
], "id": "910744",
"product_url_picture": "https//picsum.photos/id/18/200/300", "product_name": "Spathiphyllum 'Sweet Lauretta' Pot déco foncé D24cm",
"product_price": "84,99",
"product_instock": "disponible",
"product_discount_code": "", "product_discount_code": "",
"product_color": "", "product_color": "",
"product_unitprice_ati": "", "product_unitprice_ati": "84.99",
"product_unitprice_tf": "", "product_unitprice_tf": "77.3",
"product_discount_tf": "", "product_discount_tf": "0.00",
"product_discount_ati": "", "product_discount_ati": "0.00",
"product_url_page": "", "product_qty": 0,
"product_rating": 3,
"product_breadcrumb_label": "plantes fleuries",
"product_url_page": "https://www.truffaut.com/spathiphyllum-sweet-lauretta-pot-deco-fonce-d24cm-910744.html",
"product_url_picture": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0910000/910744_001.jpg",
"product_shipping_method": null, "product_shipping_method": null,
"product_image_source": "", "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0910000/910744_001.jpg",
"product_seller": "market place", "product_seller": "market place",
"product_web_only": "non" "product_web_only": "non"
}, },
{ {
"id": "910743", "id": "910743",
"product_name": "Baba", "product_name": "Spathiphyllum 'Sweet Lauretta' Pot déco clair D24cm",
"product_price": "5", "product_price": "84,99",
"product_qty": 5, "product_instock": "disponible",
"product_rating": 5,
"product_breadcrumb_label": "plantes fleuries",
"product_instock": [
[
"disponible"
]
],
"product_url_picture": "https//picsum.photos/id/18/200/300",
"product_discount_code": "", "product_discount_code": "",
"product_color": "", "product_color": "",
"product_unitprice_ati": "", "product_unitprice_ati": "84.99",
"product_unitprice_tf": "", "product_unitprice_tf": "77.3",
"product_discount_tf": "", "product_discount_tf": "0.00",
"product_discount_ati": "", "product_discount_ati": "0.00",
"product_url_page": "", "product_qty": 0,
"product_rating": 3,
"product_breadcrumb_label": "plantes fleuries",
"product_url_page": "https://www.truffaut.com/spathiphyllum-sweet-lauretta-pot-deco-clair-d24cm-910743.html",
"product_url_picture": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0910000/910743_001.jpg",
"product_shipping_method": null, "product_shipping_method": null,
"product_image_source": "", "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0910000/910743_001.jpg",
"product_seller": "market place", "product_seller": "market place",
"product_web_only": "non" "product_web_only": "non"
}, },
{ {
"id": "63158", "id": "63158",
"product_name": "boubou", "product_name": "Spathiphyllum: d.14cm, pot grand modèle",
"product_price": "5", "product_price": "7,95",
"product_qty": 5, "product_instock": "disponible",
"product_rating": 5,
"product_breadcrumb_label": "cactus et plantes grasses",
"product_instock": [
"partiellement disponible"
],
"product_url_picture": "https//picsum.photos/id/18/200/300",
"product_discount_code": "", "product_discount_code": "",
"product_color": "", "product_color": "Blanc",
"product_unitprice_ati": "", "product_unitprice_ati": "7.95",
"product_unitprice_tf": "", "product_unitprice_tf": "7.2",
"product_discount_tf": "", "product_discount_tf": "0.00",
"product_discount_ati": "", "product_discount_ati": "0.00",
"product_url_page": "", "product_qty": 1,
"product_rating": 3,
"product_breadcrumb_label": "plantes fleuries",
"product_url_page": "https://www.truffaut.com/spathiphyllum-d-14cm-pot-grand-modele-63158.html",
"product_url_picture": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0063000/63158_005.jpg",
"product_shipping_method": null, "product_shipping_method": null,
"product_image_source": "", "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0063000/63158_005.jpg",
"product_seller": "market place", "product_seller": "Truffaut",
"product_web_only": "non" "product_web_only": "oui"
}, },
{ {
"id": "910674", "id": "910674",
"product_name": "Spathiphyllum 'Sweet Lauretta' pot D24cm", "product_name": "Spathiphyllum 'Sweet Lauretta' pot D24cm",
"product_price": "69,99", "product_price": "69,99",
"product_qty": 3, "product_instock": "disponible",
"product_rating": 4,
"product_breadcrumb_label": "plantes fleuries",
"product_instock": [
[
"disponible"
]
],
"product_url_picture": "https//picsum.photos/id/18/200/300",
"product_discount_code": "", "product_discount_code": "",
"product_color": "", "product_color": "",
"product_unitprice_ati": "", "product_unitprice_ati": "69.99",
"product_unitprice_tf": "", "product_unitprice_tf": "63.6",
"product_discount_tf": "", "product_discount_tf": "0.00",
"product_discount_ati": "", "product_discount_ati": "0.00",
"product_url_page": "", "product_qty": 0,
"product_rating": 3,
"product_breadcrumb_label": "plantes fleuries",
"product_url_page": "https://www.truffaut.com/spathiphyllum-sweet-lauretta-pot-d24cm-910674.html",
"product_url_picture": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0910000/910674_001.jpg",
"product_shipping_method": null, "product_shipping_method": null,
"product_image_source": "", "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0910000/910674_001.jpg",
"product_seller": "market place", "product_seller": "market place",
"product_web_only": "non" "product_web_only": "non"
}, },
@ -106,22 +109,20 @@
"id": "801429", "id": "801429",
"product_name": "Strelitzia Nicolai Cache-pot Anthracite: D.21-H.75", "product_name": "Strelitzia Nicolai Cache-pot Anthracite: D.21-H.75",
"product_price": "64,99", "product_price": "64,99",
"product_qty": 5, "product_instock": "disponible",
"product_rating": 4.5,
"product_breadcrumb_label": "plantes fleuries",
"product_instock": [
"disponible"
],
"product_url_picture": "https//picsum.photos/id/18/200/300",
"product_discount_code": "", "product_discount_code": "",
"product_color": "", "product_color": "Blanc",
"product_unitprice_ati": "", "product_unitprice_ati": "64.99",
"product_unitprice_tf": "", "product_unitprice_tf": "59.1",
"product_discount_tf": "", "product_discount_tf": "0.00",
"product_discount_ati": "", "product_discount_ati": "0.00",
"product_url_page": "", "product_qty": 0,
"product_rating": 3,
"product_breadcrumb_label": "plantes fleuries",
"product_url_page": "https://www.truffaut.com/strelitzia-nicolai-cache-pot-gris-d-21-h-75-801429.html",
"product_url_picture": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0801000/801429_001.jpg",
"product_shipping_method": null, "product_shipping_method": null,
"product_image_source": "", "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0801000/801429_001.jpg",
"product_seller": "market place", "product_seller": "market place",
"product_web_only": "non" "product_web_only": "non"
}, },
@ -5983,6 +5984,29 @@
"product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0832000/832900_001.jpg", "product_image_source": "https://images.truffaut.com/media/catalog/product/cdn:///Articles/jpg/0832000/832900_001.jpg",
"product_seller": "Truffaut", "product_seller": "Truffaut",
"product_web_only": "oui" "product_web_only": "oui"
},
{
"product_name": "Belle plante",
"product_price": "35",
"product_qty": 1,
"product_rating": 3,
"product_breadcrumb_label": "orchides",
"product_instock": [
"non disponible"
],
"product_url_picture": "https//picsum.photos/id/18/200/300",
"product_discount_code": "",
"product_color": "",
"product_unitprice_ati": "",
"product_unitprice_tf": "",
"product_discount_tf": "",
"product_discount_ati": "",
"product_url_page": "",
"product_shipping_method": null,
"product_image_source": "",
"product_seller": "market place",
"product_web_only": "non",
"id": "Fcq4EWk"
} }
], ],
"users": [ "users": [

View File

@ -1,2 +1,2 @@
<h1>Ajouter une plante</h1> <h1>Ajouter une plante</h1>
<app-formulaire [buttonLabel]="'Ajouter une plante'"></app-formulaire> <app-formulaire [plantInfos]="newplant" (submitted)="addPlant($event)" [buttonLabel]="'Ajouter une plante'"></app-formulaire>

View File

@ -19,42 +19,47 @@ import { AdminService } from '../../services/admin.service';
styleUrls: ['./page-ajouter.component.scss'], styleUrls: ['./page-ajouter.component.scss'],
}) })
export class PageAjouterComponent implements OnInit { export class PageAjouterComponent implements OnInit {
public plantForm: FormGroup; public newplant = new Plant();
public isAdd: boolean = false;
constructor(private fb: FormBuilder, private router: Router, private adminService: AdminService) { constructor(private fb: FormBuilder, private router: Router, private adminService: AdminService) {
this.plantForm = new FormGroup({});
this.isAdd = false;
} }
ngOnInit(): void { ngOnInit(): void {
} }
public onSubmit(): void { public addPlant(plant: any): void {
const nameValue = this.plantForm.value['nameFC']; const nameValue = plant.nameFc;
const priceValue = this.plantForm.value['priceFc']; const priceValue = plant.priceFc;
const quantityValue = this.plantForm.value['quantityFc']; const ratingValue = plant.ratingFc;
const inStockValue = this.plantForm.value['inStockFC']; const quantityValue = plant.quantityFc;
const categoryValue = this.plantForm.value['categotyFC']; const categoryValue = plant.categoryFc;
const urlPicture: string = 'https//picsum.photos/id/18/200/300'; const inStockValue = plant.inStockFc;
const ratingValue = this.plantForm.value['ratingFc'];
const idValue = this.plantForm.value[''];
const plant : Plant = { const plante: any = {
name: nameValue, product_name: nameValue,
price: priceValue, product_price: priceValue,
quantity: quantityValue, product_qty: quantityValue,
inStock: [inStockValue], product_rating: ratingValue,
category: [categoryValue], product_breadcrumb_label: categoryValue,
urlPicture: 'https//picsum.photos/id/18/200/300', product_instock: [inStockValue],
rating: ratingValue, product_url_picture : "https//picsum.photos/id/18/200/300",
id: idValue, product_discount_code : "",
product_color: "",
product_unitprice_ati: "",
product_unitprice_tf: "",
product_discount_tf: "",
product_discount_ati: "",
product_url_page: "",
product_shipping_method: null,
product_image_source: "",
product_seller: "market place",
product_web_only: "non"
}; };
console.log("coco",plant);
this.adminService.addPlant(plant)?.subscribe((resp)=>{ this.adminService.addPlant(plante)?.subscribe((resp)=>{
}) })
this.router.navigate(['admin']); this.router.navigate(['admin']);
} }

View File

@ -38,7 +38,7 @@ export class AdminService {
} }
addPlant(plant: Plant): Observable<any> | void { 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> { onClickDelete(id: number): Observable<any> {
return this.httpClient.delete<any>(`${this.apiUrl}/list_products/${id}`).pipe( return this.httpClient.delete<any>(`${this.apiUrl}/list_products/${id}`).pipe(