From 4b812fc0b381c22ce3142d533c582ca59b1a519f Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Tue, 24 Oct 2023 08:35:31 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20520:=20API=20IF=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2919: API IF作成](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2919) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) 新規のためなし ## レビューポイント メソッド名がふさわしいか ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば --- dictation_server/src/api/odms/openapi.json | 43 ++++++++++++++++++ .../src/features/users/types/types.ts | 6 +++ .../src/features/users/users.controller.ts | 45 +++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 993efb4..76bf8c9 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -1874,6 +1874,42 @@ "tags": ["users"] } }, + "/users/me": { + "get": { + "operationId": "getMyUser", + "summary": "", + "description": "ログインしているユーザーの情報を取得します", + "parameters": [], + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/GetMyUserResponse" } + } + } + }, + "400": { + "description": "該当ユーザーがDBに存在しない場合", + "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", @@ -4141,6 +4177,13 @@ "required": ["idToken", "acceptedEULAVersion"] }, "UpdateAcceptedVersionResponse": { "type": "object", "properties": {} }, + "GetMyUserResponse": { + "type": "object", + "properties": { + "userName": { "type": "string", "description": "ユーザー名" } + }, + "required": ["userName"] + }, "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 991ec09..b75b6b6 100644 --- a/dictation_server/src/features/users/types/types.ts +++ b/dictation_server/src/features/users/types/types.ts @@ -10,6 +10,7 @@ import { IsPasswordvalid, } from '../../../common/validators/encryptionPassword.validator'; import { IsRoleAuthorDataValid } from '../../../common/validators/roleAuthor.validator'; +import { Aadb2cUser } from '../../../common/token'; export class ConfirmRequest { @ApiProperty() @@ -266,3 +267,8 @@ export class UpdateAcceptedVersionRequest { } export class UpdateAcceptedVersionResponse {} + +export class GetMyUserResponse { + @ApiProperty({ description: 'ユーザー名' }) + userName: string; +} diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index ee6175a..c9d6a56 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -39,6 +39,7 @@ import { DeallocateLicenseRequest, UpdateAcceptedVersionRequest, UpdateAcceptedVersionResponse, + GetMyUserResponse, } from './types/types'; import { UsersService } from './users.service'; import { AuthService } from '../auth/auth.service'; @@ -53,6 +54,7 @@ import { RoleGuard } from '../../common/guards/role/roleguards'; import { makeContext } from '../../common/log'; import { UserRoles } from '../../common/types/role'; import { v4 as uuidv4 } from 'uuid'; +import { userInfo } from 'os'; @ApiTags('users') @Controller('users') @@ -621,4 +623,47 @@ export class UsersController { ); return {}; } + @ApiResponse({ + status: HttpStatus.OK, + type: GetMyUserResponse, + description: '成功時のレスポンス', + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: '該当ユーザーがDBに存在しない場合', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: '想定外のサーバーエラー', + type: ErrorResponse, + }) + @ApiOperation({ + operationId: 'getMyUser', + description: 'ログインしているユーザーの情報を取得します', + }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @Get('me') + async getMyUser(@Req() req: Request): Promise { + const accessToken = retrieveAuthorizationToken(req) as string; + if (!accessToken) { + throw new HttpException( + makeErrorResponse('E000107'), + HttpStatus.UNAUTHORIZED, + ); + } + const decodedAccessToken = jwt.decode(accessToken, { json: true }); + if (!decodedAccessToken) { + throw new HttpException( + makeErrorResponse('E000101'), + HttpStatus.UNAUTHORIZED, + ); + } + const { userId } = decodedAccessToken as AccessToken; + const context = makeContext(userId); + const userName = 'TEST'; + //const userName = await this.usersService.getUserName(context, userId); + return { userName }; + } }