Skip to content

Commit

Permalink
Merge pull request #72 from modern-agile-team/feature/friend
Browse files Browse the repository at this point in the history
Add(NicoDora/friends) : 영구거절한 친구 요청 불러오기 및 영구거절 취소 API 추가.
  • Loading branch information
NicoDora authored Oct 24, 2023
2 parents 292fe21 + a423a55 commit 7825f23
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/friends/controllers/friends.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ApiFriendResponseAccept } from '../swagger-decorators/friend-response-a
import { ApiFriendResponseReject } from '../swagger-decorators/friend-response-reject.decorator';
import { ApiDeleteFriend } from '../swagger-decorators/delete-friend.decorator';
import { ApiFriendResponseRejectPermanent } from '../swagger-decorators/friend-response-reject-permanent.decorator';
import { ApiGetRejectPermanent } from '../swagger-decorators/get-reject-permanent.decorator';
import { ApiDeleteRejectPermanentCancel } from '../swagger-decorators/delete-reject-permanent-cancel.decorator';

@Controller('friends')
@ApiTags('friends API')
Expand Down Expand Up @@ -40,6 +42,13 @@ export class FriendsController {
return await this.friendsService.getFriends(userId);
}

@ApiGetRejectPermanent()
@Get('responses/reject/permanent')
async getRejectPermanent(@Headers('access_token') accessToken: string) {
const userId = await this.tokenService.decodeToken(accessToken);
return await this.friendsService.getRejectPermanent(userId);
}

@ApiFriendRequest()
@Post('requests/:friend_id')
async friendRequest(@Headers('access_token') accessToken: string, @Param('friend_id') friendId: number) {
Expand All @@ -61,6 +70,13 @@ export class FriendsController {
return await this.friendsService.friendResponseReject(userId, friendId);
}

@ApiDeleteRejectPermanentCancel()
@Delete('responses/reject/permanent/:friend_id')
async friendResponseRejectPermanentCancel(@Headers('access_token') accessToken: string, @Param('friend_id') friendId: number) {
const userId = await this.tokenService.decodeToken(accessToken);
return await this.friendsService.friendResponseRejectPermanentCancel(userId, friendId);
}

@ApiFriendResponseRejectPermanent()
@Patch('responses/reject/permanent/:friend_id')
async friendResponseRejectPermanent(@Headers('access_token') accessToken: string, @Param('friend_id') friendId: number) {
Expand Down
25 changes: 25 additions & 0 deletions src/friends/repositories/friends.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export class FriendsRepository {
});
}

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

async friendRequest(userId: number, friendId: number): Promise<Friend> {
const friend = new Friend();
friend.requesterId = userId;
Expand Down Expand Up @@ -81,6 +90,22 @@ export class FriendsRepository {
return await this.entityManager.delete(Friend, friend);
}

async friendResponseRejectPermanentCancel(userId: number, friendId: number): Promise<DeleteResult> {
const friend = await this.entityManager.findOne(Friend, {
where: {
requesterId: friendId,
respondentId: userId,
status: Status.REJECT,
},
});

if (!friend) {
return null;
}

return await this.entityManager.delete(Friend, friend);
}

async friendResponseRejectPermanent(userId: number, friendId: number): Promise<Friend> {
const friend = await this.entityManager.findOne(Friend, {
where: {
Expand Down
20 changes: 20 additions & 0 deletions src/friends/services/friends.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export class FriendsService {
return await this.friendsRepository.getFriends(userId);
}

async getRejectPermanent(userId: number) {
return await this.friendsRepository.getRejectPermanent(userId);
}

async friendRequest(userId: number, friendId: number) {
try {
const checkRejectPermanent = await this.checkRejectPermanent(userId, friendId);
Expand Down Expand Up @@ -93,6 +97,22 @@ export class FriendsService {
}
}
}
async friendResponseRejectPermanentCancel(userId: number, friendId: number) {
try {
const rejectPermanentCancel = await this.friendsRepository.friendResponseRejectPermanentCancel(userId, friendId);
if (!rejectPermanentCancel) {
throw new HttpException('영구 거절한 친구 요청을 찾을 수 없습니다.', HttpStatus.NOT_FOUND);
}
return { message: '친구 요청 영구 거절을 취소했습니다.' };
} catch (error) {
if (error.getStatus() === HttpStatus.NOT_FOUND) {
throw error;
} else {
console.log(error);
throw new HttpException('친구 요청 영구 거절 취소에 실패했습니다.', HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

async friendResponseRejectPermanent(userId: number, friendId: number) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { applyDecorators } from "@nestjs/common";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";

export function ApiDeleteRejectPermanentCancel() {
return applyDecorators(
ApiOperation({
summary: '친구 요청 영구 거절 취소 API',
description: '친구 요청 영구 거절을 취소합니다.',
}),
ApiResponse({
status: 200,
description: '성공적으로 친구 요청 영구 거절을 취소한 경우',
content: {
JSON: { example: { message: '친구 요청 영구 거절을 취소했습니다.' } },
},
}),
ApiResponse({
status: 401,
description: '우리 서비스의 액세스 토큰이 아닌 경우',
content: {
JSON: {
example: { statusCode: 401, message: '유효하지 않은 토큰입니다.' },
},
},
}),
ApiResponse({
status: 403,
description: '만료된 액세스 토큰인 경우',
content: {
JSON: {
example: { statusCode: 403, message: '만료된 토큰입니다.' },
},
},
}),
ApiResponse({
status: 404,
description: '영구 거절한 친구 요청을 찾을 수 없는 경우',
content: {
JSON: {
example: { statusCode: 404, message: '영구 거절한 친구 요청을 찾을 수 없습니다.' },
},
},
}),
ApiResponse({
status: 411,
description: '액세스 토큰이 제공되지 않은 경우',
content: {
JSON: {
example: { statusCode: 411, message: '토큰이 제공되지 않았습니다.' },
},
},
}),
ApiResponse({
status: 500,
description: '친구 요청 영구 거절 취소에 실패한 경우',
content: {
JSON: {
example: { statusCode: 500, message: '친구 요청 영구 거절 취소에 실패했습니다.' },
},
},
}),
);
}
76 changes: 76 additions & 0 deletions src/friends/swagger-decorators/get-reject-permanent.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { applyDecorators } from "@nestjs/common";
import { ApiOperation, ApiResponse } from "@nestjs/swagger";

export function ApiGetRejectPermanent() {
return applyDecorators(
ApiOperation({
summary: '내가 영구적으로 친구 요청을 거절한 목록 조회 API',
description: '내가 영구적으로 친구 요청을 거절한 목록을 조회합니다.',
}),
ApiResponse({
status: 200,
description:
'성공적으로 영구적으로 친구 요청을 거절한 목록을 조회한 경우 (배열 형태) , 영구적으로 친구 요청을 거절한 목록이 없는 경우 빈 배열을 반환합니다.',
content: {
Array: {
example: [
{
id: 1,
requesterId: 1,
respondentId: 63,
status: '친구 거절',
},
{
id: 2,
requesterId: 2,
respondentId: 63,
status: '친구 거절',
},
{
id: 3,
requesterId: 3,
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: '토큰이 제공되지 않았습니다.' },
},
},
}),
);
}

0 comments on commit 7825f23

Please sign in to comment.