## 概要 [Task1599: API I/F実装(メール認証)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1599) - エンドユーザーのメール認証を行うAPIのI/Fを作成 ## レビューポイント - pathは問題なさそうか - Request/Responseは本質的に同一だと思われるため、管理者の認証と共通としたが問題ないか? ## 動作確認状況 - openapi.jsonの生成を確認
125 lines
3.2 KiB
TypeScript
125 lines
3.2 KiB
TypeScript
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<ConfirmResponse> {
|
|
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<ConfirmResponse> {
|
|
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<GetUsersResponse> {
|
|
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<SignupResponse> {
|
|
console.log(req.header('Authorization'));
|
|
console.log(body);
|
|
return {};
|
|
}
|
|
}
|