diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index ef8e82e..1d7bb5e 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -132,6 +132,54 @@ "tags": ["accounts"] } }, + "/accounts/licenses/summary": { + "post": { + "operationId": "getLicenseSummary", + "summary": "", + "description": "指定したアカウントのライセンス集計情報を取得します", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetLicenseSummaryRequest" + } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetLicenseSummaryResponse" + } + } + } + }, + "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": { "post": { "operationId": "confirmUser", @@ -1275,6 +1323,49 @@ ] }, "CreateAccountResponse": { "type": "object", "properties": {} }, + "GetLicenseSummaryRequest": { + "type": "object", + "properties": { "accountId": { "type": "number" } }, + "required": ["accountId"] + }, + "LicenseSummaryInfo": { + "type": "object", + "properties": { + "totalLicense": { "type": "number" }, + "allocatedLicense": { "type": "number" }, + "reusableLicense": { "type": "number" }, + "freeLicense": { "type": "number" }, + "expiringWithin14daysLicense": { "type": "number" }, + "issueRequesting": { "type": "number" }, + "numberOfRequesting": { "type": "number" }, + "shortage": { "type": "number" }, + "storageSize": { "type": "number" }, + "usedSize": { "type": "number" }, + "isAccountLock": { "type": "boolean" } + }, + "required": [ + "totalLicense", + "allocatedLicense", + "reusableLicense", + "freeLicense", + "expiringWithin14daysLicense", + "issueRequesting", + "numberOfRequesting", + "shortage", + "storageSize", + "usedSize", + "isAccountLock" + ] + }, + "GetLicenseSummaryResponse": { + "type": "object", + "properties": { + "licenseSummaryInfo": { + "$ref": "#/components/schemas/LicenseSummaryInfo" + } + }, + "required": ["licenseSummaryInfo"] + }, "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 b2f359c..e464208 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -1,9 +1,29 @@ -import { Body, Controller, HttpStatus, Post } from '@nestjs/common'; -import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { + Body, + Controller, + HttpStatus, + Post, + Req, + UseGuards, +} from '@nestjs/common'; +import { + ApiOperation, + ApiResponse, + ApiTags, + ApiBearerAuth, +} from '@nestjs/swagger'; import { ErrorResponse } from '../../common/error/types/types'; +import { Request } from 'express'; import { AccountsService } from './accounts.service'; -import { CreateAccountRequest, CreateAccountResponse } from './types/types'; -import { USER_ROLES } from '../../constants'; +import { + CreateAccountRequest, + CreateAccountResponse, + GetLicenseSummaryRequest, + GetLicenseSummaryResponse, +} from './types/types'; +import { USER_ROLES, ADMIN_ROLES } from '../../constants'; +import { AuthGuard } from 'src/common/guards/auth/authguards'; +import { RoleGuard } from 'src/common/guards/role/roleguards'; @ApiTags('accounts') @Controller('accounts') @@ -54,4 +74,50 @@ export class AccountsController { return {}; } + + @ApiResponse({ + status: HttpStatus.OK, + type: GetLicenseSummaryResponse, + description: '成功時のレスポンス', + }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: '認証エラー', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: '想定外のサーバーエラー', + type: ErrorResponse, + }) + @ApiOperation({ + operationId: 'getLicenseSummary', + description: '指定したアカウントのライセンス集計情報を取得します', + }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] })) + @Post('licenses/summary') + async getLicenseSummary( + @Req() req: Request, + @Body() body: GetLicenseSummaryRequest, + ): Promise { + console.log(req.header('Authorization')); + console.log(body); + return { + licenseSummaryInfo: { + totalLicense: 0, + allocatedLicense: 0, + reusableLicense: 0, + freeLicense: 0, + expiringWithin14daysLicense: 0, + issueRequesting: 0, + numberOfRequesting: 0, + shortage: 0, + storageSize: 0, + usedSize: 0, + isAccountLock: true, + }, + }; + } } diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index 56dd897..2a4089d 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -28,3 +28,47 @@ export class CreateAccountRequest { } export class CreateAccountResponse {} + +export class GetLicenseSummaryRequest { + @ApiProperty() + accountId: number; +} + +export class LicenseSummaryInfo { + @ApiProperty() + totalLicense: number; + + @ApiProperty() + allocatedLicense: number; + + @ApiProperty() + reusableLicense: number; + + @ApiProperty() + freeLicense: number; + + @ApiProperty() + expiringWithin14daysLicense: number; + + @ApiProperty() + issueRequesting: number; + + @ApiProperty() + numberOfRequesting: number; + + @ApiProperty() + shortage: number; + + @ApiProperty() + storageSize: number; + + @ApiProperty() + usedSize: number; + + @ApiProperty() + isAccountLock: boolean; +} +export class GetLicenseSummaryResponse { + @ApiProperty({ type: LicenseSummaryInfo }) + licenseSummaryInfo: LicenseSummaryInfo; +}