From 34088c5bc20ec537fecadbdb47a296c45e2064db Mon Sep 17 00:00:00 2001 From: Yeongbin Im <56269396+yeongbinim@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:19:26 +0900 Subject: [PATCH] =?UTF-8?q?[BE#494]=20=ED=8C=94=EB=A1=9C=EC=9B=8C=EB=93=A4?= =?UTF-8?q?=20=EC=B0=A8=EB=8B=A8=ED=95=98=EA=B8=B0=20(#495)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 차단/ 차단 해제 API 생성 - fixation과 동일한 로직으로 작성 * refactor: blocking controller 변수 follower_id로 변경 * feat: 팔로워 조회시 차단된 유저 제외 - where문에 "AND mates.is_blocked = false"추가 * feat: 차단한 사람들 조회 - 기존 getFollowersInfo에서true false 만 변경 * refactor: swagger 변수 변경 --- BE/src/mates/mates.controller.ts | 45 +++++++++++++++++++++++++++++++- BE/src/mates/mates.entity.ts | 3 +++ BE/src/mates/mates.service.ts | 33 +++++++++++++++++++++-- BE/src/users/users.service.ts | 2 +- 4 files changed, 79 insertions(+), 4 deletions(-) diff --git a/BE/src/mates/mates.controller.ts b/BE/src/mates/mates.controller.ts index 80c13ed..f895f83 100644 --- a/BE/src/mates/mates.controller.ts +++ b/BE/src/mates/mates.controller.ts @@ -184,7 +184,7 @@ export class MatesController { description: '친구의 id', example: '1', }, - fixation: { + is_fixed: { type: 'boolean', description: '고정/고정 해제 여부', example: 'true', @@ -204,4 +204,47 @@ export class MatesController { message: '수정 완료', }; } + + @Patch('blocking') + @UseGuards(AccessTokenGuard) + @ApiBearerAuth() + @ApiOperation({ + summary: '팔로워 목록에서 차단/차단 해제(나를 팔로우하고 있는 사람만 가능)', + }) + @ApiBody({ + schema: { + properties: { + follower_id: { + type: 'number', + description: '친구의 id', + example: '1', + }, + is_blocked: { + type: 'boolean', + description: '차단/차단 해제 여부', + example: 'true', + }, + }, + }, + }) + async blockMate( + @User('id') id: number, + @Body('follower_id') follower_id: number, + @Body('is_blocked') is_blocked: boolean, + ): Promise { + await this.matesService.blockMate(id, follower_id, is_blocked); + + return { + statusCode: 200, + message: '수정 완료', + }; + } + + @Get('/blockings') + @UseGuards(AccessTokenGuard) + @ApiBearerAuth() + @ApiOperation({ summary: '내가 차단한 사람들 조회하기' }) + getBlockedMate(@User('id') user_id: number): Promise { + return this.matesService.getBlockedFollowersInfo(user_id); + } } diff --git a/BE/src/mates/mates.entity.ts b/BE/src/mates/mates.entity.ts index 2a327aa..98a11f7 100644 --- a/BE/src/mates/mates.entity.ts +++ b/BE/src/mates/mates.entity.ts @@ -28,4 +28,7 @@ export class Mates { @Column({ type: 'boolean', default: false }) is_fixed: boolean; + + @Column({ type: 'boolean', default: false }) + is_blocked: boolean; } diff --git a/BE/src/mates/mates.service.ts b/BE/src/mates/mates.service.ts index a342067..6c212d3 100644 --- a/BE/src/mates/mates.service.ts +++ b/BE/src/mates/mates.service.ts @@ -65,7 +65,18 @@ export class MatesService { `SELECT u.id, u.nickname, u.image_url FROM mates INNER JOIN users_model as u ON u.id = mates.follower_id - WHERE mates.following_id = ? + WHERE mates.following_id = ? AND mates.is_blocked = false + ORDER BY u.nickname`, + [user_id], + ); + } + + getBlockedFollowersInfo(user_id: number) { + return this.matesRepository.query( + `SELECT u.id, u.nickname, u.image_url + FROM mates + INNER JOIN users_model as u ON u.id = mates.follower_id + WHERE mates.following_id = ? AND mates.is_blocked = true ORDER BY u.nickname`, [user_id], ); @@ -245,7 +256,7 @@ export class MatesService { } async fixationMate( - id, + id: number, following_id: number, is_fixed: boolean, ): Promise { @@ -262,6 +273,24 @@ export class MatesService { } } + async blockMate( + id: number, + follower_id: number, + is_blocked: boolean, + ): Promise { + const result = await this.matesRepository.update( + { + follower_id: { id: follower_id }, + following_id: { id: id }, + }, + { is_blocked: is_blocked }, + ); + + if (!result) { + throw new NotFoundException('해당 친구 관계는 존재하지 않습니다.'); + } + } + entityToDto(mate: Mates): MatesDto { const { id, follower_id, following_id } = mate; const mateDto = { diff --git a/BE/src/users/users.service.ts b/BE/src/users/users.service.ts index d55cf6d..19e8240 100644 --- a/BE/src/users/users.service.ts +++ b/BE/src/users/users.service.ts @@ -22,7 +22,7 @@ export class UsersService { async getFollowsCount(user_id: number) { const [followsCount] = await this.usersRepository.query( `SELECT - (SELECT COUNT(*) FROM mates WHERE following_id = ?) AS follower_count, + (SELECT COUNT(*) FROM mates WHERE following_id = ? AND is_blocked = false) AS follower_count, (SELECT COUNT(*) FROM mates WHERE follower_id = ?) AS following_count`, [user_id, user_id], );