From 75025ca596b706ec4331371ecbe1eb825819ec48 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:32:08 +0700 Subject: [PATCH] docs: cabinet --- .../src/controllers/cabinetController.ts | 41 ++++++++++++++++-- Services/server/src/swagger.json | 42 +++++++++++++++---- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/Services/server/src/controllers/cabinetController.ts b/Services/server/src/controllers/cabinetController.ts index b900dbb..3c3bf10 100644 --- a/Services/server/src/controllers/cabinetController.ts +++ b/Services/server/src/controllers/cabinetController.ts @@ -12,6 +12,7 @@ import { Tags, Request, Response, + Example, } from "tsoa"; import minioClient from "../minio"; @@ -38,6 +39,20 @@ export class CabinetController extends Controller { "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการตู้เอกสารได้ กรุณาลองใหม่ในภายหลัง", ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") + @Example([ + { + path: "ตู้เอกสาร 1/", + name: "ตู้เอกสาร 1", + createdAt: "2021-07-20T12:33:13.018Z", + createdBy: "admin", + }, + { + path: "ตู้เอกสาร 2/", + name: "ตู้เอกสาร 2", + createdAt: "2022-01-23T16:05:02.114Z", + createdBy: "admin", + }, + ]) public async listCabinet(): Promise { const list = await listFolder(DEFAULT_BUCKET!).catch((e) => console.error(`Error List Folder: ${e}`), @@ -54,7 +69,13 @@ export class CabinetController extends Controller { @SuccessResponse(HttpStatusCode.CREATED, "สำเร็จ") public async createCabinet( @Request() request: { user: { preferred_username: string } }, - @Body() body: { name: string }, + @Body() + body: { + /** + * @example "ตู้เอกสาร 1" + */ + name: string; + }, ) { const created = await minioClient .putObject(DEFAULT_BUCKET!, `${replaceIllegalChars(body.name)}/.keep`, "", 0, { @@ -68,6 +89,9 @@ export class CabinetController extends Controller { return this.setStatus(HttpStatusCode.CREATED); } + /** + * @example cabinetName "ตู้เอกสาร 1" + */ @Put("/{cabinetName}") @Tags("ตู้เอกสาร") @Security("bearerAuth", ["admin"]) @@ -75,7 +99,13 @@ export class CabinetController extends Controller { @SuccessResponse(HttpStatusCode.NO_CONTENT, "สำเร็จ") public async editCabinet( @Path() cabinetName: string, - @Body() body: { name: string }, + @Body() + body: { + /** + * @example "ตู้เอกสารใหม่" + */ + name: string; + }, ): Promise { const path = `${cabinetName}/`; const list = await listItem(DEFAULT_BUCKET!, path, true); @@ -94,7 +124,9 @@ export class CabinetController extends Controller { return await minioClient.removeObject(DEFAULT_BUCKET!, current.name); } - const search = await esClient.search }>({ + const search = await esClient.search< + StorageFile & { attachment: Record } + >({ index: DEFAULT_INDEX!, query: { match: { pathname: current.name } }, }); @@ -121,6 +153,9 @@ export class CabinetController extends Controller { return this.setStatus(HttpStatusCode.NO_CONTENT); } + /** + * @example cabinetName "ตู้เอกสาร 1" + */ @Delete("/{cabinetName}") @Tags("ตู้เอกสาร") @Security("bearerAuth", ["admin"]) diff --git a/Services/server/src/swagger.json b/Services/server/src/swagger.json index 9c56b10..4e2ff8f 100644 --- a/Services/server/src/swagger.json +++ b/Services/server/src/swagger.json @@ -205,6 +205,24 @@ "$ref": "#/components/schemas/StorageFolder" }, "type": "array" + }, + "examples": { + "Example 1": { + "value": [ + { + "path": "ตู้เอกสาร 1/", + "name": "ตู้เอกสาร 1", + "createdAt": "2021-07-20T12:33:13.018Z", + "createdBy": "admin" + }, + { + "path": "ตู้เอกสาร 2/", + "name": "ตู้เอกสาร 2", + "createdAt": "2022-01-23T16:05:02.114Z", + "createdBy": "admin" + } + ] + } } } } @@ -251,7 +269,8 @@ "schema": { "properties": { "name": { - "type": "string" + "type": "string", + "example": "ตู้เอกสาร 1" } }, "required": [ @@ -292,7 +311,8 @@ "required": true, "schema": { "type": "string" - } + }, + "example": "ตู้เอกสาร 1" } ], "requestBody": { @@ -302,7 +322,8 @@ "schema": { "properties": { "name": { - "type": "string" + "type": "string", + "example": "ตู้เอกสารใหม่" } }, "required": [ @@ -341,7 +362,8 @@ "required": true, "schema": { "type": "string" - } + }, + "example": "ตู้เอกสาร 1" } ] } @@ -382,7 +404,8 @@ "required": true, "schema": { "type": "string" - } + }, + "example": "ตู้เอกสาร 1" } ] }, @@ -416,7 +439,8 @@ "required": true, "schema": { "type": "string" - } + }, + "example": "ตู้เอกสาร 1" } ], "requestBody": { @@ -467,7 +491,8 @@ "required": true, "schema": { "type": "string" - } + }, + "example": "ตู้เอกสาร 1" }, { "in": "path", @@ -521,7 +546,8 @@ "required": true, "schema": { "type": "string" - } + }, + "example": "ตู้เอกสาร 1" }, { "in": "path",