Skip to content

Commit

Permalink
refactor : /users delete API auth -> user로 옮김
Browse files Browse the repository at this point in the history
* 사용자를 삭제하는 API는 용도가 user 모듈가 더 가까워 옮김
  • Loading branch information
sk000801 committed Feb 23, 2024
1 parent c935cb6 commit 3ba12e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
8 changes: 0 additions & 8 deletions server/nest/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 0 additions & 18 deletions server/nest/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}
}
9 changes: 9 additions & 0 deletions server/nest/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 18 additions & 0 deletions server/nest/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3ba12e9

Please sign in to comment.