From 7e200c9172cc47dc8de8f59977b76896ab167c00 Mon Sep 17 00:00:00 2001 From: KPOTY Kpotivi <kpotivi.kpoty@etu.univ-amu.fr> Date: Fri, 3 Nov 2023 20:22:11 +0100 Subject: [PATCH] feat: adding of services --- package.json | 2 +- src/app/services/admin.service.ts | 19 +++++++++++ src/app/services/buyer.service.ts | 44 ++++++++++++++++++++++++ src/app/services/order.service.ts | 52 +++++++++++++++++++++++++++++ src/app/services/product.service.ts | 35 +++++++++++++++++++ 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/app/services/admin.service.ts create mode 100644 src/app/services/buyer.service.ts create mode 100644 src/app/services/order.service.ts create mode 100644 src/app/services/product.service.ts diff --git a/package.json b/package.json index ac9fbfc..2add968 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "scripts": { "ng": "ng", - "generate-api": "rm -rf openapi-generator-cli.jar && curl --insecure https://repo.maven.apache.org/maven2/org/openapitools/openapi-generator-cli/6.6.0/openapi-generator-cli-6.6.0.jar -o openapi-generator-cli.jar && java -jar openapi-generator-cli.jar generate -i ../backend/src/main/java/com/shop/sphere/api/shop-sphere.yaml -g typescript-angular -o ./src/api --additional-properties=stringEnums=true,ngVersion=16.2.11", + "generate-api": "rm -rf openapi-generator-cli.jar && curl --insecure https://repo.maven.apache.org/maven2/org/openapitools/openapi-generator-cli/6.6.0/openapi-generator-cli-6.6.0.jar -o openapi-generator-cli.jar && java -jar openapi-generator-cli.jar generate -i ../backend/src/main/java/com/shop/sphere/api/shop-sphere.yaml -g typescript-angular -o ./src/api-client --additional-properties=stringEnums=true,ngVersion=16.2.11", "start": "npm run generate-api && ng serve --port ", "build": "npm run generate-api && ng build", "watch": "ng build --watch --configuration development", diff --git a/src/app/services/admin.service.ts b/src/app/services/admin.service.ts new file mode 100644 index 0000000..5777ae6 --- /dev/null +++ b/src/app/services/admin.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { AdminDTO, AdminsService } from 'src/api-client'; + +@Injectable({ + providedIn: 'root', +}) +export class AdminService { + constructor(private adminsApiService: AdminsService) {} + + /** + * Find admin by id + * @param id the id of the admin to find + * @returns an observable of admin + */ + public getAdmin(id: number): Observable<AdminDTO> { + return this.adminsApiService.getAdmin(id); + } +} diff --git a/src/app/services/buyer.service.ts b/src/app/services/buyer.service.ts new file mode 100644 index 0000000..db88a73 --- /dev/null +++ b/src/app/services/buyer.service.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { BuyerDTO, BuyersService, IdBuyer } from 'src/api-client'; + +@Injectable({ + providedIn: 'root', +}) +export class BuyerService { + constructor(private buyersApiService: BuyersService) {} + + /** + * Create a new buyer in the database + * @param buyer to save in the databse + * @returns an obserable containing the id of the buyer created + */ + public createBuyer(buyer: BuyerDTO): Observable<IdBuyer> { + return this.buyersApiService.createBuyer(buyer); + } + + /** + * Find a buyer by id + * @param id the id of the buyer + * @returns an observable of buyer + */ + public getBuyer(id: number): Observable<BuyerDTO> { + return this.buyersApiService.getBuyer(id); + } + + /** + * Retrieve all buyers from the database + * @returns an observable of buyers + */ + public getBuyers(): Observable<BuyerDTO[]> { + return this.buyersApiService.getBuyers(); + } + + /** + * Update a buyer in the database + * @param buyer the buyer to update + */ + public updateBuyer(buyer: BuyerDTO): Observable<any> { + return this.buyersApiService.updateBuyer(buyer); + } +} diff --git a/src/app/services/order.service.ts b/src/app/services/order.service.ts new file mode 100644 index 0000000..69d15de --- /dev/null +++ b/src/app/services/order.service.ts @@ -0,0 +1,52 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { IdOrder, OrderDTO, OrdersService } from 'src/api-client'; + +@Injectable({ + providedIn: 'root', +}) +export class OrderService { + constructor(private ordersApiService: OrdersService) {} + + /** + * Create a new order in the database + * @param order to save in the databse + * @returns an obserable containing the id of the order created + */ + public createOrder(order: OrderDTO): Observable<IdOrder> { + return this.ordersApiService.createOrder(order); + } + + /** + * Delete an order in the database + * @param id of the order to delete + */ + public deleteOrder(id: number): Observable<any> { + return this.ordersApiService.deleteOrder(id); + } + + /** + * Find an order by id + * @param id the id of the order to find + * @returns an observable of order + */ + public getOrder(id: number): Observable<OrderDTO> { + return this.ordersApiService.getOrder(id); + } + + /** + * Retrieve all orders from the database + * @returns an observable of orders + */ + public getOrders(): Observable<OrderDTO[]> { + return this.ordersApiService.getOrders(); + } + + /** + * Update an order in the database + * @param order the order to update + */ + public updateOrder(order: OrderDTO): Observable<any> { + return this.ordersApiService.updateOrder(order); + } +} diff --git a/src/app/services/product.service.ts b/src/app/services/product.service.ts new file mode 100644 index 0000000..75a17f5 --- /dev/null +++ b/src/app/services/product.service.ts @@ -0,0 +1,35 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { ProductDTO, ProductsService } from 'src/api-client'; + +@Injectable({ + providedIn: 'root', +}) +export class ProductService { + constructor(private productsApiService: ProductsService) {} + + /** + * Find a product by id + * @param id the id of the product to find + * @returns an observable of product + */ + public getProduct(id: number): Observable<ProductDTO> { + return this.productsApiService.getProduct(id); + } + + /** + * Retrieve all products from the database + * @returns an observable of products + */ + public getProducts(): Observable<Array<ProductDTO>> { + return this.productsApiService.getProducts(); + } + + /** + * Update a product in the database + * @param product the product to update + */ + public updateProduct(product: ProductDTO): void { + this.productsApiService.updateProduct(product); + } +} -- GitLab