feat: add endpoints and logic for retrieving warehouse space usage and status distribution, including SQL queries, models, and service integration

This commit is contained in:
Tran Anh Tuan
2026-05-14 11:44:39 +07:00
parent cee0186225
commit 84ef7d446e
11 changed files with 612 additions and 0 deletions

View File

@@ -2247,6 +2247,122 @@ const docTemplate = `{
}
}
},
"/v1/dashboard/space-usage": {
"get": {
"description": "Retrieve warehouse space usage statistics showing total vs used containers per room",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"dashboard"
],
"summary": "Get space usage",
"parameters": [
{
"type": "integer",
"description": "Filter by warehouse ID",
"name": "warehouse_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.SpaceUsageItem"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/dashboard/status-distribution": {
"get": {
"description": "Retrieve component items count grouped by status (normal, damaged, expired, etc.)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"dashboard"
],
"summary": "Get status distribution",
"parameters": [
{
"type": "integer",
"description": "Filter by warehouse ID",
"name": "warehouse_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.StatusDistributionItem"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/dashboard/stock-alerts": {
"get": {
"description": "Retrieve list of components that are low on stock (total_quantity \u003c= min_quantity)",
@@ -4598,6 +4714,37 @@ const docTemplate = `{
}
}
},
"models.SpaceUsageItem": {
"type": "object",
"properties": {
"room": {
"type": "string"
},
"totalContainers": {
"type": "integer"
},
"usedContainers": {
"type": "integer"
},
"warehouse": {
"type": "string"
}
}
},
"models.StatusDistributionItem": {
"type": "object",
"properties": {
"count": {
"type": "integer"
},
"status": {
"type": "string"
},
"totalQuantity": {
"type": "integer"
}
}
},
"models.StockAlert": {
"type": "object",
"properties": {

View File

@@ -2241,6 +2241,122 @@
}
}
},
"/v1/dashboard/space-usage": {
"get": {
"description": "Retrieve warehouse space usage statistics showing total vs used containers per room",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"dashboard"
],
"summary": "Get space usage",
"parameters": [
{
"type": "integer",
"description": "Filter by warehouse ID",
"name": "warehouse_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.SpaceUsageItem"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/dashboard/status-distribution": {
"get": {
"description": "Retrieve component items count grouped by status (normal, damaged, expired, etc.)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"dashboard"
],
"summary": "Get status distribution",
"parameters": [
{
"type": "integer",
"description": "Filter by warehouse ID",
"name": "warehouse_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.StatusDistributionItem"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/dashboard/stock-alerts": {
"get": {
"description": "Retrieve list of components that are low on stock (total_quantity \u003c= min_quantity)",
@@ -4592,6 +4708,37 @@
}
}
},
"models.SpaceUsageItem": {
"type": "object",
"properties": {
"room": {
"type": "string"
},
"totalContainers": {
"type": "integer"
},
"usedContainers": {
"type": "integer"
},
"warehouse": {
"type": "string"
}
}
},
"models.StatusDistributionItem": {
"type": "object",
"properties": {
"count": {
"type": "integer"
},
"status": {
"type": "string"
},
"totalQuantity": {
"type": "integer"
}
}
},
"models.StockAlert": {
"type": "object",
"properties": {

View File

@@ -321,6 +321,26 @@ definitions:
updatedAt:
type: string
type: object
models.SpaceUsageItem:
properties:
room:
type: string
totalContainers:
type: integer
usedContainers:
type: integer
warehouse:
type: string
type: object
models.StatusDistributionItem:
properties:
count:
type: integer
status:
type: string
totalQuantity:
type: integer
type: object
models.StockAlert:
properties:
componentTypeId:
@@ -2519,6 +2539,78 @@ paths:
summary: Get anomaly items
tags:
- dashboard
/v1/dashboard/space-usage:
get:
consumes:
- application/json
description: Retrieve warehouse space usage statistics showing total vs used
containers per room
parameters:
- description: Filter by warehouse ID
in: query
name: warehouse_id
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.SpaceUsageItem'
type: array
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Get space usage
tags:
- dashboard
/v1/dashboard/status-distribution:
get:
consumes:
- application/json
description: Retrieve component items count grouped by status (normal, damaged,
expired, etc.)
parameters:
- description: Filter by warehouse ID
in: query
name: warehouse_id
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.StatusDistributionItem'
type: array
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Get status distribution
tags:
- dashboard
/v1/dashboard/stock-alerts:
get:
consumes: