Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

유저 정보 조회 api #160

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

110 changes: 0 additions & 110 deletions backend/resources/scripts/[email protected]/setup-elk.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseException } from '../../common/exception/BaseException';
import { BaseException } from '@src/common/exception/BaseException';
import { HttpStatus } from '@nestjs/common';

export class CoursePermissionException extends BaseException {
Expand Down
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,
});
}
}
10 changes: 9 additions & 1 deletion backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Controller } from '@nestjs/common';
import { Controller, Get, UseGuards } from '@nestjs/common';
import { UserService } from './user.service';
import { JwtAuthGuard } from '@src/auth/JwtAuthGuard';
import { AuthUser } from '@src/auth/AuthUser.decorator';

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

@Get('/info')
@UseGuards(JwtAuthGuard)
async getUserInfo(@AuthUser() user: AuthUser) {
return await this.userService.getUserInfo(user.userId);
}
}
10 changes: 10 additions & 0 deletions backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 @@ -22,4 +24,12 @@ export class UserService {
const newUser = await this.userRepository.save(user);
return { userId: newUser.id, role: newUser.role };
}

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