sector => clean archi et test vert
This commit is contained in:
@@ -35,10 +35,7 @@ export class ProjectFacade {
|
||||
private readonly projectPresenter = new ProjectPresenter();
|
||||
|
||||
load(userId: string) {
|
||||
this.loading.set({
|
||||
action: ActionType.READ,
|
||||
isLoading: true,
|
||||
});
|
||||
this.handleError(ActionType.READ, false, null, true);
|
||||
|
||||
this.listUseCase.execute(userId).subscribe({
|
||||
next: (projects: Project[]) => {
|
||||
@@ -53,10 +50,7 @@ export class ProjectFacade {
|
||||
}
|
||||
|
||||
loadOne(projectId: string) {
|
||||
this.loading.set({
|
||||
action: ActionType.READ,
|
||||
isLoading: true,
|
||||
});
|
||||
this.handleError(ActionType.READ, false, null, true);
|
||||
|
||||
this.getUseCase.execute(projectId).subscribe({
|
||||
next: (project: Project) => {
|
||||
@@ -70,10 +64,7 @@ export class ProjectFacade {
|
||||
}
|
||||
|
||||
create(projectDto: CreateProjectDto) {
|
||||
this.loading.set({
|
||||
action: ActionType.CREATE,
|
||||
isLoading: true,
|
||||
});
|
||||
this.handleError(ActionType.CREATE, false, null, true);
|
||||
|
||||
this.createUseCase.execute(projectDto).subscribe({
|
||||
next: (project: Project) => {
|
||||
@@ -88,10 +79,7 @@ export class ProjectFacade {
|
||||
}
|
||||
|
||||
update(userId: string, data: any) {
|
||||
this.loading.set({
|
||||
action: ActionType.UPDATE,
|
||||
isLoading: true,
|
||||
});
|
||||
this.handleError(ActionType.UPDATE, false, null, true);
|
||||
|
||||
this.UpdateUseCase.execute(userId, data).subscribe({
|
||||
next: (project: Project) => {
|
||||
|
||||
65
src/app/ui/sectors/sector.facade.ts
Normal file
65
src/app/ui/sectors/sector.facade.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { inject, signal } from '@angular/core';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { ListSectorUsecase } from '@app/usecase/sectors/list-sector.usecase';
|
||||
import { GetSectorUseCase } from '@app/usecase/sectors/get-sector.usecase';
|
||||
import { ActionType } from '@app/domain/action-type.util';
|
||||
import { LoaderAction } from '@app/domain/loader-action.util';
|
||||
import { ErrorResponse } from '@app/domain/error-response.util';
|
||||
import { SectorPresenterModel } from '@app/ui/sectors/sector.presenter.model';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { SectorPresenter } from '@app/ui/sectors/sector.presenter';
|
||||
|
||||
export class SectorFacade {
|
||||
private readonly sectorRepo = inject(SECTOR_REPOSITORY_TOKEN);
|
||||
|
||||
private readonly listSectorUseCase = new ListSectorUsecase(this.sectorRepo);
|
||||
private readonly getSectorUseCase = new GetSectorUseCase(this.sectorRepo);
|
||||
|
||||
readonly sectors = signal<SectorPresenterModel[]>([]);
|
||||
readonly sector = signal<SectorPresenterModel>({} as SectorPresenterModel);
|
||||
|
||||
readonly loading = signal<LoaderAction>({ isLoading: false, action: ActionType.NONE });
|
||||
readonly error = signal<ErrorResponse>({
|
||||
action: ActionType.NONE,
|
||||
hasError: false,
|
||||
message: null,
|
||||
});
|
||||
|
||||
private readonly sectorPresenter = new SectorPresenter();
|
||||
|
||||
load() {
|
||||
this.handleError(ActionType.READ, false, null, true);
|
||||
this.listSectorUseCase.execute().subscribe({
|
||||
next: (sectors: Sector[]) => {
|
||||
this.sectors.set(this.sectorPresenter.toViewModels(sectors));
|
||||
this.handleError(ActionType.READ, false, null, false);
|
||||
},
|
||||
error: (err) => {
|
||||
this.handleError(ActionType.READ, false, err, false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
loadOne(sectorId: string) {
|
||||
this.handleError(ActionType.READ, false, null, true);
|
||||
this.getSectorUseCase.execute(sectorId).subscribe({
|
||||
next: (sector: Sector) => {
|
||||
this.sector.set(this.sectorPresenter.toViewModel(sector));
|
||||
this.handleError(ActionType.READ, false, null, false);
|
||||
},
|
||||
error: (err) => {
|
||||
this.handleError(ActionType.READ, false, err, false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private handleError(
|
||||
action: ActionType = ActionType.NONE,
|
||||
hasError: boolean,
|
||||
message: string | null = null,
|
||||
isLoading = false
|
||||
) {
|
||||
this.error.set({ action, hasError, message });
|
||||
this.loading.set({ action, isLoading });
|
||||
}
|
||||
}
|
||||
5
src/app/ui/sectors/sector.presenter.model.ts
Normal file
5
src/app/ui/sectors/sector.presenter.model.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface SectorPresenterModel {
|
||||
id: string;
|
||||
nom: string;
|
||||
noms?: string[];
|
||||
}
|
||||
17
src/app/ui/sectors/sector.presenter.ts
Normal file
17
src/app/ui/sectors/sector.presenter.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { SectorPresenterModel } from '@app/ui/sectors/sector.presenter.model';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
|
||||
export class SectorPresenter {
|
||||
toViewModel(sector: Sector): SectorPresenterModel {
|
||||
const names = sector.nom ? sector.nom.split('-') : [];
|
||||
return {
|
||||
id: sector.id,
|
||||
nom: sector.nom,
|
||||
noms: names,
|
||||
};
|
||||
}
|
||||
|
||||
toViewModels(sectors: Sector[]): SectorPresenterModel[] {
|
||||
return sectors.map(this.toViewModel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user