project refactoring en clean archi

This commit is contained in:
styve Lioumba
2025-10-23 14:10:53 +02:00
parent ef02c6a537
commit 02637235e3
52 changed files with 3873 additions and 875 deletions

View File

@@ -5,30 +5,45 @@ import { Profile } from '@app/domain/profiles/profile.model';
import { Injectable } from '@angular/core';
import { ProfilePresenter } from '@app/ui/profiles/profile.presenter';
import { ProfileViewModel } from '@app/ui/profiles/profile.presenter.model';
import { LoaderAction } from '@app/domain/loader-action.util';
import { ActionType } from '@app/domain/action-type.util';
import { ErrorResponse } from '@app/domain/error-response.util';
@Injectable({
providedIn: 'root',
})
export class ProfileFacade {
private profileRepository = inject(PROFILE_REPOSITORY_TOKEN);
private useCase = new ListProfilesUseCase(this.profileRepository);
readonly loading = signal(false);
private listUseCase = new ListProfilesUseCase(this.profileRepository);
readonly profiles = signal<ProfileViewModel[]>([]);
readonly error = signal<string | null>(null);
readonly loading = signal<LoaderAction>({ isLoading: false, action: ActionType.NONE });
readonly error = signal<ErrorResponse>({
action: ActionType.NONE,
hasError: false,
message: null,
});
load(search?: string) {
this.loading.set(true);
this.error.set(null);
this.handleError(ActionType.READ, false, null, true);
this.useCase.execute({ search }).subscribe({
this.listUseCase.execute({ search }).subscribe({
next: (profiles) => {
this.profiles.set(ProfilePresenter.toViewModels(profiles));
this.loading.set(false);
this.handleError(ActionType.READ, false, null, false);
},
error: (err) => {
this.error.set('Failed to load profiles');
this.loading.set(false);
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 });
}
}