Skip to content

Commit

Permalink
feat: add ApiBearerAuth decorator for api-gateway support (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
d0lim authored Sep 18, 2023
1 parent 5b97b3a commit a1d42bf
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 54 deletions.
3 changes: 3 additions & 0 deletions src/answer/answer.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Controller, Get, Param } from '@nestjs/common';
import { AnswerService } from './answer.service';
import { GetAnswerResponseDto } from './dto/get-answer-response.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller('answer')
@ApiBearerAuth(ACCESS_TOKEN)
export class AnswerController {
constructor(private readonly answerService: AnswerService) {}
@Get()
Expand Down
3 changes: 3 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { UniversalAccountId, UniversalAccountIdHeader } from './common/account/universal-account-id.decorator';
import { SwaggerUniversalAccountId } from './config/decorator/swagger-universal-account-id.decorator';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from './config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class AppController {
constructor(private readonly appService: AppService) {}

Expand Down
3 changes: 3 additions & 0 deletions src/apply-form/apply-form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import { GetApplyFormResponseDto } from './dto/get-apply-form-response.dto';
import { CreateApplyFormResponseDto } from './dto/create-apply-form-response.dto';
import { UpdateApplyFormDto } from './dto/update-apply-form.dto';
import { UpdateApplyFormResponseDto } from './dto/update-apply-form-response.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class ApplyFormController {
constructor(private readonly applyFormService: ApplyFormService) {}

Expand Down
4 changes: 3 additions & 1 deletion src/config/swagger-config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { INestApplication } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

export const ACCESS_TOKEN = 'access-token';

export function initSwaggerConfig(app: INestApplication): void {
const config = new DocumentBuilder()
.setTitle('title example')
.setDescription('description example')
.setVersion('1.0.0')
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'Token' }, 'access-token')
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'Token' }, ACCESS_TOKEN)
.build();

const document = SwaggerModule.createDocument(app, config);
Expand Down
21 changes: 12 additions & 9 deletions src/internal-user/internal-user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Controller, Get, Param } from '@nestjs/common';
import { InternalUserService } from './internal-user.service';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class InternalUserController {
constructor(private readonly internalUserService: InternalUserService) {}
constructor(private readonly internalUserService: InternalUserService) {}

@Get()
findAll() {
return this.internalUserService.findAll();
}
@Get()
findAll() {
return this.internalUserService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.internalUserService.findOne(+id);
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.internalUserService.findOne(+id);
}
}
45 changes: 24 additions & 21 deletions src/journal/journal.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@ import { Controller, Get, Param, Post, Patch, Delete, Body } from '@nestjs/commo
import { JournalService } from './journal.service';
import { UpdateJournalDto } from './dto/update-journal.dto';
import { CreateJournalDto } from './dto/create-journal.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class JournalController {
constructor(private readonly journalService: JournalService) {}
constructor(private readonly journalService: JournalService) {}

@Get()
findAll() {
return this.journalService.findAll();
}
@Get()
findAll() {
return this.journalService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.journalService.findOne(+id);
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.journalService.findOne(+id);
}

@Post()
create(@Body() createJournalDto: CreateJournalDto) {
return this.journalService.create(createJournalDto);
}
@Post()
create(@Body() createJournalDto: CreateJournalDto) {
return this.journalService.create(createJournalDto);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateJournalDto: UpdateJournalDto) {
return this.journalService.update(+id, updateJournalDto);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateJournalDto: UpdateJournalDto) {
return this.journalService.update(+id, updateJournalDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.journalService.remove(+id);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.journalService.remove(+id);
}
}
4 changes: 3 additions & 1 deletion src/member/member.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { UpdateMemberResponseDto } from './dto/update-member-response.dto';
import { UpdateMemberDto } from './dto/update-member.dto';
import { MemberService } from './member.service';
import { Controller, Get, Param, Patch, Body, Delete } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class MemberController {
constructor(private readonly memberService: MemberService) {}

Expand Down
45 changes: 24 additions & 21 deletions src/notice/notice.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@ import { Controller, Get, Post, Patch, Delete, Param, Body } from '@nestjs/commo
import { NoticeService } from './notice.service';
import { CreateNoticeDto } from './dto/create-notice.dto';
import { UpdateNoticeDto } from './dto/update-notice.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class NoticeController {
constructor(private readonly noticeService: NoticeService) {}
constructor(private readonly noticeService: NoticeService) {}

@Get()
findAll() {
return this.noticeService.findAll();
}
@Get()
findAll() {
return this.noticeService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.noticeService.findOne(+id);
}
@Get(':id')
findOne(@Param('id') id: string) {
return this.noticeService.findOne(+id);
}

@Post()
create(@Body() createNoticeDto: CreateNoticeDto) {
return this.noticeService.create(createNoticeDto);
}
@Post()
create(@Body() createNoticeDto: CreateNoticeDto) {
return this.noticeService.create(createNoticeDto);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateNoticeDto: UpdateNoticeDto) {
return this.noticeService.update(+id, updateNoticeDto);
}
@Patch(':id')
update(@Param('id') id: string, @Body() updateNoticeDto: UpdateNoticeDto) {
return this.noticeService.update(+id, updateNoticeDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.noticeService.remove(+id);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.noticeService.remove(+id);
}
}
3 changes: 3 additions & 0 deletions src/question/question.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { QuestionService } from './question.service';
import { CreateQuestionDto } from './dto/create-question.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class QuestionController {
constructor(private readonly questionService: QuestionService) {}

Expand Down
3 changes: 3 additions & 0 deletions src/study/study.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { GetStudyResponseDto } from './dto/get-study-response.dto';
import { UpdateStudyResponseDto } from './dto/update-study-response.dto';
import { GetNoticeResponseDto } from 'src/notice/dto/get-notice-response.dto';
import { GetJournalResponseDto } from 'src/journal/dto/get-journal-response.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class StudyController {
constructor(private readonly studyService: StudyService) {}

Expand Down
3 changes: 3 additions & 0 deletions src/tag/tag.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/commo
import { TagService } from './tag.service';
import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class TagController {
constructor(private readonly tagService: TagService) {}

Expand Down
3 changes: 3 additions & 0 deletions src/timeFrame/timeframe.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Controller, Get, Param } from '@nestjs/common';
import { TimeFrameService } from './timeframe.service';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class TimeFrameController {
constructor(private readonly timeFrameService: TimeFrameService) {}

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 @@ -2,8 +2,11 @@ import { Body, Controller, Get, Post, Patch, Delete, Param, HttpCode } from '@ne
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { ApiBearerAuth } from '@nestjs/swagger';
import { ACCESS_TOKEN } from '../config/swagger-config';

@Controller()
@ApiBearerAuth(ACCESS_TOKEN)
export class UserController {
constructor(private readonly userService: UserService) {}

Expand Down Expand Up @@ -35,6 +38,6 @@ export class UserController {
@Delete(':id')
@HttpCode(204)
remove(@Param('id') id: string) {
return this.userService.remove(+id);
return this.userService.remove(+id);
}
}

0 comments on commit a1d42bf

Please sign in to comment.