Add product data domain layer
This commit is contained in:
70
src/app/facades/platform/product.facade.ts
Normal file
70
src/app/facades/platform/product.facade.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import { ProductDataService } from '../../core/products/product-data.service';
|
||||
import { Product, ProductCategory, ProductListQuery, ProductListResult, ProductSearchQuery, RelatedProductsQuery } from '../../core/products/models/product-domain.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ProductFacade {
|
||||
readonly categories = signal<ProductCategory[]>([]);
|
||||
readonly products = signal<Product[]>([]);
|
||||
readonly selectedProduct = signal<Product | null>(null);
|
||||
readonly relatedProducts = signal<Product[]>([]);
|
||||
readonly total = signal(0);
|
||||
readonly loading = signal(false);
|
||||
readonly error = signal<string | null>(null);
|
||||
|
||||
constructor(private readonly productData: ProductDataService) {}
|
||||
|
||||
loadCategories(): void {
|
||||
this.loading.set(true);
|
||||
this.error.set(null);
|
||||
|
||||
this.productData.getCategories().subscribe({
|
||||
next: (categories) => {
|
||||
this.categories.set(categories);
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: () => {
|
||||
this.categories.set([]);
|
||||
this.error.set('Failed to load categories');
|
||||
this.loading.set(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getCategories() {
|
||||
return this.productData.getCategories();
|
||||
}
|
||||
|
||||
getProducts(query?: ProductListQuery) {
|
||||
return this.productData.getProducts(query);
|
||||
}
|
||||
|
||||
getProduct(productID: number) {
|
||||
return this.productData.getProduct(productID);
|
||||
}
|
||||
|
||||
searchProducts(query: ProductSearchQuery) {
|
||||
return this.productData.searchProducts(query);
|
||||
}
|
||||
|
||||
getFeaturedProducts(query?: ProductListQuery) {
|
||||
return this.productData.getFeaturedProducts(query);
|
||||
}
|
||||
|
||||
getLatestProducts(query?: ProductListQuery) {
|
||||
return this.productData.getLatestProducts(query);
|
||||
}
|
||||
|
||||
getProductsByCategory(categoryID: number, query?: ProductListQuery) {
|
||||
return this.productData.getProductsByCategory(categoryID, query);
|
||||
}
|
||||
|
||||
getRelatedProducts(query: RelatedProductsQuery) {
|
||||
return this.productData.getRelatedProducts(query);
|
||||
}
|
||||
|
||||
setListResult(result: ProductListResult): void {
|
||||
this.products.set(result.items);
|
||||
this.total.set(result.total);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user