admin area
This commit is contained in:
44
apps/website/lib/services/AdminViewModelService.ts
Normal file
44
apps/website/lib/services/AdminViewModelService.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { UserDto, DashboardStats, UserListResponse } from '@/lib/api/admin/AdminApiClient';
|
||||
import { AdminUserViewModel, DashboardStatsViewModel, UserListViewModel } from '@/lib/view-models/AdminUserViewModel';
|
||||
|
||||
/**
|
||||
* AdminViewModelService
|
||||
*
|
||||
* Service layer responsible for mapping API DTOs to View Models.
|
||||
* This is where the transformation from API data to UI-ready state happens.
|
||||
*/
|
||||
export class AdminViewModelService {
|
||||
/**
|
||||
* Map a single user DTO to a View Model
|
||||
*/
|
||||
static mapUser(dto: UserDto): AdminUserViewModel {
|
||||
return new AdminUserViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map an array of user DTOs to View Models
|
||||
*/
|
||||
static mapUsers(dtos: UserDto[]): AdminUserViewModel[] {
|
||||
return dtos.map(dto => this.mapUser(dto));
|
||||
}
|
||||
|
||||
/**
|
||||
* Map dashboard stats DTO to View Model
|
||||
*/
|
||||
static mapDashboardStats(dto: DashboardStats): DashboardStatsViewModel {
|
||||
return new DashboardStatsViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map user list response to View Model
|
||||
*/
|
||||
static mapUserList(response: UserListResponse): UserListViewModel {
|
||||
return new UserListViewModel({
|
||||
users: response.users,
|
||||
total: response.total,
|
||||
page: response.page,
|
||||
limit: response.limit,
|
||||
totalPages: response.totalPages,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user