view models
This commit is contained in:
@@ -1,44 +1,40 @@
|
||||
import type { SponsorsApiClient } from '../../api/sponsors/SponsorsApiClient';
|
||||
import type { SponsorshipPricingPresenter } from '../../presenters/SponsorshipPricingPresenter';
|
||||
import type { SponsorSponsorshipsPresenter } from '../../presenters/SponsorSponsorshipsPresenter';
|
||||
import type {
|
||||
import {
|
||||
SponsorshipPricingViewModel,
|
||||
SponsorSponsorshipsViewModel
|
||||
} from '../../view-models';
|
||||
import type {
|
||||
GetEntitySponsorshipPricingResultDto,
|
||||
SponsorSponsorshipsDto
|
||||
} from '../../dtos';
|
||||
import type { SponsorSponsorshipsDTO } from '../../types/generated';
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type GetEntitySponsorshipPricingResultDto = { pricing: Array<{ entityType: string; price: number }> };
|
||||
|
||||
/**
|
||||
* Sponsorship Service
|
||||
*
|
||||
* Orchestrates sponsorship operations by coordinating API calls and presentation logic.
|
||||
* Orchestrates sponsorship operations by coordinating API calls and view model creation.
|
||||
* All dependencies are injected via constructor.
|
||||
*/
|
||||
export class SponsorshipService {
|
||||
constructor(
|
||||
private readonly apiClient: SponsorsApiClient,
|
||||
private readonly sponsorshipPricingPresenter: SponsorshipPricingPresenter,
|
||||
private readonly sponsorSponsorshipsPresenter: SponsorSponsorshipsPresenter
|
||||
private readonly apiClient: SponsorsApiClient
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get sponsorship pricing with presentation transformation
|
||||
* Get sponsorship pricing with view model transformation
|
||||
*/
|
||||
async getSponsorshipPricing(): Promise<SponsorshipPricingViewModel> {
|
||||
const dto = await this.apiClient.getPricing();
|
||||
return this.sponsorshipPricingPresenter.present(dto);
|
||||
return new SponsorshipPricingViewModel(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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user