refactor
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import type { Presenter } from '../presentation';
|
||||
import type { Result } from './Result';
|
||||
import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';
|
||||
|
||||
@@ -8,9 +7,8 @@ import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';
|
||||
* Use cases represent application-level business logic. They coordinate domain objects and repositories,
|
||||
* but contain no infrastructure or framework concerns.
|
||||
*
|
||||
* Commands change system state and return nothing on success. They use a presenter to handle the output.
|
||||
* If a business rejection is possible, the output must be a Result<T, ApplicationErrorCode<E>> handled by the presenter.
|
||||
* Use cases do not throw errors; they use error codes in Result.
|
||||
* Commands change system state and return a Result on execution. If a business rejection is possible,
|
||||
* the result contains an ApplicationErrorCode<E>. Use cases do not throw errors; they use error codes in Result.
|
||||
*
|
||||
* Example:
|
||||
* ```typescript
|
||||
@@ -19,19 +17,17 @@ import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';
|
||||
* | 'RACE_ALREADY_EXISTS'
|
||||
* | 'INVALID_RACE_CONFIG';
|
||||
*
|
||||
* export class CreateRaceUseCase implements UseCase<CreateRaceInput, void, CreateRaceErrorCode, ViewModel, Presenter<Result<void, ApplicationErrorCode<CreateRaceErrorCode>>, ViewModel>> {
|
||||
* execute(input: CreateRaceInput, presenter: Presenter<Result<void, ApplicationErrorCode<CreateRaceErrorCode>>, ViewModel>): Promise<void> {
|
||||
* export class CreateRaceUseCase implements UseCase<CreateRaceInput, void, CreateRaceErrorCode> {
|
||||
* execute(input: CreateRaceInput): Promise<Result<void, ApplicationErrorCode<CreateRaceErrorCode>>> {
|
||||
* // implementation
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @template Input - The input type for the use case
|
||||
* @template Success - The success type in the Result passed to the presenter
|
||||
* @template Success - The success type in the Result
|
||||
* @template ErrorCode - The error code type for ApplicationErrorCode
|
||||
* @template ViewModel - The view model type
|
||||
* @template P - The presenter type, extending Presenter<Result<Success, ApplicationErrorCode<ErrorCode>>, ViewModel>
|
||||
*/
|
||||
export interface UseCase<Input, Success, ErrorCode extends string, ViewModel, P extends Presenter<Result<Success, ApplicationErrorCode<ErrorCode>>, ViewModel>> {
|
||||
execute(input: Input, presenter: P): Promise<void> | void;
|
||||
export interface UseCase<Input, Success, ErrorCode extends string> {
|
||||
execute(input: Input): Promise<Result<Success, ApplicationErrorCode<ErrorCode>>>;
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
import type { Result } from './Result';
|
||||
import type { ApplicationErrorCode } from '../errors/ApplicationErrorCode';
|
||||
|
||||
/**
|
||||
* Output Port interface for use cases.
|
||||
*
|
||||
* Defines how the core communicates outward. A behavioral boundary that allows
|
||||
* the use case to present results without knowing the presentation details.
|
||||
*
|
||||
* @template T - The result type to present
|
||||
* @template T - The success type in the Result
|
||||
* @template E - The error code type
|
||||
*/
|
||||
export interface UseCaseOutputPort<T> {
|
||||
present(data: T): void;
|
||||
export interface UseCaseOutputPort<T, E extends string = string> {
|
||||
present(result: Result<T, ApplicationErrorCode<E>>): any;
|
||||
}
|
||||
Reference in New Issue
Block a user