From 3ba12e9b5007ce498a257c718de7bd7ceb19a2b8 Mon Sep 17 00:00:00 2001 From: seokyung Date: Fri, 23 Feb 2024 13:52:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20/users=20delete=20API=20auth=20-?= =?UTF-8?q?>=20user=EB=A1=9C=20=EC=98=AE=EA=B9=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 사용자를 삭제하는 API는 용도가 user 모듈가 더 가까워 옮김 --- server/nest/src/auth/auth.controller.ts | 8 -------- server/nest/src/auth/auth.service.ts | 18 ------------------ server/nest/src/user/user.controller.ts | 9 +++++++++ server/nest/src/user/user.service.ts | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/server/nest/src/auth/auth.controller.ts b/server/nest/src/auth/auth.controller.ts index 76d01a1..6bb44fa 100644 --- a/server/nest/src/auth/auth.controller.ts +++ b/server/nest/src/auth/auth.controller.ts @@ -60,12 +60,4 @@ export class AuthController { ); return { userId: user.user_id }; } - - @Delete() - @UseGuards(AuthGuard()) - @HttpCode(HTTP_STATUS_CODE.SUCCESS) - async deleteUser(@ReqUser() user: User): Promise<{ userId: string }> { - this.logger.log(`DELETE /users - nickname=${user.nickname}`); - return await this.authService.deleteUser(user); - } } diff --git a/server/nest/src/auth/auth.service.ts b/server/nest/src/auth/auth.service.ts index a3a2728..a9f548b 100644 --- a/server/nest/src/auth/auth.service.ts +++ b/server/nest/src/auth/auth.service.ts @@ -195,22 +195,4 @@ export class AuthService { return true; } - - async deleteUser(user: User): Promise<{ userId: string }> { - try { - await this.userRepository.deleteUser(user.user_id); - - return { userId: user.user_id }; - } catch (err) { - if (err instanceof CatchyException) { - throw err; - } - - throw new CatchyException( - 'SERVICE_ERROR', - HTTP_STATUS_CODE.SERVER_ERROR, - ERROR_CODE.SERVICE_ERROR, - ); - } - } } diff --git a/server/nest/src/user/user.controller.ts b/server/nest/src/user/user.controller.ts index e8f02b8..7a6124a 100644 --- a/server/nest/src/user/user.controller.ts +++ b/server/nest/src/user/user.controller.ts @@ -12,6 +12,7 @@ import { Logger, Put, ValidationPipe, + Delete, } from '@nestjs/common'; import { UserService } from './user.service'; import { HTTP_STATUS_CODE } from 'src/codes/httpStatusCode.enum'; @@ -48,6 +49,14 @@ export class UserController { }; } + @Delete() + @UseGuards(AuthGuard()) + @HttpCode(HTTP_STATUS_CODE.SUCCESS) + async deleteUser(@ReqUser() user: User): Promise<{ userId: string }> { + this.logger.log(`DELETE /users - nickname=${user.nickname}`); + return await this.userService.deleteUser(user); + } + @Get('duplicate/:name') @HttpCode(HTTP_STATUS_CODE.NOT_DUPLICATED_NICKNAME) async checkDuplicateNickname( diff --git a/server/nest/src/user/user.service.ts b/server/nest/src/user/user.service.ts index d6c13e0..5105eb1 100644 --- a/server/nest/src/user/user.service.ts +++ b/server/nest/src/user/user.service.ts @@ -41,6 +41,24 @@ export class UserService { } } + async deleteUser(user: User): Promise<{ userId: string }> { + try { + await this.userRepository.deleteUser(user.user_id); + + return { userId: user.user_id }; + } catch (err) { + if (err instanceof CatchyException) { + throw err; + } + + throw new CatchyException( + 'SERVICE_ERROR', + HTTP_STATUS_CODE.SERVER_ERROR, + ERROR_CODE.SERVICE_ERROR, + ); + } + } + async getRecentPlayedMusicByUserId( userId: string, count: number,