feat: add endpoint and logic for retrieving top exported components, including SQL queries, models, and service integration

This commit is contained in:
Tran Anh Tuan
2026-05-14 11:02:09 +07:00
parent 96bc22942b
commit cee0186225
12 changed files with 431 additions and 4 deletions

View File

@@ -2340,6 +2340,78 @@ const docTemplate = `{
}
}
},
"/v1/dashboard/top-components": {
"get": {
"description": "Retrieve top components by export quantity for chart display",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"dashboard"
],
"summary": "Get top exported components",
"parameters": [
{
"type": "string",
"default": "30d",
"description": "Time period: today, 7d, 30d, this_month",
"name": "period",
"in": "query"
},
{
"type": "integer",
"description": "Filter by warehouse ID",
"name": "warehouse_id",
"in": "query"
},
{
"type": "integer",
"default": 10,
"description": "Number of components to return",
"name": "component_quantities",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.TopExportedComponent"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/dashboard/transactions-chart": {
"get": {
"description": "Retrieve import/export transaction quantities grouped by date for chart display",
@@ -4563,6 +4635,26 @@ const docTemplate = `{
}
}
},
"models.TopExportedComponent": {
"type": "object",
"properties": {
"componentTypeName": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"totalExported": {
"type": "integer"
},
"unit": {
"type": "string"
}
}
},
"models.TotalComponentStats": {
"type": "object",
"properties": {

View File

@@ -2334,6 +2334,78 @@
}
}
},
"/v1/dashboard/top-components": {
"get": {
"description": "Retrieve top components by export quantity for chart display",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"dashboard"
],
"summary": "Get top exported components",
"parameters": [
{
"type": "string",
"default": "30d",
"description": "Time period: today, 7d, 30d, this_month",
"name": "period",
"in": "query"
},
{
"type": "integer",
"description": "Filter by warehouse ID",
"name": "warehouse_id",
"in": "query"
},
{
"type": "integer",
"default": 10,
"description": "Number of components to return",
"name": "component_quantities",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.TopExportedComponent"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/dashboard/transactions-chart": {
"get": {
"description": "Retrieve import/export transaction quantities grouped by date for chart display",
@@ -4557,6 +4629,26 @@
}
}
},
"models.TopExportedComponent": {
"type": "object",
"properties": {
"componentTypeName": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"totalExported": {
"type": "integer"
},
"unit": {
"type": "string"
}
}
},
"models.TotalComponentStats": {
"type": "object",
"properties": {

View File

@@ -345,6 +345,19 @@ definitions:
type:
type: string
type: object
models.TopExportedComponent:
properties:
componentTypeName:
type: string
id:
type: integer
name:
type: string
totalExported:
type: integer
unit:
type: string
type: object
models.TotalComponentStats:
properties:
totalQuantity:
@@ -2562,6 +2575,51 @@ paths:
summary: Get dashboard summary
tags:
- dashboard
/v1/dashboard/top-components:
get:
consumes:
- application/json
description: Retrieve top components by export quantity for chart display
parameters:
- default: 30d
description: 'Time period: today, 7d, 30d, this_month'
in: query
name: period
type: string
- description: Filter by warehouse ID
in: query
name: warehouse_id
type: integer
- default: 10
description: Number of components to return
in: query
name: component_quantities
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.TopExportedComponent'
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 top exported components
tags:
- dashboard
/v1/dashboard/transactions-chart:
get:
consumes: