diff --git a/Services/server/src/controllers/cabinetController.ts b/Services/server/src/controllers/cabinetController.ts index 463cb43..ec6a6a2 100644 --- a/Services/server/src/controllers/cabinetController.ts +++ b/Services/server/src/controllers/cabinetController.ts @@ -182,4 +182,21 @@ export class CabinetController extends Controller { return this.setStatus(HttpStatusCode.NO_CONTENT); } + + /** + * @example cabinetName "ตู้เอกสาร 1" + */ + @Get("/{cabinetName}/size") + @Tags("ตู้เอกสาร") + @Security("bearerAuth") + @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") + public async calc(@Path() cabinetName: string) { + const list = await listItem(DEFAULT_BUCKET!, `${cabinetName}/`, true).catch((e) => + console.error(`Error List Folder: ${e}`), + ); + + if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง"); + + return { size: list.reduce((a, c) => a + c.size, 0) }; + } } diff --git a/Services/server/src/controllers/drawerController.ts b/Services/server/src/controllers/drawerController.ts index 9d3a505..1bf437d 100644 --- a/Services/server/src/controllers/drawerController.ts +++ b/Services/server/src/controllers/drawerController.ts @@ -203,4 +203,22 @@ export class DrawerController extends Controller { return this.setStatus(HttpStatusCode.NO_CONTENT); } + + /** + * @example cabinetName "ตู้เอกสาร 1" + * @example drawerName "ลิ้นชัก 1" + */ + @Get("/{drawerName}/size") + @Tags("ลิ้นชัก") + @Security("bearerAuth") + @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") + public async calc(@Path() cabinetName: string, @Path() drawerName: string) { + const list = await listItem(DEFAULT_BUCKET!, `${cabinetName}/${drawerName}/`, true).catch((e) => + console.error(`Error List Folder: ${e}`), + ); + + if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง"); + + return { size: list.reduce((a, c) => a + c.size, 0) }; + } } diff --git a/Services/server/src/controllers/folderController.ts b/Services/server/src/controllers/folderController.ts index 9a2e663..f1567e8 100644 --- a/Services/server/src/controllers/folderController.ts +++ b/Services/server/src/controllers/folderController.ts @@ -215,4 +215,29 @@ export class FolderController extends Controller { return this.setStatus(HttpStatusCode.NO_CONTENT); } + + /** + * @example cabinetName "ตู้เอกสาร 1" + * @example drawerName "ลิ้นชัก 1" + * @example folderName "แฟ้ม 1" + */ + @Get("/{folderName}/size") + @Tags("แฟ้ม") + @Security("bearerAuth") + @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") + public async calc( + @Path() cabinetName: string, + @Path() drawerName: string, + @Path() folderName: string, + ) { + const list = await listItem( + DEFAULT_BUCKET!, + `${cabinetName}/${drawerName}/${folderName}/`, + true, + ).catch((e) => console.error(`Error List Folder: ${e}`)); + + if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง"); + + return { size: list.reduce((a, c) => a + c.size, 0) }; + } } diff --git a/Services/server/src/controllers/subFolderController.ts b/Services/server/src/controllers/subFolderController.ts index 9199a30..a2d29e2 100644 --- a/Services/server/src/controllers/subFolderController.ts +++ b/Services/server/src/controllers/subFolderController.ts @@ -220,4 +220,31 @@ export class SubFolderController extends Controller { return this.setStatus(HttpStatusCode.NO_CONTENT); } + + /** + * @example cabinetName "ตู้เอกสาร 1" + * @example drawerName "ลิ้นชัก 1" + * @example folderName "แฟ้ม 1" + * @example subFolderName "แฟ้มย่อย 1" + */ + @Get("/{subFolderName}/size") + @Tags("แฟ้มย่อย") + @Security("bearerAuth") + @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") + public async calc( + @Path() cabinetName: string, + @Path() drawerName: string, + @Path() folderName: string, + @Path() subFolderName: string, + ) { + const list = await listItem( + DEFAULT_BUCKET!, + `${cabinetName}/${drawerName}/${folderName}/${subFolderName}`, + true, + ).catch((e) => console.error(`Error List Folder: ${e}`)); + + if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง"); + + return { size: list.reduce((a, c) => a + c.size, 0) }; + } } diff --git a/Services/server/src/routes.ts b/Services/server/src/routes.ts index a056828..7b3897c 100644 --- a/Services/server/src/routes.ts +++ b/Services/server/src/routes.ts @@ -180,6 +180,32 @@ export function RegisterRoutes(app: Router) { } }); // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + app.get('/cabinet/:cabinetName/size', + authenticateMiddleware([{"bearerAuth":[]}]), + ...(fetchMiddlewares(CabinetController)), + ...(fetchMiddlewares(CabinetController.prototype.calc)), + + function CabinetController_calc(request: any, response: any, next: any) { + const args = { + cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, + }; + + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + + let validatedArgs: any[] = []; + try { + validatedArgs = getValidatedArgs(args, request, response); + + const controller = new CabinetController(); + + + const promise = controller.calc.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 200, next); + } catch (err) { + return next(err); + } + }); + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa app.get('/cabinet/:cabinetName/drawer', authenticateMiddleware([{"bearerAuth":[]}]), ...(fetchMiddlewares(DrawerController)), @@ -289,6 +315,33 @@ export function RegisterRoutes(app: Router) { } }); // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + app.get('/cabinet/:cabinetName/drawer/:drawerName/size', + authenticateMiddleware([{"bearerAuth":[]}]), + ...(fetchMiddlewares(DrawerController)), + ...(fetchMiddlewares(DrawerController.prototype.calc)), + + function DrawerController_calc(request: any, response: any, next: any) { + const args = { + cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, + drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, + }; + + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + + let validatedArgs: any[] = []; + try { + validatedArgs = getValidatedArgs(args, request, response); + + const controller = new DrawerController(); + + + const promise = controller.calc.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 200, next); + } catch (err) { + return next(err); + } + }); + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa app.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/file', authenticateMiddleware([{"bearerAuth":[]}]), ...(fetchMiddlewares(FileController)), @@ -549,6 +602,34 @@ export function RegisterRoutes(app: Router) { } }); // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + app.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/size', + authenticateMiddleware([{"bearerAuth":[]}]), + ...(fetchMiddlewares(FolderController)), + ...(fetchMiddlewares(FolderController.prototype.calc)), + + function FolderController_calc(request: any, response: any, next: any) { + const args = { + cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, + drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, + folderName: {"in":"path","name":"folderName","required":true,"dataType":"string"}, + }; + + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + + let validatedArgs: any[] = []; + try { + validatedArgs = getValidatedArgs(args, request, response); + + const controller = new FolderController(); + + + const promise = controller.calc.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 200, next); + } catch (err) { + return next(err); + } + }); + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa app.post('/search', authenticateMiddleware([{"bearerAuth":[]}]), ...(fetchMiddlewares(SearchController)), @@ -692,6 +773,35 @@ export function RegisterRoutes(app: Router) { } }); // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + app.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/subfolder/:subFolderName/size', + authenticateMiddleware([{"bearerAuth":[]}]), + ...(fetchMiddlewares(SubFolderController)), + ...(fetchMiddlewares(SubFolderController.prototype.calc)), + + function SubFolderController_calc(request: any, response: any, next: any) { + const args = { + cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, + drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, + folderName: {"in":"path","name":"folderName","required":true,"dataType":"string"}, + subFolderName: {"in":"path","name":"subFolderName","required":true,"dataType":"string"}, + }; + + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa + + let validatedArgs: any[] = []; + try { + validatedArgs = getValidatedArgs(args, request, response); + + const controller = new SubFolderController(); + + + const promise = controller.calc.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 200, next); + } catch (err) { + return next(err); + } + }); + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa app.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/subfolder/:subFolderName/file', authenticateMiddleware([{"bearerAuth":[]}]), ...(fetchMiddlewares(SubFolderFileController)), diff --git a/Services/server/src/swagger.json b/Services/server/src/swagger.json index 37ab26f..7dd5811 100644 --- a/Services/server/src/swagger.json +++ b/Services/server/src/swagger.json @@ -375,6 +375,51 @@ ] } }, + "/cabinet/{cabinetName}/size": { + "get": { + "operationId": "Calc", + "responses": { + "200": { + "description": "สำเร็จ", + "content": { + "application/json": { + "schema": { + "properties": { + "size": { + "type": "number", + "format": "double" + } + }, + "required": [ + "size" + ], + "type": "object" + } + } + } + } + }, + "tags": [ + "ตู้เอกสาร" + ], + "security": [ + { + "bearerAuth": [] + } + ], + "parameters": [ + { + "in": "path", + "name": "cabinetName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ตู้เอกสาร 1" + } + ] + } + }, "/cabinet/{cabinetName}/drawer": { "get": { "operationId": "ListDrawer", @@ -592,6 +637,60 @@ ] } }, + "/cabinet/{cabinetName}/drawer/{drawerName}/size": { + "get": { + "operationId": "Calc", + "responses": { + "200": { + "description": "สำเร็จ", + "content": { + "application/json": { + "schema": { + "properties": { + "size": { + "type": "number", + "format": "double" + } + }, + "required": [ + "size" + ], + "type": "object" + } + } + } + } + }, + "tags": [ + "ลิ้นชัก" + ], + "security": [ + { + "bearerAuth": [] + } + ], + "parameters": [ + { + "in": "path", + "name": "cabinetName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ตู้เอกสาร 1" + }, + { + "in": "path", + "name": "drawerName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ลิ้นชัก 1" + } + ] + } + }, "/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/file": { "get": { "operationId": "GetFile", @@ -1461,6 +1560,69 @@ ] } }, + "/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/size": { + "get": { + "operationId": "Calc", + "responses": { + "200": { + "description": "สำเร็จ", + "content": { + "application/json": { + "schema": { + "properties": { + "size": { + "type": "number", + "format": "double" + } + }, + "required": [ + "size" + ], + "type": "object" + } + } + } + } + }, + "tags": [ + "แฟ้ม" + ], + "security": [ + { + "bearerAuth": [] + } + ], + "parameters": [ + { + "in": "path", + "name": "cabinetName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ตู้เอกสาร 1" + }, + { + "in": "path", + "name": "drawerName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ลิ้นชัก 1" + }, + { + "in": "path", + "name": "folderName", + "required": true, + "schema": { + "type": "string" + }, + "example": "แฟ้ม 1" + } + ] + } + }, "/search": { "post": { "operationId": "SearchFile", @@ -1788,6 +1950,78 @@ ] } }, + "/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/subfolder/{subFolderName}/size": { + "get": { + "operationId": "Calc", + "responses": { + "200": { + "description": "สำเร็จ", + "content": { + "application/json": { + "schema": { + "properties": { + "size": { + "type": "number", + "format": "double" + } + }, + "required": [ + "size" + ], + "type": "object" + } + } + } + } + }, + "tags": [ + "แฟ้มย่อย" + ], + "security": [ + { + "bearerAuth": [] + } + ], + "parameters": [ + { + "in": "path", + "name": "cabinetName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ตู้เอกสาร 1" + }, + { + "in": "path", + "name": "drawerName", + "required": true, + "schema": { + "type": "string" + }, + "example": "ลิ้นชัก 1" + }, + { + "in": "path", + "name": "folderName", + "required": true, + "schema": { + "type": "string" + }, + "example": "แฟ้ม 1" + }, + { + "in": "path", + "name": "subFolderName", + "required": true, + "schema": { + "type": "string" + }, + "example": "แฟ้มย่อย 1" + } + ] + } + }, "/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/subfolder/{subFolderName}/file": { "get": { "operationId": "GetFile",