Skip to content

Commit

Permalink
Merge pull request #59 from modern-agile-team/feature/friend
Browse files Browse the repository at this point in the history
Add(NicoDora/friend) : 내가 받은 친구 요청 조회 API 추가
  • Loading branch information
NicoDora authored Oct 23, 2023
2 parents 34dfeb9 + 8f6f4e3 commit 22bcf7f
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/friends/controllers/friends.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion src/friends/repositories/friends.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ export class FriendsRepository {
});
}

async getFriendsResPending(userId: number): Promise<Friend[]> {
return await this.entityManager.find(Friend, {
where: {
respondentId: userId,
status: Status.PENDING,
},
});
}

async getFriends(userId: number): Promise<Friend[]> {
return await this.entityManager.find(Friend, {
where: [
Expand All @@ -29,7 +38,7 @@ export class FriendsRepository {
],
});
}

async friendRequest(userId: number, friendId: number): Promise<Friend> {
const friend = new Friend();
friend.requesterId = userId;
Expand Down
4 changes: 4 additions & 0 deletions src/friends/services/friends.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiHeaders, ApiOperation, ApiResponse } from '@nestjs/swagger';
export function ApiGetFriendsReqPending() {
return applyDecorators(
ApiOperation({
summary: '친구 요청 목록 조회 API',
summary: '내가 보낸 친구 요청 목록 조회 API',
description: '내가 보낸 친구 요청 목록을 조회합니다.',
}),
ApiResponse({
Expand Down
Original file line number Diff line number Diff line change
@@ -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: '여기에 액세스 토큰',
},
]),
);
}
46 changes: 45 additions & 1 deletion src/friends/swagger-decorators/get-friends.docorator.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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: '여기에 액세스 토큰',
},
]),
);
}
2 changes: 1 addition & 1 deletion src/users/controllers/user-image.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 22bcf7f

Please sign in to comment.