From 7cc9ac0eb88486913522e9655b0039d923cbf1b6 Mon Sep 17 00:00:00 2001 From: ChoiYongWon Date: Sat, 10 Dec 2022 14:52:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#47=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EB=B3=84=EB=A1=9C=20=EC=9A=B0=EC=97=B0=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/posting/posting.controller.ts | 18 ++++++++++-------- src/posting/posting.service.ts | 8 ++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/posting/posting.controller.ts b/src/posting/posting.controller.ts index 3f55e20..f325cc5 100644 --- a/src/posting/posting.controller.ts +++ b/src/posting/posting.controller.ts @@ -141,9 +141,9 @@ export class PostingController { isArray: true, }) @Roles([Role.User]) - async getAllPost(@Req() req) { + async getAllPost(@Req() req, @Query('page') page: number) { const user_id = req.user.user_id; - return await this.postingService.getAllPost(user_id).catch((err) => { + return await this.postingService.getAllPost(user_id, page).catch((err) => { throw new InternalServerErrorException({ statusCode: HttpStatus.INTERNAL_SERVER_ERROR, message: err.message, @@ -161,14 +161,16 @@ export class PostingController { isArray: true, }) @Roles([Role.User]) - async getViewedPost(@Req() req) { + async getViewedPost(@Req() req, @Query('page') page: number) { const user_id = req.user.user_id; - return await this.postingService.getViewedPost(user_id).catch((err) => { - throw new InternalServerErrorException({ - statusCode: HttpStatus.INTERNAL_SERVER_ERROR, - message: err.message, + return await this.postingService + .getViewedPost(user_id, page) + .catch((err) => { + throw new InternalServerErrorException({ + statusCode: HttpStatus.INTERNAL_SERVER_ERROR, + message: err.message, + }); }); - }); } @Get('/near') diff --git a/src/posting/posting.service.ts b/src/posting/posting.service.ts index bd37990..1d2336e 100644 --- a/src/posting/posting.service.ts +++ b/src/posting/posting.service.ts @@ -120,7 +120,7 @@ forFriend = 0 인 게시물 중에 return result; } - async getViewedPost(user_id: string) { + async getViewedPost(user_id: string, page: number) { let query = await this.postingRepository .createQueryBuilder('post') .leftJoin('post.footprint', 'footprint') @@ -128,6 +128,8 @@ forFriend = 0 인 게시물 중에 .select('post.post_id') .addSelect('image.img_url') .where('footprint.user_id = :user_id', { user_id }) + .take(15) + .skip(15 * page) .getMany(); const result = []; @@ -245,7 +247,7 @@ forFriend = 0 인 게시물 중에 return { ...result, emotion: { ...emotion }, distance, owner }; } - async getAllPost(user_id: string) { + async getAllPost(user_id: string, page: number) { let query = await this.postingRepository .createQueryBuilder('post') .leftJoinAndSelect('post.user_id', 'user') @@ -253,6 +255,8 @@ forFriend = 0 인 게시물 중에 .select('post.post_id') .addSelect('image.img_url') .where('user.user_id = :user_id', { user_id }) + .take(15) + .skip(15 * page) .getMany(); // 대표사진만