From bde1ff60a92c8b2caaac921cfe3c28f682b9ed3d Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Tue, 5 Sep 2023 08:09:41 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20384:=20API=20IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2568: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2568) - worktype更新APIのIFを実装し、OpenAPI定義を更新しました。 ## レビューポイント - パスは適切か - パラメータの制約は適切か ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- dictation_server/src/api/odms/openapi.json | 76 +++++++++++++++++++ .../features/accounts/accounts.controller.ts | 48 ++++++++++++ .../src/features/accounts/types/types.ts | 22 ++++++ 3 files changed, 146 insertions(+) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 8618769..da51092 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -838,6 +838,69 @@ "security": [{ "bearer": [] }] } }, + "/accounts/worktypes/{id}": { + "post": { + "operationId": "updateWorktype", + "summary": "", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "description": "Worktypeの内部ID", + "schema": { "type": "number" } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UpdateWorktypesRequest" + } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/UpdateWorktypeResponse" + } + } + } + }, + "400": { + "description": "WorktypeIDが重複 / WorktypeIDが空", + "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": [] }] + } + }, "/accounts/partners": { "get": { "operationId": "getPartners", @@ -2825,6 +2888,19 @@ "required": ["worktypeId"] }, "CreateWorktypeResponse": { "type": "object", "properties": {} }, + "UpdateWorktypesRequest": { + "type": "object", + "properties": { + "worktypeId": { + "type": "string", + "minLength": 1, + "description": "WorktypeID" + }, + "description": { "type": "string", "description": "Worktypeの説明" } + }, + "required": ["worktypeId"] + }, + "UpdateWorktypeResponse": { "type": "object", "properties": {} }, "Partner": { "type": "object", "properties": { diff --git a/dictation_server/src/features/accounts/accounts.controller.ts b/dictation_server/src/features/accounts/accounts.controller.ts index 289bee3..1681637 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -48,6 +48,9 @@ import { CreateWorktypesRequest, GetPartnersRequest, GetPartnersResponse, + UpdateWorktypeRequestParam, + UpdateWorktypeResponse, + UpdateWorktypesRequest, } from './types/types'; import { USER_ROLES, ADMIN_ROLES, TIERS } from '../../constants'; import { AuthGuard } from '../../common/guards/auth/authguards'; @@ -719,6 +722,51 @@ export class AccountsController { return {}; } + @Post('/worktypes/:id') + @ApiResponse({ + status: HttpStatus.OK, + type: UpdateWorktypeResponse, + description: '成功時のレスポンス', + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'WorktypeIDが重複 / WorktypeIDが空', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: '認証エラー', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: '想定外のサーバーエラー', + type: ErrorResponse, + }) + @ApiOperation({ operationId: 'updateWorktype' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] })) + async updateWorktype( + @Req() req: Request, + @Param() param: UpdateWorktypeRequestParam, + @Body() body: UpdateWorktypesRequest, + ): Promise { + const { worktypeId, description } = body; + const { id } = param; + const token = retrieveAuthorizationToken(req); + const { userId } = jwt.decode(token, { json: true }) as AccessToken; + + const context = makeContext(userId); + + console.log('worktypeId: ', worktypeId); + console.log('description: ', description); + console.log('id: ', id); + console.log(context.trackingId); + + return {}; + } + @Get('/partners') @ApiResponse({ status: HttpStatus.OK, diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index 4b54066..9ce7f7a 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -362,6 +362,28 @@ export class CreateWorktypesRequest { export class CreateWorktypeResponse {} +export class UpdateWorktypesRequest { + @ApiProperty({ minLength: 1, description: 'WorktypeID' }) + @MinLength(1) + @MaxLength(255) + @IsWorktypeId() + worktypeId: string; + @ApiProperty({ description: 'Worktypeの説明', required: false }) + @MaxLength(255) + @IsOptional() + description?: string; +} + +export class UpdateWorktypeResponse {} + +export class UpdateWorktypeRequestParam { + @ApiProperty({ description: 'Worktypeの内部ID' }) + @Type(() => Number) + @IsInt() + @Min(0) + id: number; +} + export class GetPartnersRequest { @ApiProperty({ description: '取得件数' }) @IsInt()