Skip to content

Commit

Permalink
fix: 본인 정보 조회에는 id값을 입력 받지 않도록 수정 #158
Browse files Browse the repository at this point in the history
  • Loading branch information
koomchang committed Nov 20, 2024
1 parent 7ec0da8 commit 662cbda
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
11 changes: 11 additions & 0 deletions backend/src/user/exception/UserNotFoundException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BaseException } from '@src/common/exception/BaseException';

export class UserNotFoundException extends BaseException {
constructor(id: number) {
super({
code: 2001,
message: `id:${id} 사용자를 찾을 수 없습니다.`,
status: 404,
});
}
}
11 changes: 0 additions & 11 deletions backend/src/user/exception/UserPermissionException.ts

This file was deleted.

20 changes: 0 additions & 20 deletions backend/src/user/guards/UserPermissionGuard.ts

This file was deleted.

12 changes: 6 additions & 6 deletions backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { Controller, Get, UseGuards } from '@nestjs/common';
import { UserService } from './user.service';
import { JwtAuthGuard } from '@src/auth/JwtAuthGuard';
import { UserPermissionGuard } from '@src/user/guards/UserPermissionGuard';
import { AuthUser } from '@src/auth/AuthUser.decorator';

@Controller('users')
export class UserController {
constructor(private readonly userService: UserService) {}

@Get('/:id')
@UseGuards(JwtAuthGuard, UserPermissionGuard)
async getUserInfo(@Param('id') id: number) {
return await this.userService.getUserInfo(id);
@Get('/info')
@UseGuards(JwtAuthGuard)
async getUserInfo(@AuthUser() user: AuthUser) {
return await this.userService.getUserInfo(user.userId);
}
}
4 changes: 4 additions & 0 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { UserRepository } from './user.repository';
import { CreateUserRequest } from './dto/CreateUserRequest';
import { UserIconResponse } from '@src/user/dto/UserIconResponse';
import { UserNotFoundException } from '@src/user/exception/UserNotFoundException';

@Injectable()
export class UserService {
Expand All @@ -26,6 +27,9 @@ export class UserService {

async getUserInfo(userId: number) {
const user = await this.userRepository.findById(userId);
if (!user) {
throw new UserNotFoundException(userId);
}
return UserIconResponse.from(user);
}
}

0 comments on commit 662cbda

Please sign in to comment.