feat: implement component-item management with CRUD operations and status updates

This commit is contained in:
Tran Anh Tuan
2026-05-11 17:49:18 +07:00
parent 9ea72b4eea
commit 0ff65a18c0
23 changed files with 3870 additions and 0 deletions

View File

@@ -288,6 +288,409 @@ const docTemplate = `{
}
}
},
"/api/v1/component-items": {
"get": {
"description": "Retrieve a list of all component items ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "List all component items",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.ComponentItem"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component item with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "Create a new component item",
"parameters": [
{
"description": "Component item request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentItemRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentItemResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-items/find/{componentId}": {
"get": {
"description": "Retrieve component items with full location details (container, shelf, cabinet, room, warehouse) for a given component ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "Find component items by component ID",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "componentId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.FindComponentItemResult"
}
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-items/{id}": {
"get": {
"description": "Retrieve a single component item using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "Get component item by ID",
"parameters": [
{
"type": "integer",
"description": "Component item ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.ComponentItem"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"put": {
"description": "Update an existing component item by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "Update component item",
"parameters": [
{
"type": "integer",
"description": "Component item ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component item request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentItemRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentItemResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"delete": {
"description": "Delete a component item by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "Delete component item",
"parameters": [
{
"type": "integer",
"description": "Component item ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.SuccessResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-items/{id}/status": {
"put": {
"description": "Change the status of a component item. Supports partial quantity change with automatic split/merge logic. A status history record is created automatically.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-item"
],
"summary": "Change component item status",
"parameters": [
{
"type": "integer",
"description": "Component item ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Status change request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentItemStatusRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentItemStatusResponse"
}
}
}
]
}
},
"400": {
"description": "Validation error (e.g., changed_quantity \u003e quantity, status unchanged)",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"404": {
"description": "Component item not found",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-types": {
"get": {
"description": "Retrieve a list of all component types ordered by creation date",
@@ -2375,6 +2778,38 @@ const docTemplate = `{
}
}
},
"models.ComponentItem": {
"type": "object",
"properties": {
"componentId": {
"type": "integer"
},
"containerId": {
"type": "integer"
},
"createdAt": {
"type": "string"
},
"id": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"quantity": {
"type": "integer"
},
"status": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
@@ -2436,6 +2871,41 @@ const docTemplate = `{
}
}
},
"models.FindComponentItemResult": {
"type": "object",
"properties": {
"cabinetName": {
"type": "string"
},
"componentName": {
"type": "string"
},
"containerName": {
"type": "string"
},
"containerType": {
"type": "string"
},
"quantity": {
"type": "integer"
},
"roomName": {
"type": "string"
},
"shelfName": {
"type": "string"
},
"status": {
"type": "string"
},
"typeName": {
"type": "string"
},
"warehouseName": {
"type": "string"
}
}
},
"models.Room": {
"type": "object",
"properties": {
@@ -2576,6 +3046,35 @@ const docTemplate = `{
}
}
},
"requests.CreateComponentItemRequest": {
"type": "object",
"required": [
"componentId",
"containerId",
"quantity",
"status"
],
"properties": {
"componentId": {
"type": "integer"
},
"containerId": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"quantity": {
"type": "integer"
},
"status": {
"type": "string"
}
}
},
"requests.CreateComponentRequest": {
"type": "object",
"required": [
@@ -2751,6 +3250,47 @@ const docTemplate = `{
}
}
},
"requests.UpdateComponentItemRequest": {
"type": "object",
"properties": {
"componentId": {
"type": "integer"
},
"containerId": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"requests.UpdateComponentItemStatusRequest": {
"type": "object",
"required": [
"status"
],
"properties": {
"changedQuantity": {
"type": "integer"
},
"note": {
"type": "string"
},
"status": {
"type": "string",
"enum": [
"normal",
"damaged",
"long_unused",
"expired",
"pending_inspection"
]
}
}
},
"requests.UpdateComponentRequest": {
"type": "object",
"properties": {
@@ -2913,6 +3453,14 @@ const docTemplate = `{
}
}
},
"responses.CreateComponentItemResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateComponentResponse": {
"type": "object",
"properties": {
@@ -2998,6 +3546,58 @@ const docTemplate = `{
}
}
},
"responses.UpdateComponentItemResponse": {
"type": "object",
"properties": {
"componentId": {
"type": "integer"
},
"containerId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"quantity": {
"type": "integer"
},
"status": {
"type": "string"
}
}
},
"responses.UpdateComponentItemStatusResponse": {
"type": "object",
"properties": {
"changedQuantity": {
"type": "integer"
},
"historyId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"mergedComponentItemId": {
"type": "integer"
},
"newComponentItemId": {
"type": "integer"
},
"newStatus": {
"type": "string"
},
"oldStatus": {
"type": "string"
}
}
},
"responses.UpdateComponentResponse": {
"type": "object",
"properties": {