Skip to content

Commit

Permalink
Refactor: remove appController, edit api-docs (#35)
Browse files Browse the repository at this point in the history
* Refactor: remove appController, edit api-docs

- 앱 컨트롤러 삭제
    - 본인 조회는 user controller로 이관
- 스웨거를 위한 태그 추가
- User엔티티를, UserResponseDto로 변환하는 함수 추가

* chore

chore
  • Loading branch information
sally0226 authored Jul 6, 2024
1 parent 3535f5d commit a0eaad9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 74 deletions.
23 changes: 0 additions & 23 deletions src/app.controller.spec.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/app.controller.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { MikroOrmModule } from '@mikro-orm/nestjs';
import { LoggerMiddleware } from 'src/core/intercepters/logging.interceptor';
import { InviteLinkModule } from 'src/invite-link/invite-link.module';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { getNodeEnv, isIgnoreEnvFile } from './common/helper/env.helper';
import { envValidation } from './common/helper/env.validation';
Expand Down Expand Up @@ -39,8 +37,8 @@ import { UtilModule } from './util/util.module';
PlaceModule,
InviteLinkModule,
],
controllers: [AppController],
providers: [AppService],
controllers: [],
providers: [],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
Expand Down
8 changes: 0 additions & 8 deletions src/app.service.ts

This file was deleted.

9 changes: 6 additions & 3 deletions src/map/map.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
BadRequestException,
Body,
Controller,
Delete,
Get,
Param,
Patch,
Expand Down Expand Up @@ -38,7 +37,7 @@ export class MapController {

@Post()
@ApiOkResponse({ type: MapItemForUserDto })
@ApiOperation({ summary: '새 지도를 생성합니다' })
@ApiOperation({ summary: '새 지도를 생성합니다.' })
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
create(@Body() createMapDto: CreateMapDto, @CurrentUser() user: User) {
Expand All @@ -53,7 +52,7 @@ export class MapController {
}

@Get()
@ApiOperation({ summary: '사용자가 속해있는 지도를 가져옵니다' })
@ApiOperation({ summary: '사용자가 속해있는 지도를 가져옵니다.' })
@ApiOkResponse({ type: [MapItemForUserDto] })
@ApiBearerAuth()
@UseAuthGuard([UserRole.USER])
Expand Down Expand Up @@ -90,6 +89,10 @@ export class MapController {
// }

@Post(':id/invite-links')
@ApiOperation({
summary: '지도의 초대링크를 생성합니다.',
description: '유효기간은 7일로 설정되어 있습니다.',
})
@ApiResponse({ type: InviteLinkResponseDto })
@ApiBearerAuth()
@UseMapRoleGuard([UserMapRole.ADMIN])
Expand Down
11 changes: 11 additions & 0 deletions src/user/dtos/user-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ export class UserResponseDto implements Partial<Omit<User, 'userMap'>> {
@IsNotEmpty()
role: UserRoleValueType;
}

export function toUserResponseDto(user: User): UserResponseDto {
const userResponse = new UserResponseDto();
userResponse.id = user.id;
userResponse.nickname = user.nickname;
userResponse.provider = user.provider;
userResponse.providerId = user.providerId;
userResponse.role = user.role;

return userResponse;
}
39 changes: 29 additions & 10 deletions src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,68 @@ import {
Patch,
Query,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiExcludeEndpoint,
ApiOkResponse,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';

import { UseAuthGuard } from 'src/common/decorators/auth-guard.decorator';
import { CurrentUser } from 'src/common/decorators/user.decorator';
import { User, UserRole } from 'src/entities';

import { UpdateUserRequestDto } from './dtos/update-user.dto';
import { UserResponseDto } from './dtos/user-response.dto';
import { UserResponseDto, toUserResponseDto } from './dtos/user-response.dto';
import { UserService } from './user.service';

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

@Get(':id')
@Get('me')
@ApiOperation({ summary: '내 정보를 조회합니다.' })
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async findOne(@Param('id') id: string) {
const user = await this.userService.findOne({ id: +id });
return user;
getMe(@CurrentUser() user: User): UserResponseDto {
return toUserResponseDto(user);
}

@Patch()
@Patch('me')
@ApiOperation({ summary: '내 정보를 수정합니다.' })
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async update(
async updateMe(
@Body() updateUserDto: UpdateUserRequestDto,
@CurrentUser() user: User,
) {
return await this.userService.update(+user.id, updateUserDto);
): Promise<UserResponseDto> {
const updatedUser = await this.userService.update(user.id, user);
return toUserResponseDto(updatedUser);
}

@Get(':id')
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async findOne(@Param('id') id: string): Promise<UserResponseDto> {
const user = await this.userService.findOne({ id: +id });
return toUserResponseDto(user);
}

@Delete(':id')
@ApiOkResponse({ type: Number })
@ApiBearerAuth()
@ApiExcludeEndpoint()
async remove(@Param('id') id: string) {
return this.userService.remove(+id);
}

@Get('check/nickname')
@ApiOperation({ summary: '닉네임 중복체크합니다.' })
@ApiOkResponse({})
async checkDuplicateNickname(@Query('nickname') nickname: string) {
return this.userService.checkDuplicateNickname(nickname);
Expand Down

0 comments on commit a0eaad9

Please sign in to comment.