wip
This commit is contained in:
17
packages/social/application/dto/FeedItemDTO.ts
Normal file
17
packages/social/application/dto/FeedItemDTO.ts
Normal 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;
|
||||
}
|
||||
16
packages/social/application/index.ts
Normal file
16
packages/social/application/index.ts
Normal 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';
|
||||
20
packages/social/application/presenters/ISocialPresenters.ts
Normal file
20
packages/social/application/presenters/ISocialPresenters.ts
Normal 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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
52
packages/social/application/use-cases/GetUserFeedUseCase.ts
Normal file
52
packages/social/application/use-cases/GetUserFeedUseCase.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user