rename to core
This commit is contained in:
8
core/social/application/dto/CurrentUserSocialDTO.ts
Normal file
8
core/social/application/dto/CurrentUserSocialDTO.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export interface CurrentUserSocialDTO {
|
||||
driverId: string;
|
||||
displayName: string;
|
||||
avatarUrl: string;
|
||||
countryCode: string;
|
||||
primaryTeamId?: string;
|
||||
primaryLeagueId?: string;
|
||||
}
|
||||
22
core/social/application/dto/FeedItemDTO.ts
Normal file
22
core/social/application/dto/FeedItemDTO.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export type FeedItemType =
|
||||
| 'race_result'
|
||||
| 'championship_standing'
|
||||
| 'league_announcement'
|
||||
| 'friend_joined_league'
|
||||
| 'friend_won_race';
|
||||
|
||||
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;
|
||||
}
|
||||
9
core/social/application/dto/FriendDTO.ts
Normal file
9
core/social/application/dto/FriendDTO.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface FriendDTO {
|
||||
driverId: string;
|
||||
displayName: string;
|
||||
avatarUrl: string;
|
||||
isOnline: boolean;
|
||||
lastSeen: Date;
|
||||
primaryLeagueId?: string;
|
||||
primaryTeamId?: string;
|
||||
}
|
||||
16
core/social/application/index.ts
Normal file
16
core/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
core/social/application/presenters/ISocialPresenters.ts
Normal file
20
core/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,68 @@
|
||||
import type { AsyncUseCase } from '@gridpilot/shared/application';
|
||||
import type { ILogger } from '../../../shared/src/logging/ILogger';
|
||||
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
|
||||
implements AsyncUseCase<GetCurrentUserSocialParams, void> {
|
||||
constructor(
|
||||
private readonly socialGraphRepository: ISocialGraphRepository,
|
||||
public readonly presenter: ICurrentUserSocialPresenter,
|
||||
private readonly logger: ILogger,
|
||||
) {}
|
||||
|
||||
async execute(params: GetCurrentUserSocialParams): Promise<void> {
|
||||
this.logger.debug('GetCurrentUserSocialUseCase: Starting execution', { params });
|
||||
try {
|
||||
const { driverId } = params;
|
||||
|
||||
this.logger.debug(`GetCurrentUserSocialUseCase: Fetching friends for driverId: ${driverId}`);
|
||||
const friendsDomain = await this.socialGraphRepository.getFriends(driverId);
|
||||
this.logger.debug('GetCurrentUserSocialUseCase: Successfully fetched friends from social graph repository', { friendsCount: friendsDomain.length });
|
||||
if (friendsDomain.length === 0) {
|
||||
this.logger.warn(`GetCurrentUserSocialUseCase: No friends found for driverId: ${driverId}`);
|
||||
}
|
||||
|
||||
const friends: FriendDTO[] = friendsDomain.map((friend) => ({
|
||||
driverId: friend.id,
|
||||
displayName: friend.name,
|
||||
avatarUrl: '',
|
||||
isOnline: false,
|
||||
lastSeen: new Date(),
|
||||
}));
|
||||
|
||||
const currentUser: CurrentUserSocialDTO = {
|
||||
driverId,
|
||||
displayName: '',
|
||||
avatarUrl: '',
|
||||
countryCode: '',
|
||||
};
|
||||
|
||||
const viewModel: CurrentUserSocialViewModel = {
|
||||
currentUser,
|
||||
friends,
|
||||
};
|
||||
|
||||
this.presenter.present(viewModel);
|
||||
this.logger.info('GetCurrentUserSocialUseCase: Successfully presented current user social data');
|
||||
} catch (error) {
|
||||
this.logger.error('GetCurrentUserSocialUseCase: Error during execution', { error });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
core/social/application/use-cases/GetUserFeedUseCase.ts
Normal file
72
core/social/application/use-cases/GetUserFeedUseCase.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import type { AsyncUseCase } from '@gridpilot/shared/application';
|
||||
import type { IFeedRepository } from '../../domain/repositories/IFeedRepository';
|
||||
import type { FeedItemDTO } from '../dto/FeedItemDTO';
|
||||
import type { FeedItem } from '../../domain/types/FeedItem';
|
||||
import type {
|
||||
IUserFeedPresenter,
|
||||
UserFeedViewModel,
|
||||
} from '../presenters/ISocialPresenters';
|
||||
import type { ILogger } from '../../../shared/src/logging/ILogger';
|
||||
|
||||
export interface GetUserFeedParams {
|
||||
driverId: string;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export class GetUserFeedUseCase
|
||||
implements AsyncUseCase<GetUserFeedParams, void> {
|
||||
constructor(
|
||||
private readonly feedRepository: IFeedRepository,
|
||||
public readonly presenter: IUserFeedPresenter,
|
||||
private readonly logger: ILogger,
|
||||
) {}
|
||||
|
||||
async execute(params: GetUserFeedParams): Promise<void> {
|
||||
const { driverId, limit } = params;
|
||||
this.logger.debug('Executing GetUserFeedUseCase', { driverId, limit });
|
||||
|
||||
try {
|
||||
const items = await this.feedRepository.getFeedForDriver(driverId, limit);
|
||||
this.logger.info('Successfully retrieved user feed', { driverId, itemCount: items.length });
|
||||
if (items.length === 0) {
|
||||
this.logger.warn(`No feed items found for driverId: ${driverId}`);
|
||||
}
|
||||
const dtoItems = items.map(mapFeedItemToDTO);
|
||||
|
||||
const viewModel: UserFeedViewModel = {
|
||||
items: dtoItems,
|
||||
};
|
||||
|
||||
this.presenter.present(viewModel);
|
||||
} catch (error) {
|
||||
this.logger.error('Failed to retrieve user feed', error);
|
||||
throw error; // Re-throw the error so it can be handled upstream
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mapFeedItemToDTO(item: FeedItem): FeedItemDTO {
|
||||
const mappedType = (item.type as string).replace(/-/g, '_') as FeedItemDTO['type'];
|
||||
|
||||
const dto: FeedItemDTO = {
|
||||
id: item.id,
|
||||
timestamp:
|
||||
item.timestamp instanceof Date
|
||||
? item.timestamp.toISOString()
|
||||
: new Date(item.timestamp).toISOString(),
|
||||
type: mappedType,
|
||||
headline: item.headline,
|
||||
};
|
||||
|
||||
if (item.actorFriendId !== undefined) dto.actorFriendId = item.actorFriendId;
|
||||
if (item.actorDriverId !== undefined) dto.actorDriverId = item.actorDriverId;
|
||||
if (item.leagueId !== undefined) dto.leagueId = item.leagueId;
|
||||
if (item.raceId !== undefined) dto.raceId = item.raceId;
|
||||
if (item.teamId !== undefined) dto.teamId = item.teamId;
|
||||
if (item.position !== undefined) dto.position = item.position;
|
||||
if (item.body !== undefined) dto.body = item.body;
|
||||
if (item.ctaLabel !== undefined) dto.ctaLabel = item.ctaLabel;
|
||||
if (item.ctaHref !== undefined) dto.ctaHref = item.ctaHref;
|
||||
|
||||
return dto;
|
||||
}
|
||||
Reference in New Issue
Block a user