refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -14,8 +14,6 @@ import type { Weekday } from '../../domain/types/Weekday';
import { v4 as uuidv4 } from 'uuid';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
/**
* Input, result and error models shared across Season-focused use cases.
*/
@@ -180,15 +178,12 @@ export type ManageSeasonLifecycleApplicationError = ApplicationErrorCode<
* configuration from a source Season or a league config form.
*/
export class CreateSeasonForLeagueUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository,
private readonly output: UseCaseOutputPort<CreateSeasonForLeagueResult>,
) {}
constructor(private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository) {}
async execute(
command: CreateSeasonForLeagueCommand,
): Promise<Result<void, CreateSeasonForLeagueApplicationError>> {
): Promise<Result<CreateSeasonForLeagueResult, CreateSeasonForLeagueApplicationError>> {
try {
const league = await this.leagueRepository.findById(command.leagueId);
if (!league) {
@@ -265,9 +260,7 @@ export class CreateSeasonForLeagueUseCase {
await this.seasonRepository.add(season);
this.output.present({ season });
return Result.ok(undefined);
return Result.ok({ season });
} catch (error) {
return Result.err({
code: 'REPOSITORY_ERROR',
@@ -408,15 +401,12 @@ export class CreateSeasonForLeagueUseCase {
* ListSeasonsForLeagueUseCase
*/
export class ListSeasonsForLeagueUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository,
private readonly output: UseCaseOutputPort<ListSeasonsForLeagueResult>,
) {}
constructor(private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository) {}
async execute(
query: ListSeasonsForLeagueQuery,
): Promise<Result<void, ListSeasonsForLeagueApplicationError>> {
): Promise<Result<ListSeasonsForLeagueResult, ListSeasonsForLeagueApplicationError>> {
try {
const league = await this.leagueRepository.findById(query.leagueId);
if (!league) {
@@ -430,9 +420,7 @@ export class ListSeasonsForLeagueUseCase {
const seasons = await this.seasonRepository.listByLeague(league.id.toString());
this.output.present({ seasons });
return Result.ok(undefined);
return Result.ok({ seasons });
} catch (error) {
return Result.err({
code: 'REPOSITORY_ERROR',
@@ -448,15 +436,12 @@ export class ListSeasonsForLeagueUseCase {
* GetSeasonDetailsUseCase
*/
export class GetSeasonDetailsUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository,
private readonly output: UseCaseOutputPort<GetSeasonDetailsResult>,
) {}
constructor(private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository) {}
async execute(
query: GetSeasonDetailsQuery,
): Promise<Result<void, GetSeasonDetailsApplicationError>> {
): Promise<Result<GetSeasonDetailsResult, GetSeasonDetailsApplicationError>> {
try {
const league = await this.leagueRepository.findById(query.leagueId);
if (!league) {
@@ -478,9 +463,7 @@ export class GetSeasonDetailsUseCase {
});
}
this.output.present({ season });
return Result.ok(undefined);
return Result.ok({ season });
} catch (error) {
return Result.err({
code: 'REPOSITORY_ERROR',
@@ -496,15 +479,12 @@ export class GetSeasonDetailsUseCase {
* ManageSeasonLifecycleUseCase
*/
export class ManageSeasonLifecycleUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository,
private readonly output: UseCaseOutputPort<ManageSeasonLifecycleResult>,
) {}
constructor(private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository) {}
async execute(
command: ManageSeasonLifecycleCommand,
): Promise<Result<void, ManageSeasonLifecycleApplicationError>> {
): Promise<Result<ManageSeasonLifecycleResult, ManageSeasonLifecycleApplicationError>> {
try {
const league = await this.leagueRepository.findById(command.leagueId);
if (!league) {
@@ -570,9 +550,7 @@ export class ManageSeasonLifecycleUseCase {
});
}
this.output.present({ season: updated });
return Result.ok(undefined);
return Result.ok({ season: updated });
} catch (error) {
return Result.err({
code: 'REPOSITORY_ERROR',