From 2ff47263a179f776319758cc2945ab5cc53efbd1 Mon Sep 17 00:00:00 2001 From: carteronm Date: Thu, 11 Dec 2025 14:32:46 +0100 Subject: [PATCH] get all customers done --- .../customers-get-all/customers-get-all.html | 12 +-- .../customers-get-all/customers-get-all.ts | 23 +++-- .../get-all-customers-card.css | 0 .../get-all-customers-card.html | 29 ++++++ .../get-all-customers-card.ts | 89 +++++++++++++++++++ .../providers-get-all/providers-get-all.ts | 23 ----- .../services/api/model/create-contact-dto.ts | 2 + .../services/api/model/create-customer-dto.ts | 1 + src/app/services/api/model/get-contact-dto.ts | 2 + .../services/api/model/get-customer-dto.ts | 1 + .../api/model/method-impl-attributes.ts | 1 - .../services/api/model/update-contact-dto.ts | 2 + 12 files changed, 143 insertions(+), 42 deletions(-) create mode 100644 src/app/pages/customers/get-all-customers-card/get-all-customers-card.css create mode 100644 src/app/pages/customers/get-all-customers-card/get-all-customers-card.html create mode 100644 src/app/pages/customers/get-all-customers-card/get-all-customers-card.ts diff --git a/src/app/pages/customers/customers-get-all/customers-get-all.html b/src/app/pages/customers/customers-get-all/customers-get-all.html index cbe0385..4c47919 100644 --- a/src/app/pages/customers/customers-get-all/customers-get-all.html +++ b/src/app/pages/customers/customers-get-all/customers-get-all.html @@ -2,14 +2,8 @@
@for (customer of customers(); track customer.id) { - -

Utilisateur n°{{ customer.id }}

-

Nom/Prénom : {{ customer.name }} {{ customer.firstName }}

-

Téléphone : {{ customer.phone }}

-

Email : {{ customer.email }}

-

Adresse : {{ customer.address }}

-

Note : {{ customer.note }}

-
+ + }
- + \ No newline at end of file diff --git a/src/app/pages/customers/customers-get-all/customers-get-all.ts b/src/app/pages/customers/customers-get-all/customers-get-all.ts index 69def45..7da7565 100644 --- a/src/app/pages/customers/customers-get-all/customers-get-all.ts +++ b/src/app/pages/customers/customers-get-all/customers-get-all.ts @@ -1,22 +1,28 @@ -import {Component, inject, signal} from '@angular/core'; -import {Router} from "@angular/router"; -import {firstValueFrom} from "rxjs"; +import {Component, inject, OnInit, signal} from '@angular/core'; +import { Router } from '@angular/router'; +import {CustomersService, GetCustomerDto} from "../../../services/api"; import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; +import {ReactiveFormsModule} from "@angular/forms"; +import {NzFormModule} from "ng-zorro-antd/form"; +import {NzSpaceComponent} from "ng-zorro-antd/space"; +import {GetAllCustomersCard} from "../get-all-customers-card/get-all-customers-card"; @Component({ selector: 'app-customers-get-all', - imports: [], + imports: [ReactiveFormsModule, NzFormModule, GetAllCustomersCard, GetAllCustomersCard], templateUrl: './customers-get-all.html', styleUrl: './customers-get-all.css', }) export class CustomersGetAll { - private customerService = inject(CustomersService); + private customersService = inject(CustomersService); private notificationService = inject(NzNotificationService) router = inject(Router); customers = signal([]); customersLoading = signal(false); + async ngOnInit() { await this.fetchCustomers(); } @@ -24,10 +30,9 @@ export class CustomersGetAll { async fetchCustomers() { this.customersLoading.set(true); try { - const customer = await firstValueFrom(this.customerService.getAllCustomersEndpoint()) - this.customers.set(customer) - } catch (e) - { + const customers = await firstValueFrom(this.customersService.getAllCustomerEndpoint()) + this.customers.set(customers) + } catch (e) { this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); } diff --git a/src/app/pages/customers/get-all-customers-card/get-all-customers-card.css b/src/app/pages/customers/get-all-customers-card/get-all-customers-card.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/pages/customers/get-all-customers-card/get-all-customers-card.html b/src/app/pages/customers/get-all-customers-card/get-all-customers-card.html new file mode 100644 index 0000000..03641b7 --- /dev/null +++ b/src/app/pages/customers/get-all-customers-card/get-all-customers-card.html @@ -0,0 +1,29 @@ +@if (edit() == false) { + +

Client n°{{ customer().id }}

+

Note : {{ customer().note }}

+
+ + + + + + +} @else { + +
+ + Note + + + + +
+
+ + + + + + +} diff --git a/src/app/pages/customers/get-all-customers-card/get-all-customers-card.ts b/src/app/pages/customers/get-all-customers-card/get-all-customers-card.ts new file mode 100644 index 0000000..922cced --- /dev/null +++ b/src/app/pages/customers/get-all-customers-card/get-all-customers-card.ts @@ -0,0 +1,89 @@ +import {Component, inject, input, output, signal} from '@angular/core'; +import {NzIconDirective} from "ng-zorro-antd/icon"; +import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms"; +import {NzFormModule} from "ng-zorro-antd/form"; +import {NzCardComponent} from "ng-zorro-antd/card"; +import {NzInputDirective} from "ng-zorro-antd/input"; +import {CustomersService, GetCustomerDto, UpdateCustomerDto} from "../../../services/api"; +import {NzNotificationService} from "ng-zorro-antd/notification"; +import {firstValueFrom} from "rxjs"; + +@Component({ + selector: 'app-get-all-customers-card', + imports: [ReactiveFormsModule, NzFormModule, NzCardComponent, NzIconDirective, NzInputDirective], + templateUrl: './get-all-customers-card.html', + styleUrl: './get-all-customers-card.css', +}) +export class GetAllCustomersCard { + private customersService = inject(CustomersService); + private notificationService = inject(NzNotificationService) + + customerEdit = signal(null); + customersLoading = signal(false); + + customerForm = new FormGroup({ + id: new FormControl(null, [Validators.required]), + note: new FormControl(null, [Validators.required]), + }) + + async submitForm() { + this.customersLoading.set(true); + + const customerValue = { + note: this.customerForm.value.note, + } + + try { + const customer = await firstValueFrom(this.customersService.updateCustomer(this.customer().id,customerValue)); + this.customerEdit.set(customer); + console.log(customer); + this.customerForm.reset(); + this.edit.set(false); + + this.triggerEdited.emit(); + + } catch (e) + { + this.notificationService.error('Erreur', ' (ou Erreur de communication avec l\'API)'); + } + + this.customersLoading.set(false); + + } + + + customer = input(null); + + edit = signal(false) + + triggerEdited = output(); + + protected Edit() { + this.edit.set(true) + } + + protected Back() { + this.edit.set(false) + this.customerForm.reset(); + } + + async Delete() { + this.customersLoading.set(true); + + try { + const customer = await firstValueFrom(this.customersService.deleteCustomerEndpoint(this.customer().id)); + this.customerEdit.set(customer); + + this.customerForm.reset(); + this.triggerEdited.emit(); + + } catch (e) + { + this.notificationService.error('Erreur de recherche', "L\'auteur n\'existe pas !"); + + this.notificationService.error('Erreur', ' (ou Erreur de communication avec l\'API)'); + } + + this.customersLoading.set(false); + } +} diff --git a/src/app/pages/providers/providers-get-all/providers-get-all.ts b/src/app/pages/providers/providers-get-all/providers-get-all.ts index 084ed18..7db4414 100644 --- a/src/app/pages/providers/providers-get-all/providers-get-all.ts +++ b/src/app/pages/providers/providers-get-all/providers-get-all.ts @@ -10,27 +10,4 @@ import {firstValueFrom} from "rxjs"; styleUrl: './providers-get-all.css', }) export class ProvidersGetAll { - private providersService = inject(ProvidersService); - private notificationService = inject(NzNotificationService) - - router = inject(Router); - - providers = signal([]); - providersLoading = signal(false); - async ngOnInit() { - await this.fetchProviders(); - } - - async fetchProviders() { - this.providersLoading.set(true); - try { - const providers = await firstValueFrom(this.providersService.getAllProvidersEndpoint()) - this.providers.set(providers) - } catch (e) - { - this.notificationService.error('Erreur', 'Erreur de communication avec l\'API'); - } - - this.providersLoading.set(false); - } } diff --git a/src/app/services/api/model/create-contact-dto.ts b/src/app/services/api/model/create-contact-dto.ts index 0ad11ac..92a3845 100644 --- a/src/app/services/api/model/create-contact-dto.ts +++ b/src/app/services/api/model/create-contact-dto.ts @@ -15,6 +15,8 @@ export interface CreateContactDto { phoneNumber?: string | null; email?: string | null; address?: string | null; + city?: string | null; role?: string | null; + customerId?: number | null; } diff --git a/src/app/services/api/model/create-customer-dto.ts b/src/app/services/api/model/create-customer-dto.ts index c751b48..8335101 100644 --- a/src/app/services/api/model/create-customer-dto.ts +++ b/src/app/services/api/model/create-customer-dto.ts @@ -11,5 +11,6 @@ export interface CreateCustomerDto { note?: string | null; + customerTypeId?: number; } diff --git a/src/app/services/api/model/get-contact-dto.ts b/src/app/services/api/model/get-contact-dto.ts index 869f71a..bbbedd0 100644 --- a/src/app/services/api/model/get-contact-dto.ts +++ b/src/app/services/api/model/get-contact-dto.ts @@ -16,6 +16,8 @@ export interface GetContactDto { phoneNumber?: string | null; email?: string | null; address?: string | null; + city?: string | null; role?: string | null; + customerId?: number | null; } diff --git a/src/app/services/api/model/get-customer-dto.ts b/src/app/services/api/model/get-customer-dto.ts index edcb955..ef85c4e 100644 --- a/src/app/services/api/model/get-customer-dto.ts +++ b/src/app/services/api/model/get-customer-dto.ts @@ -12,5 +12,6 @@ export interface GetCustomerDto { id?: number; note?: string | null; + customerTypeId?: number; } diff --git a/src/app/services/api/model/method-impl-attributes.ts b/src/app/services/api/model/method-impl-attributes.ts index 3e0ac0e..c9250ed 100644 --- a/src/app/services/api/model/method-impl-attributes.ts +++ b/src/app/services/api/model/method-impl-attributes.ts @@ -18,7 +18,6 @@ export const MethodImplAttributes = { NUMBER_1: 1, NUMBER_2: 2, NUMBER_3: 3, - NUMBER_32: 3, NUMBER_4: 4, NUMBER_42: 4, NUMBER_8: 8, diff --git a/src/app/services/api/model/update-contact-dto.ts b/src/app/services/api/model/update-contact-dto.ts index 2864dca..4f3e7ba 100644 --- a/src/app/services/api/model/update-contact-dto.ts +++ b/src/app/services/api/model/update-contact-dto.ts @@ -15,6 +15,8 @@ export interface UpdateContactDto { phoneNumber?: string | null; email?: string | null; address?: string | null; + city?: string | null; role?: string | null; + customerTypeId?: number | null; }