api doc
Some checks failed
Architecture Governance / architecture (push) Has been cancelled

This commit is contained in:
sdarbinyan
2026-07-20 01:02:36 +04:00
parent 08976de55a
commit fd5a436220
11 changed files with 930 additions and 10 deletions

View File

@@ -14,7 +14,7 @@ import {
} from '../models/admin-analytics.model';
import { AdminOrdersLocalGateway } from '../../orders/services/admin-orders-local.gateway';
import { AdminProductsLocalGateway } from '../../products/services/admin-products-local.gateway';
import { AdminCategoriesLocalGateway } from '../../categories/services/admin-categories-local.gateway';
import { ADMIN_CATEGORIES_GATEWAY } from '../../categories/services/admin-categories-gateway.token';
import { AdminModerationLocalGateway } from '../../moderation/services/admin-moderation-local.gateway';
import { AdminDashboardFacade } from '../../dashboard/facade/admin-dashboard.facade';
import { AdminOrder } from '../../orders/models/admin-order.model';
@@ -32,7 +32,7 @@ import { AdminReview } from '../../moderation/models/admin-review.model';
export class AdminAnalyticsFacade {
private readonly ordersGateway = inject(AdminOrdersLocalGateway);
private readonly productsGateway = inject(AdminProductsLocalGateway);
private readonly categoriesGateway = inject(AdminCategoriesLocalGateway);
private readonly categoriesGateway = inject(ADMIN_CATEGORIES_GATEWAY);
private readonly moderationGateway = inject(AdminModerationLocalGateway);
private readonly dashboardFacade = inject(AdminDashboardFacade);

View File

@@ -2,7 +2,7 @@ import { Injectable, computed, inject, signal } from '@angular/core';
import { take } from 'rxjs/operators';
import { AdminCategory, AdminCategoryEditorMode, AdminCategoryListFilters } from '../models/admin-category.model';
import { AdminCategoriesFormFactory } from '../services/admin-categories-form.factory';
import { AdminCategoriesLocalGateway } from '../services/admin-categories-local.gateway';
import { ADMIN_CATEGORIES_GATEWAY } from '../services/admin-categories-gateway.token';
import { LocalStorageService } from '../../../../core/storage/local-storage.service';
import { ProjectEditorFacade } from '../../../project-editor/facade/project-editor.facade';
@@ -45,7 +45,7 @@ export interface AdminCategoriesDashboardStats {
@Injectable({ providedIn: 'root' })
export class AdminCategoriesFacade {
private readonly gateway = inject(AdminCategoriesLocalGateway);
private readonly gateway = inject(ADMIN_CATEGORIES_GATEWAY);
private readonly formFactory = inject(AdminCategoriesFormFactory);
private readonly localStorage = inject(LocalStorageService);
private readonly projectEditor = inject(ProjectEditorFacade);

View File

@@ -0,0 +1,66 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError, map, of } from 'rxjs';
import { ApiConfigService } from '../../../../core/config/api-config.service';
import { AdminCategory, AdminCategoryListFilters } from '../models/admin-category.model';
import { AdminCategoriesGateway } from './admin-categories-gateway.interface';
/**
* Real HTTP implementation against /backoffice/categories per
* docs/backend/BACKEND-INTEGRATION.md §6.9 and the backend's API-REFERENCE.md §3.
* Categories have no hard delete - only soft delete/restore.
*/
@Injectable({ providedIn: 'root' })
export class AdminCategoriesApiGateway implements AdminCategoriesGateway {
private readonly http = inject(HttpClient);
private readonly apiConfig = inject(ApiConfigService);
private get baseUrl(): string {
return `${this.apiConfig.getBaseUrl()}/backoffice/categories`;
}
loadCategories(filters: AdminCategoryListFilters): Observable<AdminCategory[]> {
const params = new HttpParams()
.set('search', filters.search)
.set('visibility', filters.visibility)
.set('includeDeleted', String(filters.includeDeleted));
return this.http.get<AdminCategory[]>(this.baseUrl, { params });
}
loadCategory(id: string): Observable<AdminCategory | null> {
return this.http.get<AdminCategory>(`${this.baseUrl}/${encodeURIComponent(id)}`).pipe(
catchError(() => of(null))
);
}
createCategory(category: AdminCategory): Observable<AdminCategory> {
const { id, itemsCount, deletedAt, createdAt, updatedAt, ...body } = category;
return this.http.post<AdminCategory>(this.baseUrl, body);
}
updateCategory(category: AdminCategory): Observable<AdminCategory> {
return this.http.put<AdminCategory>(`${this.baseUrl}/${encodeURIComponent(category.id)}`, category);
}
deleteCategory(id: string): Observable<void> {
return this.http.delete<void>(`${this.baseUrl}/${encodeURIComponent(id)}`);
}
restoreCategory(id: string): Observable<AdminCategory | null> {
return this.http.post<AdminCategory>(`${this.baseUrl}/${encodeURIComponent(id)}/restore`, {}).pipe(
catchError(() => of(null))
);
}
isSlugTaken(slug: string, excludingId: string | null): Observable<boolean> {
let params = new HttpParams().set('slug', slug);
if (excludingId) {
params = params.set('excludingId', excludingId);
}
return this.http.get<{ taken: boolean }>(`${this.baseUrl}/slug-taken`, { params }).pipe(
map(response => response.taken),
catchError(() => of(false))
);
}
}

View File

@@ -0,0 +1,14 @@
import { InjectionToken, inject } from '@angular/core';
import { RuntimeProviderStrategyService } from '../../../../core/providers/runtime-provider-strategy.service';
import { AdminCategoriesApiGateway } from './admin-categories-api.gateway';
import { AdminCategoriesLocalGateway } from './admin-categories-local.gateway';
import { AdminCategoriesGateway } from './admin-categories-gateway.interface';
export const ADMIN_CATEGORIES_GATEWAY = new InjectionToken<AdminCategoriesGateway>('ADMIN_CATEGORIES_GATEWAY', {
providedIn: 'root',
factory: () => {
const strategy = inject(RuntimeProviderStrategyService);
const mode = strategy.getBackofficeProviderMode();
return mode === 'mock' ? inject(AdminCategoriesLocalGateway) : inject(AdminCategoriesApiGateway);
}
});