wip
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
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';
|
||||
@@ -22,33 +23,46 @@ export class GetCurrentUserSocialUseCase
|
||||
constructor(
|
||||
private readonly socialGraphRepository: ISocialGraphRepository,
|
||||
public readonly presenter: ICurrentUserSocialPresenter,
|
||||
private readonly logger: ILogger,
|
||||
) {}
|
||||
|
||||
async execute(params: GetCurrentUserSocialParams): Promise<void> {
|
||||
const { driverId } = params;
|
||||
this.logger.debug('GetCurrentUserSocialUseCase: Starting execution', { params });
|
||||
try {
|
||||
const { driverId } = params;
|
||||
|
||||
const friendsDomain = await this.socialGraphRepository.getFriends(driverId);
|
||||
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 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 currentUser: CurrentUserSocialDTO = {
|
||||
driverId,
|
||||
displayName: '',
|
||||
avatarUrl: '',
|
||||
countryCode: '',
|
||||
};
|
||||
|
||||
const viewModel: CurrentUserSocialViewModel = {
|
||||
currentUser,
|
||||
friends,
|
||||
};
|
||||
const viewModel: CurrentUserSocialViewModel = {
|
||||
currentUser,
|
||||
friends,
|
||||
};
|
||||
|
||||
this.presenter.present(viewModel);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
IUserFeedPresenter,
|
||||
UserFeedViewModel,
|
||||
} from '../presenters/ISocialPresenters';
|
||||
import type { ILogger } from '../../../shared/src/logging/ILogger';
|
||||
|
||||
export interface GetUserFeedParams {
|
||||
driverId: string;
|
||||
@@ -17,18 +18,30 @@ export class GetUserFeedUseCase
|
||||
constructor(
|
||||
private readonly feedRepository: IFeedRepository,
|
||||
public readonly presenter: IUserFeedPresenter,
|
||||
private readonly logger: ILogger,
|
||||
) {}
|
||||
|
||||
async execute(params: GetUserFeedParams): Promise<void> {
|
||||
const { driverId, limit } = params;
|
||||
const items = await this.feedRepository.getFeedForDriver(driverId, limit);
|
||||
const dtoItems = items.map(mapFeedItemToDTO);
|
||||
this.logger.debug('Executing GetUserFeedUseCase', { driverId, limit });
|
||||
|
||||
const viewModel: UserFeedViewModel = {
|
||||
items: dtoItems,
|
||||
};
|
||||
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);
|
||||
|
||||
this.presenter.present(viewModel);
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user