diff --git a/package.json b/package.json index ac9fbfc444aede77cc492ea483ceacebb6791d12..2add968adbad97c0cae41748a998b34ebde22c61 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 0000000000000000000000000000000000000000..5777ae6d15658f8ebf44dcc046e2ce38aa64a9fd --- /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 0000000000000000000000000000000000000000..db88a7326d57157ed2bccf7d34fa622ca8750138 --- /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 0000000000000000000000000000000000000000..69d15de9f9cdcea6e239ca224de34143401b8c9b --- /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 0000000000000000000000000000000000000000..75a17f58cd60891154e2e38db012146a317f5d95 --- /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); + } +}