From 417ba17d13c1c6fd4de51f548881252b291b5bbe Mon Sep 17 00:00:00 2001 From: masaaki Date: Tue, 22 Aug 2023 08:30:01 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20340:=20API-IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2445: API-IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2445) ライセンス割り当て解除API-IFを作成しました。 ## レビューポイント なし ## UIの変更 なし ## 動作確認状況 Swagger UIにより確認済み --- dictation_server/src/api/odms/openapi.json | 64 +++++++++++++++++++ .../src/features/users/types/types.ts | 7 ++ .../src/features/users/users.controller.ts | 46 +++++++++++++ 3 files changed, 117 insertions(+) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 7893821..f156a85 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -938,6 +938,62 @@ "security": [{ "bearer": [] }] } }, + "/users/license/deallocate": { + "post": { + "operationId": "deallocateLicense", + "summary": "", + "description": "ライセンス割り当てを解除します", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeallocateLicenseRequest" + } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeallocateLicenseResponse" + } + } + } + }, + "400": { + "description": "すでにライセンスが割り当て解除されている時", + "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": ["users"], + "security": [{ "bearer": [] }] + } + }, "/files/audio/upload-finished": { "post": { "operationId": "uploadFinished", @@ -2488,6 +2544,14 @@ "required": ["userId", "newLicenseId"] }, "AllocateLicenseResponse": { "type": "object", "properties": {} }, + "DeallocateLicenseRequest": { + "type": "object", + "properties": { + "userId": { "type": "number", "description": "ユーザーID" } + }, + "required": ["userId"] + }, + "DeallocateLicenseResponse": { "type": "object", "properties": {} }, "AudioOptionItem": { "type": "object", "properties": { diff --git a/dictation_server/src/features/users/types/types.ts b/dictation_server/src/features/users/types/types.ts index 993b38c..42f1a97 100644 --- a/dictation_server/src/features/users/types/types.ts +++ b/dictation_server/src/features/users/types/types.ts @@ -248,3 +248,10 @@ export class AllocateLicenseRequest { } export class AllocateLicenseResponse {} + +export class DeallocateLicenseRequest { + @ApiProperty({ description: 'ユーザーID' }) + userId: number; +} + +export class DeallocateLicenseResponse {} diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index 6f76fcb..bb7b589 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -35,6 +35,8 @@ import { PostUpdateUserResponse, AllocateLicenseResponse, AllocateLicenseRequest, + DeallocateLicenseResponse, + DeallocateLicenseRequest, } from './types/types'; import { UsersService } from './users.service'; import jwt from 'jsonwebtoken'; @@ -424,4 +426,48 @@ export class UsersController { ); return {}; } + + @ApiResponse({ + status: HttpStatus.OK, + type: DeallocateLicenseResponse, + description: '成功時のレスポンス', + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'すでにライセンスが割り当て解除されている時', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: '認証エラー', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: '想定外のサーバーエラー', + type: ErrorResponse, + }) + @ApiOperation({ + operationId: 'deallocateLicense', + description: 'ライセンス割り当てを解除します', + }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards( + RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN], tiers: [TIERS.TIER5] }), + ) + @Post('/license/deallocate') + async deallocateLicense( + @Body() body: DeallocateLicenseRequest, + @Req() req: Request, + ): Promise { + //API実装時に詳細をかいていく + //const accessToken = retrieveAuthorizationToken(req); + //const { userId } = jwt.decode(accessToken, { json: true }) as AccessToken; + + //const context = makeContext(userId); + + //await this.usersService.deallocateLicense(context, body.userId); + return {}; + } }