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

Chore: Set swagger authorization header #32

Merged
merged 1 commit into from
Jul 4, 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
2 changes: 2 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, Get, InternalServerErrorException } from '@nestjs/common';
import { ApiBearerAuth } from '@nestjs/swagger';

import { AppService } from './app.service';
import { UseAuthGuard } from './common/decorators/auth-guard.decorator';
Expand All @@ -18,6 +19,7 @@ export class AppController {

@Get('/me')
@UseAuthGuard([UserRole.USER])
@ApiBearerAuth()
getMe(@CurrentUser() user: User): User {
return user;
}
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async function bootstrap() {
const config = new DocumentBuilder()
.setTitle('Korrk API')
.setDescription('Mashup의 VitaminC팀 API 서버입니다')
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);
Expand Down
10 changes: 9 additions & 1 deletion src/map/map.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
Patch,
Post,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiOkResponse,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';

import { UseAuthGuard } from '../common/decorators/auth-guard.decorator';
import { CurrentUser } from '../common/decorators/user.decorator';
Expand Down Expand Up @@ -49,19 +54,22 @@ export class MapController {

@Get(':id')
@ApiOkResponse({ type: MapResponseDto })
@ApiBearerAuth()
findOne(@Param('id') id: string) {
// TODO: findOne For user로 만들어서 (ADMIN, READ, WRITE)권한없으면 403을 반환하는 라우트를 만들어야 합니다.
return this.mapService.findOne({ id });
}

@Patch(':id')
@ApiOkResponse({ type: MapResponseDto })
@ApiBearerAuth()
update(@Param('id') id: string, @Body() updateMapDto: UpdateMapDto) {
return this.mapService.update(id, updateMapDto);
}

@Delete(':id')
@ApiOkResponse({ type: Number })
@ApiBearerAuth()
remove(@Param('id') id: string) {
return this.mapService.remove(id);
}
Expand Down
5 changes: 4 additions & 1 deletion src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Patch,
Query,
} from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';

import { UseAuthGuard } from 'src/common/decorators/auth-guard.decorator';
import { CurrentUser } from 'src/common/decorators/user.decorator';
Expand All @@ -25,6 +25,7 @@ export class UserController {
@Get(':id')
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async findOne(@Param('id') id: string) {
const user = await this.userService.findOne({ id: +id });
return user;
Expand All @@ -33,6 +34,7 @@ export class UserController {
@Patch()
@UseAuthGuard([UserRole.USER])
@ApiOkResponse({ type: UserResponseDto })
@ApiBearerAuth()
async update(
@Body() updateUserDto: UpdateUserRequestDto,
@CurrentUser() user: User,
Expand All @@ -42,6 +44,7 @@ export class UserController {

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