view models
This commit is contained in:
@@ -1,58 +1,57 @@
|
||||
import type { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
||||
import type { SponsorListPresenter } from '../../presenters/SponsorListPresenter';
|
||||
import type { SponsorDashboardPresenter } from '../../presenters/SponsorDashboardPresenter';
|
||||
import type { SponsorSponsorshipsPresenter } from '../../presenters/SponsorSponsorshipsPresenter';
|
||||
import type { SponsorViewModel, SponsorDashboardViewModel, SponsorSponsorshipsViewModel } from '../../view-models';
|
||||
import type { CreateSponsorInputDto, CreateSponsorOutputDto, GetEntitySponsorshipPricingResultDto } from '../../dtos';
|
||||
import { SponsorViewModel, SponsorDashboardViewModel, SponsorSponsorshipsViewModel } from '../../view-models';
|
||||
import type { CreateSponsorInputDTO } from '../../types/generated';
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type CreateSponsorOutputDto = { id: string; name: string };
|
||||
type GetEntitySponsorshipPricingResultDto = { pricing: Array<{ entityType: string; price: number }> };
|
||||
type SponsorDTO = { id: string; name: string; logoUrl?: string; websiteUrl?: string };
|
||||
|
||||
/**
|
||||
* Sponsor Service
|
||||
*
|
||||
* Orchestrates sponsor operations by coordinating API calls and presentation logic.
|
||||
* Orchestrates sponsor operations by coordinating API calls and view model creation.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class SponsorService {
|
||||
constructor(
|
||||
private readonly apiClient: SponsorsApiClient,
|
||||
private readonly sponsorListPresenter: SponsorListPresenter,
|
||||
private readonly sponsorDashboardPresenter: SponsorDashboardPresenter,
|
||||
private readonly sponsorSponsorshipsPresenter: SponsorSponsorshipsPresenter
|
||||
private readonly apiClient: SponsorsApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get all sponsors with presentation transformation
|
||||
* Get all sponsors with view model transformation
|
||||
*/
|
||||
async getAllSponsors(): Promise<SponsorViewModel[]> {
|
||||
const dto = await this.apiClient.getAll();
|
||||
return this.sponsorListPresenter.present(dto);
|
||||
return dto.sponsors.map((sponsor: SponsorDTO) => new SponsorViewModel(sponsor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sponsor dashboard with presentation transformation
|
||||
* Get sponsor dashboard with view model transformation
|
||||
*/
|
||||
async getSponsorDashboard(sponsorId: string): Promise<SponsorDashboardViewModel | null> {
|
||||
const dto = await this.apiClient.getDashboard(sponsorId);
|
||||
if (!dto) {
|
||||
return null;
|
||||
}
|
||||
return this.sponsorDashboardPresenter.present(dto);
|
||||
return new SponsorDashboardViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sponsor sponsorships with presentation transformation
|
||||
* Get sponsor sponsorships with view model transformation
|
||||
*/
|
||||
async getSponsorSponsorships(sponsorId: string): Promise<SponsorSponsorshipsViewModel | null> {
|
||||
const dto = await this.apiClient.getSponsorships(sponsorId);
|
||||
if (!dto) {
|
||||
return null;
|
||||
}
|
||||
return this.sponsorSponsorshipsPresenter.present(dto);
|
||||
return new SponsorSponsorshipsViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new sponsor
|
||||
*/
|
||||
async createSponsor(input: CreateSponsorInputDto): Promise<CreateSponsorOutputDto> {
|
||||
async createSponsor(input: CreateSponsorInputDTO): Promise<CreateSponsorOutputDto> {
|
||||
return await this.apiClient.create(input);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user