arch(sprint1): decouple backoffice facade from http provider

This commit is contained in:
sdarbinyan
2026-07-03 02:01:01 +04:00
parent 95dbea7768
commit ac48799d9a
8 changed files with 75 additions and 54 deletions

View File

@@ -0,0 +1,8 @@
import { InjectionToken, inject } from '@angular/core';
import { BackofficeDataProvider } from './providers/backoffice-data-provider.interface';
import { MockBackofficeDataProvider } from './providers/mock-backoffice-data.provider';
export const BACKOFFICE_DATA_PROVIDER = new InjectionToken<BackofficeDataProvider>('BACKOFFICE_DATA_PROVIDER', {
providedIn: 'root',
factory: () => inject(MockBackofficeDataProvider)
});

View File

@@ -0,0 +1,17 @@
import { Injectable, inject } from '@angular/core';
import { Observable } from 'rxjs';
import { ProductCardConfig, CategoryCardConfig } from '../../shared/models/ui';
import { BACKOFFICE_DATA_PROVIDER } from './backoffice-data-provider.token';
@Injectable({ providedIn: 'root' })
export class BackofficeDataService {
private readonly provider = inject(BACKOFFICE_DATA_PROVIDER);
loadProducts(): Observable<ProductCardConfig[]> {
return this.provider.loadProducts();
}
loadCategories(): Observable<CategoryCardConfig[]> {
return this.provider.loadCategories();
}
}

View File

@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ProductCardConfig, CategoryCardConfig } from '../../../shared/models/ui';
import { BackofficeDataProvider } from './backoffice-data-provider.interface';
@Injectable({ providedIn: 'root' })
export class ApiBackofficeDataProvider implements BackofficeDataProvider {
constructor(private readonly http: HttpClient) {}
loadProducts(): Observable<ProductCardConfig[]> {
return this.http.get<ProductCardConfig[]>('/api/backoffice/products');
}
loadCategories(): Observable<CategoryCardConfig[]> {
return this.http.get<CategoryCardConfig[]>('/api/backoffice/categories');
}
}

View File

@@ -0,0 +1,7 @@
import { Observable } from 'rxjs';
import { ProductCardConfig, CategoryCardConfig } from '../../../shared/models/ui';
export interface BackofficeDataProvider {
loadProducts(): Observable<ProductCardConfig[]>;
loadCategories(): Observable<CategoryCardConfig[]>;
}

View File

@@ -0,0 +1,21 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { ProductCardConfig, CategoryCardConfig } from '../../../shared/models/ui';
import { BackofficeDataProvider } from './backoffice-data-provider.interface';
@Injectable({ providedIn: 'root' })
export class MockBackofficeDataProvider implements BackofficeDataProvider {
private readonly productsUrl = '/assets/mock/backoffice/products/list.json';
private readonly categoriesUrl = '/assets/mock/backoffice/categories/list.json';
constructor(private readonly http: HttpClient) {}
loadProducts(): Observable<ProductCardConfig[]> {
return this.http.get<ProductCardConfig[]>(this.productsUrl);
}
loadCategories(): Observable<CategoryCardConfig[]> {
return this.http.get<CategoryCardConfig[]>(this.categoriesUrl);
}
}