diff --git a/backend/src/modules/post/post.controller.ts b/backend/src/modules/post/post.controller.ts index 0bea36c..29b33f5 100644 --- a/backend/src/modules/post/post.controller.ts +++ b/backend/src/modules/post/post.controller.ts @@ -26,4 +26,10 @@ export class PostController { async getPost(@Param('postId') postId: string) { return await this.postService.getPost(postId); } + + @ApiOperation({ description: 'Getting a post by its media group id' }) + @Get('get-by-media-group-id/:mediaGroupId') + async getByMediaGroup(@Param('mediaGroupId') mediaGroupId: string) { + return await this.postService.getByMediaGroup(mediaGroupId); + } } diff --git a/backend/src/modules/post/post.service.ts b/backend/src/modules/post/post.service.ts index 4f4310a..26f95ec 100644 --- a/backend/src/modules/post/post.service.ts +++ b/backend/src/modules/post/post.service.ts @@ -61,4 +61,14 @@ export class PostService { throw new HttpException('No post with this id', HttpStatus.NOT_FOUND); } } + + async getByMediaGroup(mediaGroupId: string) { + try { + this.logger.log(`[post.getByMediaGroup] data: ${mediaGroupId}`); + return await this.postRepository.findOne({ where: { media_group_id: mediaGroupId } }); + } catch (error) { + this.logger.debug(`[post.getByMediaGroup] error: ${JSON.stringify(error)}`); + throw new HttpException("Can't find post with this media group id", HttpStatus.BAD_REQUEST); + } + } }