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

@@ -1,4 +1,4 @@
import type { Logger, UseCaseOutputPort, UseCase } from '@core/shared/application';
import type { Logger, UseCase } from '@core/shared/application';
import type { IPageViewRepository } from '../repositories/IPageViewRepository';
import { PageView } from '../../domain/entities/PageView';
import type { EntityType, VisitorType } from '../../domain/types/PageView';
@@ -22,14 +22,13 @@ export interface RecordPageViewOutput {
export type RecordPageViewErrorCode = 'REPOSITORY_ERROR';
export class RecordPageViewUseCase implements UseCase<RecordPageViewInput, void, RecordPageViewErrorCode> {
export class RecordPageViewUseCase implements UseCase<RecordPageViewInput, RecordPageViewOutput, RecordPageViewErrorCode> {
constructor(
private readonly pageViewRepository: IPageViewRepository,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<RecordPageViewOutput>,
) {}
async execute(input: RecordPageViewInput): Promise<Result<void, ApplicationErrorCode<RecordPageViewErrorCode, { message: string }>>> {
async execute(input: RecordPageViewInput): Promise<Result<RecordPageViewOutput, ApplicationErrorCode<RecordPageViewErrorCode, { message: string }>>> {
try {
type PageViewCreateProps = Parameters<(typeof PageView)['create']>[0];
@@ -53,15 +52,13 @@ export class RecordPageViewUseCase implements UseCase<RecordPageViewInput, void,
pageViewId: pageView.id,
};
this.output.present(resultModel);
this.logger.info('Page view recorded', {
pageViewId: pageView.id,
entityId: input.entityId,
entityType: input.entityType,
});
return Result.ok(undefined);
return Result.ok(resultModel);
} catch (error) {
const err = error as Error;
this.logger.error('Failed to record page view', err, { input });