import { Body, Controller, Get, HttpStatus, Post, Req } from '@nestjs/common'; import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags, } from '@nestjs/swagger'; import { ErrorResponse } from '../../common/error/types/types'; import { ConfirmRequest, ConfirmResponse, GetUsersResponse, SignupRequest, SignupResponse, } from './types/types'; import { UsersService } from './users.service'; import { Request } from 'express'; @ApiTags('users') @Controller('users') export class UsersController { constructor(private readonly usersService: UsersService) {} @ApiResponse({ status: HttpStatus.OK, type: ConfirmResponse, description: '成功時のレスポンス', }) @ApiResponse({ status: HttpStatus.BAD_REQUEST, description: '不正なトークン', type: ErrorResponse, }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: '想定外のサーバーエラー', type: ErrorResponse, }) @ApiOperation({ operationId: 'confirmUser' }) @Post('confirm') async confirmUser(@Body() body: ConfirmRequest): Promise { await this.usersService.confirmUser(body.token); return {}; } @ApiResponse({ status: HttpStatus.OK, type: ConfirmResponse, description: '成功時のレスポンス', }) @ApiResponse({ status: HttpStatus.BAD_REQUEST, description: '不正なトークン', type: ErrorResponse, }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: '想定外のサーバーエラー', type: ErrorResponse, }) @ApiOperation({ operationId: 'confirmUserAndInitPassword' }) @Post('confirm/initpassword') async confirmUserAndInitPassword( @Body() body: ConfirmRequest, ): Promise { console.log(body); return {}; } @ApiResponse({ status: HttpStatus.OK, type: GetUsersResponse, description: '成功時のレスポンス', }) @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '認証エラー', type: ErrorResponse, }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: '想定外のサーバーエラー', type: ErrorResponse, }) @ApiOperation({ operationId: 'getUsers' }) @ApiBearerAuth() @Get() async getUsers(@Req() req: Request): Promise { console.log(req.header('Authorization')); return { users: [] }; } @ApiResponse({ status: HttpStatus.OK, type: SignupResponse, description: '成功時のレスポンス', }) @ApiResponse({ status: HttpStatus.BAD_REQUEST, description: '登録済みメールによる再登録、AuthorIDの重複など', type: ErrorResponse, }) @ApiResponse({ status: HttpStatus.UNAUTHORIZED, description: '認証エラー', type: ErrorResponse, }) @ApiResponse({ status: HttpStatus.INTERNAL_SERVER_ERROR, description: '想定外のサーバーエラー', type: ErrorResponse, }) @ApiOperation({ operationId: 'signup' }) @ApiBearerAuth() @Post('/signup') async signup( @Req() req: Request, @Body() body: SignupRequest, ): Promise { console.log(req.header('Authorization')); console.log(body); return {}; } }