feat(store-home-page): refactor to use catalog structure and update product loading logic
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { ApiPaginatedResponse } from '../api-paginated-response.interface';
|
||||
|
||||
export interface Product {
|
||||
id: number;
|
||||
category_id: number;
|
||||
@@ -53,3 +55,29 @@ export interface ProductDetail extends Product {
|
||||
variants_map: ProductVariantMap[];
|
||||
variant: ProductVariant | null;
|
||||
}
|
||||
|
||||
export type CatalogProductLayout = 'row' | 'column_with_image' | 'column_with_cart';
|
||||
|
||||
export interface CatalogFeaturedItemVariant {
|
||||
id: number;
|
||||
stock_tecnico: number | null;
|
||||
values: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface CatalogFeaturedItem {
|
||||
id: number;
|
||||
nombre: string;
|
||||
descripcion?: string | null;
|
||||
precio: number | string;
|
||||
image?: string | null;
|
||||
stock_tecnico?: number | null;
|
||||
variants?: CatalogFeaturedItemVariant[];
|
||||
}
|
||||
|
||||
export interface CatalogFeaturedGroup {
|
||||
id: number;
|
||||
title: string;
|
||||
layout: CatalogProductLayout;
|
||||
group_order: number;
|
||||
items: ApiPaginatedResponse<CatalogFeaturedItem[]>;
|
||||
}
|
||||
|
||||
@@ -6,16 +6,17 @@ import { ApiPaginationQueryParams } from '../api-pagination-query-params.interfa
|
||||
import { ApiPaginatedResponse } from '../api-paginated-response.interface';
|
||||
import { ApiResponse } from '../api-response.interface';
|
||||
import { TenantService } from '../tenant.service';
|
||||
import { Product, ProductDetail } from './catalog.interface';
|
||||
import {
|
||||
CatalogFeaturedGroup,
|
||||
CatalogFeaturedItem,
|
||||
Product,
|
||||
ProductDetail,
|
||||
} from './catalog.interface';
|
||||
|
||||
type HttpParamValue =
|
||||
| string
|
||||
| number
|
||||
| boolean
|
||||
| readonly (string | number | boolean)[];
|
||||
type HttpParamValue = string | number | boolean | readonly (string | number | boolean)[];
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class CatalogService {
|
||||
private readonly http = inject(HttpClient);
|
||||
@@ -25,13 +26,23 @@ export class CatalogService {
|
||||
return this.tenantService.getTenantApiUrl();
|
||||
}
|
||||
|
||||
getProductos(params?: ApiPaginationQueryParams): Observable<ApiPaginatedResponse<Product[]>> {
|
||||
return this.http.get<ApiPaginatedResponse<Product[]>>(`${this.tenantApiUrl}/productos`, {
|
||||
params: this.buildHttpParams(params),
|
||||
});
|
||||
}
|
||||
|
||||
getProductos(
|
||||
params?: ApiPaginationQueryParams
|
||||
): Observable<ApiPaginatedResponse<Product[]>> {
|
||||
return this.http.get<ApiPaginatedResponse<Product[]>>(
|
||||
`${this.tenantApiUrl}/productos`,
|
||||
{ params: this.buildHttpParams(params) }
|
||||
getCatalog(): Observable<CatalogFeaturedGroup[]> {
|
||||
return this.http.get<CatalogFeaturedGroup[]>(`${this.tenantApiUrl}/catalog`);
|
||||
}
|
||||
|
||||
getFeaturedGroupItems(
|
||||
featuredGroupId: number,
|
||||
params?: ApiPaginationQueryParams,
|
||||
): Observable<ApiPaginatedResponse<CatalogFeaturedItem[]>> {
|
||||
return this.http.get<ApiPaginatedResponse<CatalogFeaturedItem[]>>(
|
||||
`${this.tenantApiUrl}/catalog/featured-groups/${featuredGroupId}/items`,
|
||||
{ params: this.buildHttpParams(params) },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,7 +51,7 @@ export class CatalogService {
|
||||
if (variantId) {
|
||||
params = params.set('variant_id', variantId);
|
||||
}
|
||||
|
||||
|
||||
return this.http
|
||||
.get<ApiResponse<ProductDetail>>(`${this.tenantApiUrl}/productos/${id}`, { params })
|
||||
.pipe(map((response) => response.data));
|
||||
@@ -59,7 +70,7 @@ export class CatalogService {
|
||||
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
{},
|
||||
);
|
||||
|
||||
return new HttpParams({ fromObject });
|
||||
|
||||
Reference in New Issue
Block a user