presenter refactoring
This commit is contained in:
@@ -29,11 +29,13 @@ export class MediaController {
|
||||
@Body() input: RequestAvatarGenerationInput,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const result = await this.mediaService.requestAvatarGeneration(input);
|
||||
if (result.success) {
|
||||
res.status(HttpStatus.CREATED).json(result);
|
||||
const presenter = await this.mediaService.requestAvatarGeneration(input);
|
||||
const viewModel = presenter.viewModel;
|
||||
|
||||
if (viewModel.success) {
|
||||
res.status(HttpStatus.CREATED).json(viewModel);
|
||||
} else {
|
||||
res.status(HttpStatus.BAD_REQUEST).json(result);
|
||||
res.status(HttpStatus.BAD_REQUEST).json(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +49,13 @@ export class MediaController {
|
||||
@Body() input: UploadMediaInput,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const result = await this.mediaService.uploadMedia({ ...input, file });
|
||||
if (result.success) {
|
||||
res.status(HttpStatus.CREATED).json(result);
|
||||
const presenter = await this.mediaService.uploadMedia({ ...input, file });
|
||||
const viewModel = presenter.viewModel;
|
||||
|
||||
if (viewModel.success) {
|
||||
res.status(HttpStatus.CREATED).json(viewModel);
|
||||
} else {
|
||||
res.status(HttpStatus.BAD_REQUEST).json(result);
|
||||
res.status(HttpStatus.BAD_REQUEST).json(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +67,11 @@ export class MediaController {
|
||||
@Param('mediaId') mediaId: string,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const result = await this.mediaService.getMedia(mediaId);
|
||||
if (result) {
|
||||
res.status(HttpStatus.OK).json(result);
|
||||
const presenter = await this.mediaService.getMedia(mediaId);
|
||||
const viewModel = presenter.viewModel;
|
||||
|
||||
if (viewModel) {
|
||||
res.status(HttpStatus.OK).json(viewModel);
|
||||
} else {
|
||||
res.status(HttpStatus.NOT_FOUND).json({ error: 'Media not found' });
|
||||
}
|
||||
@@ -79,10 +85,12 @@ export class MediaController {
|
||||
@Param('mediaId') mediaId: string,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const result = await this.mediaService.deleteMedia(mediaId);
|
||||
res.status(HttpStatus.OK).json(result);
|
||||
}
|
||||
const presenter = await this.mediaService.deleteMedia(mediaId);
|
||||
const viewModel = presenter.viewModel;
|
||||
|
||||
res.status(HttpStatus.OK).json(viewModel);
|
||||
}
|
||||
|
||||
@Get('avatar/:driverId')
|
||||
@ApiOperation({ summary: 'Get avatar for driver' })
|
||||
@ApiParam({ name: 'driverId', description: 'Driver ID' })
|
||||
@@ -91,14 +99,16 @@ export class MediaController {
|
||||
@Param('driverId') driverId: string,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const result = await this.mediaService.getAvatar(driverId);
|
||||
if (result) {
|
||||
res.status(HttpStatus.OK).json(result);
|
||||
const presenter = await this.mediaService.getAvatar(driverId);
|
||||
const viewModel = presenter.viewModel;
|
||||
|
||||
if (viewModel) {
|
||||
res.status(HttpStatus.OK).json(viewModel);
|
||||
} else {
|
||||
res.status(HttpStatus.NOT_FOUND).json({ error: 'Avatar not found' });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Put('avatar/:driverId')
|
||||
@ApiOperation({ summary: 'Update avatar for driver' })
|
||||
@ApiParam({ name: 'driverId', description: 'Driver ID' })
|
||||
@@ -108,7 +118,9 @@ export class MediaController {
|
||||
@Body() input: UpdateAvatarInput,
|
||||
@Res() res: Response,
|
||||
): Promise<void> {
|
||||
const result = await this.mediaService.updateAvatar(driverId, input);
|
||||
res.status(HttpStatus.OK).json(result);
|
||||
const presenter = await this.mediaService.updateAvatar(driverId, input);
|
||||
const viewModel = presenter.viewModel;
|
||||
|
||||
res.status(HttpStatus.OK).json(viewModel);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user