This commit is contained in:
2025-12-11 11:25:22 +01:00
parent 6a427eab57
commit e4c1be628d
86 changed files with 1222 additions and 736 deletions

View File

@@ -0,0 +1,17 @@
import type { FeedItemType } from '../../domain/value-objects/FeedItemType';
export interface FeedItemDTO {
id: string;
timestamp: string;
type: FeedItemType;
actorFriendId?: string;
actorDriverId?: string;
leagueId?: string;
raceId?: string;
teamId?: string;
position?: number;
headline: string;
body?: string;
ctaLabel?: string;
ctaHref?: string;
}

View File

@@ -0,0 +1,16 @@
export { GetCurrentUserSocialUseCase } from './use-cases/GetCurrentUserSocialUseCase';
export type { GetCurrentUserSocialParams } from './use-cases/GetCurrentUserSocialUseCase';
export { GetUserFeedUseCase } from './use-cases/GetUserFeedUseCase';
export type { GetUserFeedParams } from './use-cases/GetUserFeedUseCase';
export type { CurrentUserSocialDTO } from './dto/CurrentUserSocialDTO';
export type { FriendDTO } from './dto/FriendDTO';
export type { FeedItemDTO } from './dto/FeedItemDTO';
export type {
CurrentUserSocialViewModel,
ICurrentUserSocialPresenter,
UserFeedViewModel,
IUserFeedPresenter,
} from './presenters/ISocialPresenters';

View File

@@ -0,0 +1,20 @@
import type { CurrentUserSocialDTO } from '../dto/CurrentUserSocialDTO';
import type { FriendDTO } from '../dto/FriendDTO';
import type { FeedItemDTO } from '../dto/FeedItemDTO';
export interface CurrentUserSocialViewModel {
currentUser: CurrentUserSocialDTO;
friends: FriendDTO[];
}
export interface ICurrentUserSocialPresenter {
present(viewModel: CurrentUserSocialViewModel): void;
}
export interface UserFeedViewModel {
items: FeedItemDTO[];
}
export interface IUserFeedPresenter {
present(viewModel: UserFeedViewModel): void;
}

View File

@@ -0,0 +1,56 @@
import type { ISocialGraphRepository } from '../../domain/repositories/ISocialGraphRepository';
import type { CurrentUserSocialDTO } from '../dto/CurrentUserSocialDTO';
import type { FriendDTO } from '../dto/FriendDTO';
import type {
CurrentUserSocialViewModel,
ICurrentUserSocialPresenter,
} from '../presenters/ISocialPresenters';
export interface GetCurrentUserSocialParams {
driverId: string;
}
/**
* Application-level use case to retrieve the current user's social context.
*
* Keeps orchestration in the social bounded context while delegating
* data access to domain repositories and presenting via a presenter.
*/
export class GetCurrentUserSocialUseCase {
constructor(
private readonly socialGraphRepository: ISocialGraphRepository,
public readonly presenter: ICurrentUserSocialPresenter,
) {}
async execute(params: GetCurrentUserSocialParams): Promise<void> {
const { driverId } = params;
const friendsDomain = await this.socialGraphRepository.getFriends(driverId);
const friends: FriendDTO[] = friendsDomain.map((friend) => ({
driverId: friend.id,
displayName: friend.name,
avatarUrl: '',
isOnline: false,
lastSeen: new Date(),
primaryLeagueId: undefined,
primaryTeamId: undefined,
}));
const currentUser: CurrentUserSocialDTO = {
driverId,
displayName: '',
avatarUrl: '',
countryCode: '',
primaryTeamId: undefined,
primaryLeagueId: undefined,
};
const viewModel: CurrentUserSocialViewModel = {
currentUser,
friends,
};
this.presenter.present(viewModel);
}
}

View File

@@ -0,0 +1,52 @@
import type { IFeedRepository } from '../../domain/repositories/IFeedRepository';
import type { FeedItemDTO } from '../dto/FeedItemDTO';
import type { FeedItem } from '../../domain/entities/FeedItem';
import type {
IUserFeedPresenter,
UserFeedViewModel,
} from '../presenters/ISocialPresenters';
export interface GetUserFeedParams {
driverId: string;
limit?: number;
}
export class GetUserFeedUseCase {
constructor(
private readonly feedRepository: IFeedRepository,
public readonly presenter: IUserFeedPresenter,
) {}
async execute(params: GetUserFeedParams): Promise<void> {
const { driverId, limit } = params;
const items = await this.feedRepository.getFeedForDriver(driverId, limit);
const dtoItems = items.map(mapFeedItemToDTO);
const viewModel: UserFeedViewModel = {
items: dtoItems,
};
this.presenter.present(viewModel);
}
}
function mapFeedItemToDTO(item: FeedItem): FeedItemDTO {
return {
id: item.id,
timestamp:
item.timestamp instanceof Date
? item.timestamp.toISOString()
: new Date(item.timestamp).toISOString(),
type: item.type,
actorFriendId: item.actorFriendId,
actorDriverId: item.actorDriverId,
leagueId: item.leagueId,
raceId: item.raceId,
teamId: item.teamId,
position: item.position,
headline: item.headline,
body: item.body,
ctaLabel: item.ctaLabel,
ctaHref: item.ctaHref,
};
}