feat: add component_codes management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-11 11:00:46 +07:00
parent bf20286f04
commit 9ea72b4eea
14 changed files with 1562 additions and 0 deletions

View File

@@ -15,6 +15,279 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/component-codes": {
"get": {
"description": "Retrieve a list of all component codes ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "List all component codes",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.ComponentCode"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component code with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Create a new component code",
"parameters": [
{
"description": "Component code request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentCodeRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentCodeResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-codes/{id}": {
"get": {
"description": "Retrieve a single component code using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Get component code by ID",
"parameters": [
{
"type": "integer",
"description": "Component code ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.ComponentCode"
}
}
}
]
}
},
"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 code by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Update component code",
"parameters": [
{
"type": "integer",
"description": "Component code ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component code request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentCodeRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentCodeResponse"
}
}
}
]
}
},
"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 code by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Delete component code",
"parameters": [
{
"type": "integer",
"description": "Component code 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-types": {
"get": {
"description": "Retrieve a list of all component types ordered by creation date",
@@ -2073,6 +2346,35 @@ const docTemplate = `{
}
}
},
"models.ComponentCode": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"createdAt": {
"type": "string"
},
"id": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
@@ -2247,6 +2549,33 @@ const docTemplate = `{
}
}
},
"requests.CreateComponentCodeRequest": {
"type": "object",
"required": [
"code",
"componentId"
],
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"requests.CreateComponentRequest": {
"type": "object",
"required": [
@@ -2399,6 +2728,29 @@ const docTemplate = `{
}
}
},
"requests.UpdateComponentCodeRequest": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"requests.UpdateComponentRequest": {
"type": "object",
"properties": {
@@ -2553,6 +2905,14 @@ const docTemplate = `{
}
}
},
"responses.CreateComponentCodeResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateComponentResponse": {
"type": "object",
"properties": {
@@ -2618,6 +2978,26 @@ const docTemplate = `{
}
}
},
"responses.UpdateComponentCodeResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
}
}
},
"responses.UpdateComponentResponse": {
"type": "object",
"properties": {

View File

@@ -9,6 +9,279 @@
"host": "localhost:3000",
"basePath": "/api/v1",
"paths": {
"/api/v1/component-codes": {
"get": {
"description": "Retrieve a list of all component codes ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "List all component codes",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.ComponentCode"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component code with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Create a new component code",
"parameters": [
{
"description": "Component code request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentCodeRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentCodeResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-codes/{id}": {
"get": {
"description": "Retrieve a single component code using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Get component code by ID",
"parameters": [
{
"type": "integer",
"description": "Component code ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.ComponentCode"
}
}
}
]
}
},
"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 code by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Update component code",
"parameters": [
{
"type": "integer",
"description": "Component code ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component code request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentCodeRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentCodeResponse"
}
}
}
]
}
},
"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 code by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-code"
],
"summary": "Delete component code",
"parameters": [
{
"type": "integer",
"description": "Component code 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-types": {
"get": {
"description": "Retrieve a list of all component types ordered by creation date",
@@ -2067,6 +2340,35 @@
}
}
},
"models.ComponentCode": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"createdAt": {
"type": "string"
},
"id": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
@@ -2241,6 +2543,33 @@
}
}
},
"requests.CreateComponentCodeRequest": {
"type": "object",
"required": [
"code",
"componentId"
],
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"requests.CreateComponentRequest": {
"type": "object",
"required": [
@@ -2393,6 +2722,29 @@
}
}
},
"requests.UpdateComponentCodeRequest": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"requests.UpdateComponentRequest": {
"type": "object",
"properties": {
@@ -2547,6 +2899,14 @@
}
}
},
"responses.CreateComponentCodeResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateComponentResponse": {
"type": "object",
"properties": {
@@ -2612,6 +2972,26 @@
}
}
},
"responses.UpdateComponentCodeResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"codeType": {
"type": "string"
},
"componentId": {
"type": "integer"
},
"id": {
"type": "integer"
},
"isPrimary": {
"type": "boolean"
}
}
},
"responses.UpdateComponentResponse": {
"type": "object",
"properties": {

View File

@@ -40,6 +40,25 @@ definitions:
updatedAt:
type: string
type: object
models.ComponentCode:
properties:
code:
type: string
codeType:
type: string
componentId:
type: integer
createdAt:
type: string
id:
type: integer
isPrimary:
type: boolean
metadata:
items:
type: integer
type: array
type: object
models.ComponentType:
properties:
createdAt:
@@ -155,6 +174,24 @@ definitions:
- name
- roomId
type: object
requests.CreateComponentCodeRequest:
properties:
code:
type: string
codeType:
type: string
componentId:
type: integer
isPrimary:
type: boolean
metadata:
items:
type: integer
type: array
required:
- code
- componentId
type: object
requests.CreateComponentRequest:
properties:
componentTypeId:
@@ -257,6 +294,21 @@ definitions:
name:
type: string
type: object
requests.UpdateComponentCodeRequest:
properties:
code:
type: string
codeType:
type: string
componentId:
type: integer
isPrimary:
type: boolean
metadata:
items:
type: integer
type: array
type: object
requests.UpdateComponentRequest:
properties:
componentTypeId:
@@ -357,6 +409,11 @@ definitions:
id:
type: integer
type: object
responses.CreateComponentCodeResponse:
properties:
id:
type: integer
type: object
responses.CreateComponentResponse:
properties:
id:
@@ -398,6 +455,19 @@ definitions:
roomId:
type: integer
type: object
responses.UpdateComponentCodeResponse:
properties:
code:
type: string
codeType:
type: string
componentId:
type: integer
id:
type: integer
isPrimary:
type: boolean
type: object
responses.UpdateComponentResponse:
properties:
componentTypeId:
@@ -483,6 +553,176 @@ info:
title: Warehouse Management API
version: "1.0"
paths:
/api/v1/component-codes:
get:
consumes:
- application/json
description: Retrieve a list of all component codes ordered by creation date
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.ComponentCode'
type: array
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: List all component codes
tags:
- component-code
post:
consumes:
- application/json
description: Create a new component code with the provided details
parameters:
- description: Component code request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.CreateComponentCodeRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.CreateComponentCodeResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Create a new component code
tags:
- component-code
/api/v1/component-codes/{id}:
delete:
consumes:
- application/json
description: Delete a component code by its unique identifier
parameters:
- description: Component code ID
in: path
name: id
required: true
type: integer
produces:
- application/json
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'
summary: Delete component code
tags:
- component-code
get:
consumes:
- application/json
description: Retrieve a single component code using its unique identifier
parameters:
- description: Component code ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/models.ComponentCode'
type: object
"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'
summary: Get component code by ID
tags:
- component-code
put:
consumes:
- application/json
description: Update an existing component code by its ID. Only non-empty fields
will be updated.
parameters:
- description: Component code ID
in: path
name: id
required: true
type: integer
- description: Component code request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.UpdateComponentCodeRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.UpdateComponentCodeResponse'
type: object
"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'
summary: Update component code
tags:
- component-code
/api/v1/component-types:
get:
consumes: