diff --git a/src/app/models/products-selected-req.ts b/src/app/models/products-selected-req.ts new file mode 100644 index 0000000..6256dd1 --- /dev/null +++ b/src/app/models/products-selected-req.ts @@ -0,0 +1,5 @@ +export interface ProductsSelectedReq { + action: 'SELECT' | 'DESELECT'; +} + + diff --git a/src/app/modules/shopping-list/pages/shopping-list/shopping-list.component.ts b/src/app/modules/shopping-list/pages/shopping-list/shopping-list.component.ts index be54356..4ce72f0 100644 --- a/src/app/modules/shopping-list/pages/shopping-list/shopping-list.component.ts +++ b/src/app/modules/shopping-list/pages/shopping-list/shopping-list.component.ts @@ -29,6 +29,7 @@ import { SelectedProductsComponent } from '@app/modules/shopping-list/layout/shopping-list/selected-products/selected-products.component'; import {FindByIdProductListReq} from '@app/models/find-by-id-product-list-req'; +import {ProductsSelectedReq} from '@app/models/products-selected-req'; @Component({ selector: 'app-shopping-list', @@ -222,6 +223,9 @@ export class ShoppingListComponent { } deselectAllProductsEvent() { + const request: ProductsSelectedReq = { + action: 'DESELECT' + }; const selectedProducts: ProductUpdateShoppingListReq[] = this.shoppingListRes() .productList .content @@ -233,10 +237,17 @@ export class ShoppingListComponent { })); this.removeAllProducts(selectedProducts.map(product => product.productId)); - this.updateProducts(selectedProducts); + this.updateProductsView(selectedProducts); + this.shoppingListsService.updateSelectedProducts(this.shoppingListRes().id, request) + .subscribe(); } updateProducts(productsReq: ProductUpdateShoppingListReq[]) { + this.updateProductsView(productsReq); + this.updateShoppingList(productsReq); + } + + private updateProductsView(productsReq: ProductUpdateShoppingListReq[]) { this.shoppingListRes.update(value => { const products = value.productList .content @@ -269,8 +280,6 @@ export class ShoppingListComponent { } }; }); - - this.updateShoppingList(productsReq); } removeAllProducts(productsId: number[]) { diff --git a/src/app/services/pages/shopping-lists.service.ts b/src/app/services/pages/shopping-lists.service.ts index 07ed2b0..21206d2 100644 --- a/src/app/services/pages/shopping-lists.service.ts +++ b/src/app/services/pages/shopping-lists.service.ts @@ -11,6 +11,7 @@ import {SaveShoppingListRes} from '../../models/save-shopping-list-res'; import {PagingAndSortingReq} from '@app/models/paging-and-sorting-req'; import {FindByIdProductListReq} from '@app/models/find-by-id-product-list-req'; import {FindByIdProductListRes} from '@app/models/find-by-id-product-list-res'; +import {ProductsSelectedReq} from '@app/models/products-selected-req'; @Injectable({ providedIn: 'root' @@ -58,4 +59,7 @@ export class ShoppingListsService { }); } + updateSelectedProducts(id: number, request: ProductsSelectedReq) { + return this.httpClient.put(`${this._shoppingListsURI}/${id}/products-selected`, request); + } }