website refactor

This commit is contained in:
2026-01-16 12:55:48 +01:00
parent 0208334c59
commit 20a42c52fd
83 changed files with 1610 additions and 1238 deletions

View File

@@ -0,0 +1,34 @@
import { Result } from '@core/shared/application/Result';
import type { MediaStoragePort } from '../ports/MediaStoragePort';
export type GetUploadedMediaInput = {
storageKey: string;
};
export type GetUploadedMediaResult = {
bytes: Buffer;
contentType: string;
};
export class GetUploadedMediaUseCase {
constructor(private readonly mediaStorage: MediaStoragePort) {}
async execute(input: GetUploadedMediaInput): Promise<Result<GetUploadedMediaResult | null>> {
try {
const bytes = await this.mediaStorage.getBytes!(input.storageKey);
if (!bytes) {
return Result.ok(null);
}
const metadata = await this.mediaStorage.getMetadata!(input.storageKey);
const contentType = metadata?.contentType || 'application/octet-stream';
return Result.ok({
bytes: Buffer.from(bytes),
contentType,
});
} catch (error) {
return Result.err(error instanceof Error ? error : new Error(String(error)));
}
}
}

View File

@@ -0,0 +1,20 @@
import { Result } from '@core/shared/application/Result';
import type { MediaReference } from '@core/domain/media/MediaReference';
import type { MediaResolverPort } from '@core/ports/media/MediaResolverPort';
export type ResolveMediaReferenceInput = {
reference: MediaReference;
};
export class ResolveMediaReferenceUseCase {
constructor(private readonly mediaResolver: MediaResolverPort) {}
async execute(input: ResolveMediaReferenceInput): Promise<Result<string | null>> {
try {
const resolvedPath = await this.mediaResolver.resolve(input.reference);
return Result.ok(resolvedPath);
} catch (error) {
return Result.err(error instanceof Error ? error : new Error(String(error)));
}
}
}

View File

@@ -0,0 +1,63 @@
/**
* Application Use Case: GetAllNotificationsUseCase
*
* Retrieves all notifications for a recipient.
*/
import type { Logger } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { Notification } from '../../domain/entities/Notification';
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
export type GetAllNotificationsInput = {
recipientId: string;
};
export interface GetAllNotificationsResult {
notifications: Notification[];
totalCount: number;
}
export type GetAllNotificationsErrorCode = 'REPOSITORY_ERROR';
export class GetAllNotificationsUseCase {
constructor(
private readonly notificationRepository: INotificationRepository,
private readonly logger: Logger,
) {}
async execute(
input: GetAllNotificationsInput,
): Promise<Result<GetAllNotificationsResult, ApplicationErrorCode<GetAllNotificationsErrorCode, { message: string }>>> {
const { recipientId } = input;
this.logger.debug(
`Attempting to retrieve all notifications for recipient ID: ${recipientId}`,
);
try {
const notifications = await this.notificationRepository.findByRecipientId(
recipientId,
);
this.logger.info(
`Successfully retrieved ${notifications.length} notifications for recipient ID: ${recipientId}`,
);
return Result.ok<GetAllNotificationsResult, ApplicationErrorCode<GetAllNotificationsErrorCode, { message: string }>>({
notifications,
totalCount: notifications.length,
});
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
this.logger.error(
`Failed to retrieve notifications for recipient ID: ${recipientId}`,
err,
);
return Result.err<GetAllNotificationsResult, ApplicationErrorCode<GetAllNotificationsErrorCode, { message: string }>>({
code: 'REPOSITORY_ERROR',
details: { message: err.message },
});
}
}
}

View File

@@ -0,0 +1,20 @@
import { Result } from '@core/shared/application/Result';
import type { Driver } from '../../domain/entities/Driver';
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
export type GetDriverInput = {
driverId: string;
};
export class GetDriverUseCase {
constructor(private readonly driverRepository: IDriverRepository) {}
async execute(input: GetDriverInput): Promise<Result<Driver | null>> {
try {
const driver = await this.driverRepository.findById(input.driverId);
return Result.ok(driver);
} catch (error) {
return Result.err(error instanceof Error ? error : new Error(String(error)));
}
}
}