profiles => format clean archi
This commit is contained in:
34
src/app/ui/profiles/profile.facade.ts
Normal file
34
src/app/ui/profiles/profile.facade.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { ListProfilesUseCase } from '@app/usecase/profiles/list-profiles.usecase';
|
||||
import { inject, signal } from '@angular/core';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
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';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProfileFacade {
|
||||
private profileRepository = inject(PROFILE_REPOSITORY_TOKEN);
|
||||
private useCase = new ListProfilesUseCase(this.profileRepository);
|
||||
readonly loading = signal(false);
|
||||
readonly profiles = signal<ProfileViewModel[]>([]);
|
||||
readonly error = signal<string | null>(null);
|
||||
|
||||
load(search?: string) {
|
||||
this.loading.set(true);
|
||||
this.error.set(null);
|
||||
|
||||
this.useCase.execute({ search }).subscribe({
|
||||
next: (profiles) => {
|
||||
this.profiles.set(ProfilePresenter.toViewModels(profiles));
|
||||
this.loading.set(false);
|
||||
},
|
||||
error: (err) => {
|
||||
this.error.set('Failed to load profiles');
|
||||
this.loading.set(false);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
12
src/app/ui/profiles/profile.presenter.model.ts
Normal file
12
src/app/ui/profiles/profile.presenter.model.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export interface ProfileViewModel {
|
||||
id: string;
|
||||
fullName: string;
|
||||
isVerifiedLabel: string;
|
||||
createdAtFormatted: string;
|
||||
avatarUrl?: string;
|
||||
estVerifier: boolean;
|
||||
utilisateur: string;
|
||||
profession: string;
|
||||
secteur: string;
|
||||
reseaux: any;
|
||||
}
|
||||
23
src/app/ui/profiles/profile.presenter.ts
Normal file
23
src/app/ui/profiles/profile.presenter.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ProfileViewModel } from '@app/ui/profiles/profile.presenter.model';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
|
||||
export class ProfilePresenter {
|
||||
static toViewModel(profile: Profile): ProfileViewModel {
|
||||
return {
|
||||
id: profile.id,
|
||||
fullName: profile.profession.toUpperCase(), // ❗ exemple volontaire
|
||||
isVerifiedLabel: profile.estVerifier ? '✅ Vérifié' : '❌ Non vérifié',
|
||||
createdAtFormatted: new Date(profile.created).toLocaleDateString(),
|
||||
avatarUrl: '',
|
||||
estVerifier: profile.estVerifier,
|
||||
utilisateur: profile.utilisateur,
|
||||
profession: profile.profession,
|
||||
secteur: profile.secteur,
|
||||
reseaux: profile.reseaux,
|
||||
};
|
||||
}
|
||||
|
||||
static toViewModels(profiles: Profile[]): ProfileViewModel[] {
|
||||
return profiles.map(this.toViewModel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user