Skip to content

Commit

Permalink
refactor: UsersController 반환 타입을 DTO로 변경하여 명시
Browse files Browse the repository at this point in the history
  • Loading branch information
coldrain-f committed Sep 21, 2022
1 parent 89a5de5 commit 734aa07
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/users/dto/find-user-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BossRaidHistory } from 'src/boss-raid-history/entities/boss-raid-history.entity';

export class FindUserResponseDTO {
totalScore: number;
bossRaidHistory: BossRaidHistory[];
}
3 changes: 3 additions & 0 deletions src/users/dto/signup-user-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class SignupUserResponseDTO {
userId: number;
}
13 changes: 4 additions & 9 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import { Controller, Get, Param, Post } from '@nestjs/common';
import { BossRaidHistory } from 'src/boss-raid-history/entities/boss-raid-history.entity';
import { FindUserResponseDTO } from './dto/find-user-response.dto';
import { SignupUserResponseDTO } from './dto/signup-user-response.dto';
import { User } from './entities/user.entity';
import { UsersService } from './users.service';

@Controller('user')
export class UsersController {
constructor(private readonly usersService: UsersService) {}

// @Todo: 반환 타입을 DTO로 변경하기

/**
* 유저 생성 API
* @returns 생성된 유저의 아이디 값(PK)
*/
@Post()
async signup(): Promise<{ userId: number }> {
async signup(): Promise<SignupUserResponseDTO> {
return await this.usersService.signup();
}

/**
* 유저 조회 API
* @param userId 조회하고자 하는 유저의 아이디 값(PK)
* @returns 조회한 사용자의 보스 레이드 총 점수와 보스 레이드 히스토리 목록
*/
@Get(':userId')
async findOne(
@Param('userId') userId: number,
): Promise<{ totalScore: number; bossRaidHistory: BossRaidHistory[] }> {
async findOne(@Param('userId') userId: number): Promise<FindUserResponseDTO> {
const user: User = await this.usersService.findOne(userId);
let totalScore = 0;

Expand Down

0 comments on commit 734aa07

Please sign in to comment.