Skip to content

Commit 1669ec6

Browse files
authored
Merge pull request #5 from enterpriseShop/rs-category
Refactor pagination; add categories & manufacturers
2 parents 4808614 + c5de2e5 commit 1669ec6

31 files changed

Lines changed: 1555 additions & 353 deletions

src/app/app.routes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ export const routes: Routes = [
4545
),
4646
},
4747
{
48-
path: 'catalog/:sub',
49-
loadComponent: () => import('./features/placeholder').then((m) => m.PlaceholderPageComponent),
48+
path: 'catalog/categories',
49+
loadComponent: () =>
50+
import('./features/catalog/categories/categories').then((m) => m.CategoriesPageComponent),
5051
},
5152
{
5253
path: 'compatibility/:sub',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface CategoryDefaultQuery {
2+
page: number | null;
3+
name: string | null;
4+
active: boolean | null;
5+
per_page: number | null;
6+
parent_id: string | null;
7+
}
Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1-
export interface CategoryResponse {
1+
// export interface CategoryResponse {
2+
// id: string;
3+
// parent_id: null;
4+
// name: string;
5+
// slug: string;
6+
// description: string;
7+
// display_order: number;
8+
// icon: string;
9+
// image: string;
10+
// active: boolean;
11+
// created_at: string;
12+
// updated_at: string;
13+
// }
14+
15+
export interface CategoryResponse extends Record<string, unknown> {
216
id: string;
3-
parent_id: null;
17+
parent_id: string | null;
418
name: string;
519
slug: string;
6-
description: string;
20+
description: string | null;
721
display_order: number;
8-
icon: string;
9-
image: string;
22+
icon: string | null;
23+
image: string | null;
1024
active: boolean;
1125
created_at: string;
1226
updated_at: string;
27+
parent_name?: string;
28+
}
29+
30+
export interface CreateCategoryPayload {
31+
parent_id?: string | null;
32+
name: string;
33+
slug: string;
34+
description?: string | null;
35+
display_order?: number;
36+
icon?: string | null;
37+
image?: string | null;
38+
active?: boolean;
39+
}
40+
41+
export interface UpdateCategoryPayload {
42+
parent_id?: string | null;
43+
name?: string;
44+
slug?: string;
45+
description?: string | null;
46+
display_order?: number;
47+
icon?: string | null;
48+
image?: string | null;
49+
active?: boolean;
1350
}

src/app/core/models/catetories/category-options.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import { GeneralOption } from '../generals/general-options-response.model';
22

33
export interface CategoryOption extends GeneralOption {
44
icon: string;
5+
is_parent: boolean;
56
description: string;
67
}

src/app/core/models/design-system/auto-complete.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { GeneralOption } from '../generals/general-options-response.model';
33
export interface AutocompleteOption extends GeneralOption {
44
icon: string;
55
disabled: boolean;
6+
is_parent: boolean;
67
description: string;
78
}

src/app/core/models/generals/general-delete-response.ts

Whitespace-only changes.

src/app/core/models/list-table/list-table.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface TableAction<T = Record<string, unknown>> {
2828
colorClass?: string;
2929
title?: string;
3030
visible?: (row: T) => boolean;
31-
handler: (row: T) => void;
31+
handler?: (row: T) => void;
3232
}
3333

3434
export interface TablePaginationConfig {

src/app/core/services/category-service.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import { HttpClient } from '@angular/common/http';
22
import { inject, Injectable } from '@angular/core';
33
import { PaginatedResponse } from '../models/pagination/pagination.model';
44
import { environment } from '../../../environments/environment';
5-
import { CategoryResponse } from '../models/catetories/categories.model';
5+
import {
6+
CategoryResponse,
7+
CreateCategoryPayload,
8+
UpdateCategoryPayload,
9+
} from '../models/catetories/categories.model';
610
import { buildHttpParams } from './build-http-params';
711
import { CategoryOption } from '../models/catetories/category-options.model';
812
import { GeneralOptionQuery } from '../models/generals/general-option-query.model';
913
import { getAllResponse } from '../models/generals/general-responses-list.model';
14+
import { CategoryDefaultQuery } from '../models/catetories/categories-default-query';
1015

1116
@Injectable({
1217
providedIn: 'root',
@@ -16,8 +21,11 @@ export class CategoryService {
1621
private api = environment.apiUrl;
1722
private flag = 'category';
1823

19-
getAll() {
20-
return this.http.get<PaginatedResponse<CategoryResponse>>(`${this.api}/${this.flag}`);
24+
getAll(filters: CategoryDefaultQuery) {
25+
const params = buildHttpParams(filters);
26+
return this.http.get<PaginatedResponse<CategoryResponse>>(`${this.api}/${this.flag}`, {
27+
params,
28+
});
2129
}
2230

2331
getOptions(filters: GeneralOptionQuery) {
@@ -31,15 +39,15 @@ export class CategoryService {
3139
return this.http.get<CategoryResponse>(`${this.api}/${this.flag}/${id}`);
3240
}
3341

34-
create(data: FormData) {
35-
return this.http.post<CategoryResponse>(`${this.api}/${this.flag}`, data);
42+
create(data: CreateCategoryPayload) {
43+
return this.http.post<getAllResponse<CategoryResponse>>(`${this.api}/${this.flag}`, data);
3644
}
3745

38-
update(id: string, data: FormData) {
39-
return this.http.post<CategoryResponse>(`${this.api}/${this.flag}/${id}`, data);
46+
update(id: string, data: UpdateCategoryPayload) {
47+
return this.http.put<getAllResponse<CategoryResponse>>(`${this.api}/${this.flag}/${id}`, data);
4048
}
4149

4250
delete(id: string) {
43-
return this.http.delete<void>(`${this.api}/${this.flag}/${id}`);
51+
return this.http.delete<getAllResponse<CategoryResponse>>(`${this.api}/${this.flag}/${id}`);
4452
}
4553
}

src/app/core/store/manufacturer-store/manufacturer-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class ManufacturerStore extends OptionCacheStore<
3131
icon: 'chevrons-right',
3232
hasSubOptions: true,
3333
description: option.sublabel,
34+
is_parent: false,
3435
})),
3536
})),
3637
);

src/app/design-system/data-table/data-table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class DataTableComponent<T extends Record<string, unknown>> {
166166

167167
onActionClick(action: TableAction<T>, row: T, event: MouseEvent): void {
168168
event.stopPropagation();
169-
if (action.id) {
169+
if (action.handler) {
170170
action.handler(row);
171171
}
172172
console.log('[ON ACTION CLICK]', action, action.id);

0 commit comments

Comments
 (0)