From 91a901bb53e29bde157f18c33526980bc247efcd Mon Sep 17 00:00:00 2001 From: NicoDora Date: Fri, 20 Oct 2023 16:48:36 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat(#40):=20=EC=B9=9C=EA=B5=AC=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=A4=EA=B8=B0=20API=20=EB=AA=85=EC=84=B8=EC=84=9C?= =?UTF-8?q?=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get-friends.docorator.ts | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/friends/swagger-decorators/get-friends.docorator.ts b/src/friends/swagger-decorators/get-friends.docorator.ts index 5203ed6..ae46a98 100644 --- a/src/friends/swagger-decorators/get-friends.docorator.ts +++ b/src/friends/swagger-decorators/get-friends.docorator.ts @@ -1,5 +1,5 @@ import { applyDecorators } from '@nestjs/common'; -import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import { ApiHeaders, ApiOperation, ApiResponse } from '@nestjs/swagger'; export function ApiGetFriends() { return applyDecorators( @@ -36,5 +36,49 @@ export function ApiGetFriends() { }, }, }), + ApiResponse({ + status: 401, + description: '우리 서비스의 액세스 토큰이 아닌 경우', + content: { + JSON: { + example: { statusCode: 401, message: '유효하지 않은 토큰입니다.' }, + }, + }, + }), + ApiResponse({ + status: 403, + description: '만료된 액세스 토큰인 경우', + content: { + JSON: { + example: { statusCode: 403, message: '만료된 토큰입니다.' }, + }, + }, + }), + ApiResponse({ + status: 404, + description: 'DB에서 사용자를 찾을 수 없는 경우', + content: { + JSON: { + example: { statusCode: 404, message: '사용자를 찾을 수 없습니다.' }, + }, + }, + }), + ApiResponse({ + status: 411, + description: '액세스 토큰이 제공되지 않은 경우', + content: { + JSON: { + example: { statusCode: 411, message: '토큰이 제공되지 않았습니다.' }, + }, + }, + }), + ApiHeaders([ + { + name: 'access_token', + description: '액세스 토큰', + required: true, + example: '여기에 액세스 토큰', + }, + ]), ); } From 8f6f4e3edc634617886455e5924098aaf1d035b3 Mon Sep 17 00:00:00 2001 From: NicoDora Date: Fri, 20 Oct 2023 17:43:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat(#40):=20=EB=82=B4=EA=B0=80=20=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=B9=9C=EA=B5=AC=20=EC=9A=94=EC=B2=AD=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API=20=EB=B0=8F=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/friends/controllers/friends.controller.ts | 8 ++ .../repositories/friends.repository.ts | 11 ++- src/friends/services/friends.service.ts | 4 + .../get-friends-req-pending.decorator.ts | 2 +- .../get-friends-res-pending.decorator.ts | 78 +++++++++++++++++++ .../controllers/user-image.controller.ts | 2 +- 6 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/friends/swagger-decorators/get-friends-res-pending.decorator.ts diff --git a/src/friends/controllers/friends.controller.ts b/src/friends/controllers/friends.controller.ts index b52cd3d..dfcf076 100644 --- a/src/friends/controllers/friends.controller.ts +++ b/src/friends/controllers/friends.controller.ts @@ -5,6 +5,7 @@ import { ApiGetFriendsReqPending } from '../swagger-decorators/get-friends-req-p import { ApiTags } from '@nestjs/swagger'; import { ApiFriendRequest } from '../swagger-decorators/friend-request.docorator'; import { ApiGetFriends } from '../swagger-decorators/get-friends.docorator'; +import { ApiGetFriendsResPending } from '../swagger-decorators/get-friends-res-pending.decorator'; @Controller('friends') @ApiTags('friends API') @@ -21,6 +22,13 @@ export class FriendsController { return await this.friendsService.getFriendsReqPending(userId); } + @ApiGetFriendsResPending() + @Get('responses/pending') + async getFriendsResPending(@Headers('access_token') accessToken: string) { + const userId = await this.tokenService.decodeToken(accessToken); + return await this.friendsService.getFriendsResPending(userId); + } + @ApiGetFriends() @Get() async getFriends(@Headers('access_token') accessToken: string) { diff --git a/src/friends/repositories/friends.repository.ts b/src/friends/repositories/friends.repository.ts index a604cdb..33f07e7 100644 --- a/src/friends/repositories/friends.repository.ts +++ b/src/friends/repositories/friends.repository.ts @@ -15,6 +15,15 @@ export class FriendsRepository { }); } + async getFriendsResPending(userId: number): Promise { + return await this.entityManager.find(Friend, { + where: { + respondentId: userId, + status: Status.PENDING, + }, + }); + } + async getFriends(userId: number): Promise { return await this.entityManager.find(Friend, { where: [ @@ -29,7 +38,7 @@ export class FriendsRepository { ], }); } - + async friendRequest(userId: number, friendId: number): Promise { const friend = new Friend(); friend.requesterId = userId; diff --git a/src/friends/services/friends.service.ts b/src/friends/services/friends.service.ts index 9e9ae79..63781fe 100644 --- a/src/friends/services/friends.service.ts +++ b/src/friends/services/friends.service.ts @@ -10,6 +10,10 @@ export class FriendsService { return await this.friendsRepository.getFriendsReqPending(userId); } + async getFriendsResPending(userId: number) { + return await this.friendsRepository.getFriendsResPending(userId); + } + async getFriends(userId: number) { return await this.friendsRepository.getFriends(userId); } diff --git a/src/friends/swagger-decorators/get-friends-req-pending.decorator.ts b/src/friends/swagger-decorators/get-friends-req-pending.decorator.ts index d149550..3ab6637 100644 --- a/src/friends/swagger-decorators/get-friends-req-pending.decorator.ts +++ b/src/friends/swagger-decorators/get-friends-req-pending.decorator.ts @@ -4,7 +4,7 @@ import { ApiHeaders, ApiOperation, ApiResponse } from '@nestjs/swagger'; export function ApiGetFriendsReqPending() { return applyDecorators( ApiOperation({ - summary: '친구 요청 목록 조회 API', + summary: '내가 보낸 친구 요청 목록 조회 API', description: '내가 보낸 친구 요청 목록을 조회합니다.', }), ApiResponse({ diff --git a/src/friends/swagger-decorators/get-friends-res-pending.decorator.ts b/src/friends/swagger-decorators/get-friends-res-pending.decorator.ts new file mode 100644 index 0000000..cff3212 --- /dev/null +++ b/src/friends/swagger-decorators/get-friends-res-pending.decorator.ts @@ -0,0 +1,78 @@ +import { applyDecorators } from "@nestjs/common"; +import { ApiHeaders, ApiOperation, ApiResponse } from "@nestjs/swagger"; + +export function ApiGetFriendsResPending() { + return applyDecorators( + ApiOperation({ + summary: '내가 받은 친구 요청 목록 조회 API', + description: '내가 받은 친구 요청 목록을 조회합니다.', + }), + ApiResponse({ + status: 200, + description: + '성공적으로 친구 요청 목록을 조회한 경우 (배열 형태) , 내가 받은 친구 요청이 없는 경우 빈 배열을 반환합니다.', + content: { + Array: { + example: [ + { + id: 2, + requesterId: 62, + respondentId: 63, + status: '대기 상태', + }, + { + id: 5, + requesterId: 64, + respondentId: 63, + status: '대기 상태', + }, + ], + }, + }, + }), + ApiResponse({ + status: 401, + description: '우리 서비스의 액세스 토큰이 아닌 경우', + content: { + JSON: { + example: { statusCode: 401, message: '유효하지 않은 토큰입니다.' }, + }, + }, + }), + ApiResponse({ + status: 403, + description: '만료된 액세스 토큰인 경우', + content: { + JSON: { + example: { statusCode: 403, message: '만료된 토큰입니다.' }, + }, + }, + }), + ApiResponse({ + status: 404, + description: 'DB에서 사용자를 찾을 수 없는 경우', + content: { + JSON: { + example: { statusCode: 404, message: '사용자를 찾을 수 없습니다.' }, + }, + }, + }), + ApiResponse({ + status: 411, + description: '액세스 토큰이 제공되지 않은 경우', + content: { + JSON: { + example: { statusCode: 411, message: '토큰이 제공되지 않았습니다.' }, + }, + }, + }), + ApiHeaders([ + { + name: 'access_token', + description: '액세스 토큰', + required: true, + example: '여기에 액세스 토큰', + }, + ]), + ); +} \ No newline at end of file diff --git a/src/users/controllers/user-image.controller.ts b/src/users/controllers/user-image.controller.ts index 6e6a344..4df1209 100644 --- a/src/users/controllers/user-image.controller.ts +++ b/src/users/controllers/user-image.controller.ts @@ -2,7 +2,7 @@ import { TokenService } from './../../auth/services/token.service'; import { Controller, Headers, Patch, UploadedFile, UseInterceptors } from '@nestjs/common'; import { FileInterceptor } from '@nestjs/platform-express'; import { UserImageService } from '../services/user-image.service'; -import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { ApiTags } from '@nestjs/swagger'; import { ApiUploadUserImage } from '../swagger-decorators/upload-user-image.decorator'; @Controller('user/image')