arch(sprint1): decouple backoffice facade from http provider
This commit is contained in:
@@ -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)
|
||||
});
|
||||
17
src/app/core/backoffice/backoffice-data.service.ts
Normal file
17
src/app/core/backoffice/backoffice-data.service.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { ProductCardConfig, CategoryCardConfig } from '../../../shared/models/ui';
|
||||
|
||||
export interface BackofficeDataProvider {
|
||||
loadProducts(): Observable<ProductCardConfig[]>;
|
||||
loadCategories(): Observable<CategoryCardConfig[]>;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user