Merged PR 133: API I/F実装

## 概要
[Task1837: API I/F実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1837)

- ラフスケッチに基づき、「アカウント情報取得API」「ライセンス集計取得API(ラフスケッチ時は「第五階層用ライセンス情報取得API」)」のI/F実装とopenapi化を行いました。

## レビューポイント
- 管理者のみのためUseGuardsを使用しています。実装内容について問題ないか特に確認いただきたいです

## UIの変更
- 無し

## 動作確認状況
- ローカルで確認済

## 補足
- 無し
This commit is contained in:
masaaki 2023-06-06 07:00:11 +00:00
parent 85b8ab0919
commit cfca98e53b
3 changed files with 205 additions and 4 deletions

View File

@ -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" } },

View File

@ -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<GetLicenseSummaryResponse> {
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,
},
};
}
}

View File

@ -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;
}