From e77d8d8af04aff99775ba5358013ebbd18a31fc2 Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Thu, 31 Aug 2023 07:42:38 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20374:=20API=20IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2521: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2521) - Worktype追加API IFを実装しOpenAPI定義を更新しました。 ## レビューポイント - パスは認識通りか - パラメータは適切か ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- dictation_server/src/api/odms/openapi.json | 66 +++++++++++++++++++ .../features/accounts/accounts.controller.ts | 43 ++++++++++++ .../src/features/accounts/types/types.ts | 10 +++ 3 files changed, 119 insertions(+) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 03e67a3..7a7f262 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -783,6 +783,59 @@ }, "tags": ["accounts"], "security": [{ "bearer": [] }] + }, + "post": { + "operationId": "createWorktype", + "summary": "", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateWorktypesRequest" + } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateWorktypeResponse" + } + } + } + }, + "400": { + "description": "WorktypeIDが重複 / WorktypeIDが空 / WorktypeIDが20件登録済み", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorResponse" } + } + } + }, + "401": { + "description": "認証エラー", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorResponse" } + } + } + }, + "500": { + "description": "想定外のサーバーエラー", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorResponse" } + } + } + } + }, + "tags": ["accounts"], + "security": [{ "bearer": [] }] } }, "/users/confirm": { @@ -2701,6 +2754,19 @@ }, "required": ["workTypes"] }, + "CreateWorktypesRequest": { + "type": "object", + "properties": { + "worktypeId": { + "type": "string", + "minLength": 1, + "description": "WorktypeID" + }, + "description": { "type": "string", "description": "Worktypeの説明" } + }, + "required": ["worktypeId"] + }, + "CreateWorktypeResponse": { "type": "object", "properties": {} }, "ConfirmRequest": { "type": "object", "properties": { "token": { "type": "string" } }, diff --git a/dictation_server/src/features/accounts/accounts.controller.ts b/dictation_server/src/features/accounts/accounts.controller.ts index 037eb12..41929c8 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -43,6 +43,8 @@ import { CancelIssueRequest, CancelIssueResponse, GetWorkTypesResponse, + CreateWorktypeResponse, + CreateWorktypesRequest, } from './types/types'; import { USER_ROLES, ADMIN_ROLES, TIERS } from '../../constants'; import { AuthGuard } from '../../common/guards/auth/authguards'; @@ -673,4 +675,45 @@ export class AccountsController { ], }; } + + @Post('/worktypes') + @ApiResponse({ + status: HttpStatus.OK, + type: CreateWorktypeResponse, + description: '成功時のレスポンス', + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'WorktypeIDが重複 / WorktypeIDが空 / WorktypeIDが20件登録済み', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: '認証エラー', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: '想定外のサーバーエラー', + type: ErrorResponse, + }) + @ApiOperation({ operationId: 'createWorktype' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] })) + async createWorktype( + @Req() req: Request, + @Body() body: CreateWorktypesRequest, + ): Promise { + const { worktypeId, description } = body; + const token = retrieveAuthorizationToken(req); + const { userId } = jwt.decode(token, { json: true }) as AccessToken; + + const context = makeContext(userId); + console.log(context.trackingId); + console.log(worktypeId); + console.log(description); + + return {}; + } } diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index df60fcb..3d58765 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -346,3 +346,13 @@ export class GetWorkTypesResponse { @ApiProperty({ type: [WorkType] }) workTypes: WorkType[]; } + +export class CreateWorktypesRequest { + @ApiProperty({ minLength: 1, description: 'WorktypeID' }) + @MinLength(1) + worktypeId: string; + @ApiProperty({ description: 'Worktypeの説明', required: false }) + description?: string; +} + +export class CreateWorktypeResponse {}