fix DI errors and stabilize static page navigation

This commit is contained in:
sdarbinyan
2026-07-05 03:41:13 +04:00
parent b0c5c5e051
commit 79a12c0ec2
8 changed files with 45 additions and 65 deletions

View File

@@ -1,70 +1,48 @@
import { Injectable, signal } from '@angular/core';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ProductDataService } from '../../core/products/product-data.service';
import { Product, ProductCategory, ProductListQuery, ProductListResult, ProductSearchQuery, RelatedProductsQuery } from '../../core/products/models/product-domain.model';
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) {}
constructor(private readonly productData: ProductDataService) {}
getProducts(query?: ProductListQuery): Observable<ProductListResult> {
return this.productData.getProducts(query);
}
loadCategories(): void {
this.loading.set(true);
this.error.set(null);
getProduct(productID: number): Observable<Product> {
return this.productData.getProduct(productID);
}
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(): Observable<ProductCategory[]> {
return this.productData.getCategories();
}
getCategories() {
return this.productData.getCategories();
}
searchProducts(query: ProductSearchQuery): Observable<ProductListResult> {
return this.productData.searchProducts(query);
}
getProducts(query?: ProductListQuery) {
return this.productData.getProducts(query);
}
getFeaturedProducts(query?: ProductListQuery): Observable<ProductListResult> {
return this.productData.getFeaturedProducts(query);
}
getProduct(productID: number) {
return this.productData.getProduct(productID);
}
getLatestProducts(query?: ProductListQuery): Observable<ProductListResult> {
return this.productData.getLatestProducts(query);
}
searchProducts(query: ProductSearchQuery) {
return this.productData.searchProducts(query);
}
getProductsByCategory(categoryID: number, query?: ProductListQuery): Observable<ProductListResult> {
return this.productData.getProductsByCategory(categoryID, 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);
}
getRelatedProducts(query: RelatedProductsQuery): Observable<ProductListResult> {
return this.productData.getRelatedProducts(query);
}
}