Merged PR 317: API-IF実装

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

ライセンス割り当てのAPI-IFを作成しました。

## レビューポイント
なし

## UIの変更
なし

## 動作確認状況
Swagger UIで反映されていることを確認

## 補足
なし
This commit is contained in:
oura.a 2023-08-09 08:46:01 +00:00
parent 077b63b0dc
commit 3b785e97aa
5 changed files with 242 additions and 1 deletions

View File

@ -882,6 +882,62 @@
"security": [{ "bearer": [] }] "security": [{ "bearer": [] }]
} }
}, },
"/users/license/allocate": {
"post": {
"operationId": "allocateLicense",
"summary": "",
"description": "ライセンスを割り当てます",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AllocateLicenseRequest"
}
}
}
},
"responses": {
"200": {
"description": "成功時のレスポンス",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AllocateLicenseResponse"
}
}
}
},
"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": { "/files/audio/upload-finished": {
"post": { "post": {
"operationId": "uploadFinished", "operationId": "uploadFinished",
@ -1816,6 +1872,54 @@
"security": [{ "bearer": [] }] "security": [{ "bearer": [] }]
} }
}, },
"/licenses/allocatable": {
"get": {
"operationId": "getAllocatableLicenses",
"summary": "",
"description": "割り当て可能なライセンスを取得します",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetAllocatableLicensesRequest"
}
}
}
},
"responses": {
"200": {
"description": "成功時のレスポンス",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/GetAllocatableLicensesResponse"
}
}
}
},
"401": {
"description": "認証エラー",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" }
}
}
},
"500": {
"description": "想定外のサーバーエラー",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/ErrorResponse" }
}
}
}
},
"tags": ["licenses"],
"security": [{ "bearer": [] }]
}
},
"/notification/register": { "/notification/register": {
"post": { "post": {
"operationId": "register", "operationId": "register",
@ -2373,6 +2477,18 @@
"required": ["id", "role", "autoRenew", "licenseAlart", "notification"] "required": ["id", "role", "autoRenew", "licenseAlart", "notification"]
}, },
"PostUpdateUserResponse": { "type": "object", "properties": {} }, "PostUpdateUserResponse": { "type": "object", "properties": {} },
"AllocateLicenseRequest": {
"type": "object",
"properties": {
"userId": { "type": "number", "description": "ユーザーID" },
"newLicenseId": {
"type": "number",
"description": "割り当てるライセンスのID"
}
},
"required": ["userId", "newLicenseId"]
},
"AllocateLicenseResponse": { "type": "object", "properties": {} },
"AudioOptionItem": { "AudioOptionItem": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -2671,6 +2787,25 @@
"required": ["cardLicenseKey"] "required": ["cardLicenseKey"]
}, },
"ActivateCardLicensesResponse": { "type": "object", "properties": {} }, "ActivateCardLicensesResponse": { "type": "object", "properties": {} },
"GetAllocatableLicensesRequest": { "type": "object", "properties": {} },
"AllocatableLicenseInfo": {
"type": "object",
"properties": {
"licenseId": { "type": "number" },
"expiryDate": { "format": "date-time", "type": "string" }
},
"required": ["licenseId", "expiryDate"]
},
"GetAllocatableLicensesResponse": {
"type": "object",
"properties": {
"allocatableLicenses": {
"type": "array",
"items": { "$ref": "#/components/schemas/AllocatableLicenseInfo" }
}
},
"required": ["allocatableLicenses"]
},
"RegisterRequest": { "RegisterRequest": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -1,6 +1,7 @@
import { import {
Body, Body,
Controller, Controller,
Get,
HttpStatus, HttpStatus,
Post, Post,
Req, Req,
@ -21,6 +22,8 @@ import {
IssueCardLicensesRequest, IssueCardLicensesRequest,
ActivateCardLicensesResponse, ActivateCardLicensesResponse,
ActivateCardLicensesRequest, ActivateCardLicensesRequest,
GetAllocatableLicensesResponse,
GetAllocatableLicensesRequest,
} from './types/types'; } from './types/types';
import { Request } from 'express'; import { Request } from 'express';
import { retrieveAuthorizationToken } from '../../common/http/helper'; import { retrieveAuthorizationToken } from '../../common/http/helper';
@ -169,4 +172,45 @@ export class LicensesController {
return {}; return {};
} }
@ApiResponse({
status: HttpStatus.OK,
type: GetAllocatableLicensesResponse,
description: '成功時のレスポンス',
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: '認証エラー',
type: ErrorResponse,
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: '想定外のサーバーエラー',
type: ErrorResponse,
})
@ApiOperation({
operationId: 'getAllocatableLicenses',
description: '割り当て可能なライセンスを取得します',
})
@ApiBearerAuth()
@UseGuards(AuthGuard)
@UseGuards(
RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN], tiers: [TIERS.TIER5] }),
)
@Get('/allocatable')
async getAllocatableLicenses(
@Req() req: Request,
@Body() body: GetAllocatableLicensesRequest,
): Promise<GetAllocatableLicensesResponse> {
// TODO 仮の戻り値
return {
allocatableLicenses: [
{ licenseId: 1, expiryDate: null },
{ licenseId: 2, expiryDate: null },
{ licenseId: 3, expiryDate: new Date(2023, 12, 31, 23, 59, 59) },
{ licenseId: 4, expiryDate: new Date(2023, 10, 31, 23, 59, 59) },
],
};
}
} }

View File

@ -38,6 +38,19 @@ export class ActivateCardLicensesRequest {
export class ActivateCardLicensesResponse {} export class ActivateCardLicensesResponse {}
export class GetAllocatableLicensesRequest {}
export class AllocatableLicenseInfo {
@ApiProperty()
licenseId: number;
@ApiProperty()
expiryDate: Date;
}
export class GetAllocatableLicensesResponse {
@ApiProperty({ type: [AllocatableLicenseInfo] })
allocatableLicenses: AllocatableLicenseInfo[];
}
// ライセンス算出用に、その日の始まりの時刻0:00:00.000)の日付を取得する // ライセンス算出用に、その日の始まりの時刻0:00:00.000)の日付を取得する
export class DateWithZeroTime extends Date { export class DateWithZeroTime extends Date {
constructor(...args: any[]) { constructor(...args: any[]) {

View File

@ -239,3 +239,12 @@ export class PostUpdateUserRequest {
} }
export class PostUpdateUserResponse {} export class PostUpdateUserResponse {}
export class AllocateLicenseRequest {
@ApiProperty({ description: 'ユーザーID' })
userId: number;
@ApiProperty({ description: '割り当てるライセンスのID' })
newLicenseId: number;
}
export class AllocateLicenseResponse{}

View File

@ -33,6 +33,8 @@ import {
GetSortCriteriaResponse, GetSortCriteriaResponse,
PostUpdateUserRequest, PostUpdateUserRequest,
PostUpdateUserResponse, PostUpdateUserResponse,
AllocateLicenseResponse,
AllocateLicenseRequest,
} from './types/types'; } from './types/types';
import { UsersService } from './users.service'; import { UsersService } from './users.service';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
@ -41,7 +43,7 @@ import {
isSortDirection, isSortDirection,
isTaskListSortableAttribute, isTaskListSortableAttribute,
} from '../../common/types/sort'; } from '../../common/types/sort';
import { ADMIN_ROLES } from '../../constants'; import { ADMIN_ROLES, TIERS } from '../../constants';
import { RoleGuard } from '../../common/guards/role/roleguards'; import { RoleGuard } from '../../common/guards/role/roleguards';
import { makeContext } from '../../common/log'; import { makeContext } from '../../common/log';
import { UserRoles } from '../../common/types/role'; import { UserRoles } from '../../common/types/role';
@ -372,4 +374,42 @@ export class UsersController {
); );
return {}; return {};
} }
@ApiResponse({
status: HttpStatus.OK,
type: AllocateLicenseResponse,
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: 'allocateLicense',
description: 'ライセンスを割り当てます',
})
@ApiBearerAuth()
@UseGuards(AuthGuard)
@UseGuards(
RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN], tiers: [TIERS.TIER5] }),
)
@Post('/license/allocate')
async allocateLicense(
@Body() body: AllocateLicenseRequest,
@Req() req: Request,
): Promise<AllocateLicenseResponse> {
return {};
}
} }