feat: add component_types management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-11 10:15:02 +07:00
parent 7c9a0d4670
commit 50564e9b78
14 changed files with 1468 additions and 1 deletions

View File

@@ -15,6 +15,279 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/component-types": {
"get": {
"description": "Retrieve a list of all component types ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "List all component types",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.ComponentType"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component type with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Create a new component type",
"parameters": [
{
"description": "Component type request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentTypeRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentTypeResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-types/{id}": {
"get": {
"description": "Retrieve a single component type using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Get component type by ID",
"parameters": [
{
"type": "integer",
"description": "Component type ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.ComponentType"
}
}
}
]
}
},
"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 type by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Update component type",
"parameters": [
{
"type": "integer",
"description": "Component type ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component type request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentTypeRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentTypeResponse"
}
}
}
]
}
},
"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 type by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Delete component type",
"parameters": [
{
"type": "integer",
"description": "Component type 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"
}
}
}
}
},
"/auth/register": {
"post": {
"description": "Register with email, username and password",
@@ -1489,6 +1762,32 @@ const docTemplate = `{
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"models.Container": {
"type": "object",
"properties": {
@@ -1637,6 +1936,26 @@ const docTemplate = `{
}
}
},
"requests.CreateComponentTypeRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
}
}
},
"requests.CreateContainerRequest": {
"type": "object",
"required": [
@@ -1737,6 +2056,23 @@ const docTemplate = `{
}
}
},
"requests.UpdateComponentTypeRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
}
}
},
"requests.UpdateContainerRequest": {
"type": "object",
"properties": {
@@ -1848,6 +2184,14 @@ const docTemplate = `{
}
}
},
"responses.CreateComponentTypeResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateContainerResponse": {
"type": "object",
"properties": {
@@ -1897,6 +2241,20 @@ const docTemplate = `{
}
}
},
"responses.UpdateComponentTypeResponse": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"responses.UpdateContainerResponse": {
"type": "object",
"properties": {

View File

@@ -9,6 +9,279 @@
"host": "localhost:3000",
"basePath": "/api/v1",
"paths": {
"/api/v1/component-types": {
"get": {
"description": "Retrieve a list of all component types ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "List all component types",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.ComponentType"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component type with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Create a new component type",
"parameters": [
{
"description": "Component type request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentTypeRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentTypeResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/component-types/{id}": {
"get": {
"description": "Retrieve a single component type using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Get component type by ID",
"parameters": [
{
"type": "integer",
"description": "Component type ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.ComponentType"
}
}
}
]
}
},
"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 type by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Update component type",
"parameters": [
{
"type": "integer",
"description": "Component type ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component type request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentTypeRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentTypeResponse"
}
}
}
]
}
},
"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 type by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component-type"
],
"summary": "Delete component type",
"parameters": [
{
"type": "integer",
"description": "Component type 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"
}
}
}
}
},
"/auth/register": {
"post": {
"description": "Register with email, username and password",
@@ -1483,6 +1756,32 @@
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"models.Container": {
"type": "object",
"properties": {
@@ -1631,6 +1930,26 @@
}
}
},
"requests.CreateComponentTypeRequest": {
"type": "object",
"required": [
"name"
],
"properties": {
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
}
}
},
"requests.CreateContainerRequest": {
"type": "object",
"required": [
@@ -1731,6 +2050,23 @@
}
}
},
"requests.UpdateComponentTypeRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"name": {
"type": "string"
}
}
},
"requests.UpdateContainerRequest": {
"type": "object",
"properties": {
@@ -1842,6 +2178,14 @@
}
}
},
"responses.CreateComponentTypeResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateContainerResponse": {
"type": "object",
"properties": {
@@ -1891,6 +2235,20 @@
}
}
},
"responses.UpdateComponentTypeResponse": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"responses.UpdateContainerResponse": {
"type": "object",
"properties": {

View File

@@ -15,6 +15,23 @@ definitions:
updatedAt:
type: string
type: object
models.ComponentType:
properties:
createdAt:
type: string
description:
type: string
id:
type: integer
metadata:
items:
type: integer
type: array
name:
type: string
updatedAt:
type: string
type: object
models.Container:
properties:
containerType:
@@ -113,6 +130,19 @@ definitions:
- name
- roomId
type: object
requests.CreateComponentTypeRequest:
properties:
description:
type: string
metadata:
items:
type: integer
type: array
name:
type: string
required:
- name
type: object
requests.CreateContainerRequest:
properties:
containerType:
@@ -180,6 +210,17 @@ definitions:
name:
type: string
type: object
requests.UpdateComponentTypeRequest:
properties:
description:
type: string
metadata:
items:
type: integer
type: array
name:
type: string
type: object
requests.UpdateContainerRequest:
properties:
containerType:
@@ -252,6 +293,11 @@ definitions:
id:
type: integer
type: object
responses.CreateComponentTypeResponse:
properties:
id:
type: integer
type: object
responses.CreateContainerResponse:
properties:
id:
@@ -283,6 +329,15 @@ definitions:
roomId:
type: integer
type: object
responses.UpdateComponentTypeResponse:
properties:
description:
type: string
id:
type: integer
name:
type: string
type: object
responses.UpdateContainerResponse:
properties:
containerType:
@@ -344,6 +399,176 @@ info:
title: Warehouse Management API
version: "1.0"
paths:
/api/v1/component-types:
get:
consumes:
- application/json
description: Retrieve a list of all component types ordered by creation date
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.ComponentType'
type: array
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: List all component types
tags:
- component-type
post:
consumes:
- application/json
description: Create a new component type with the provided details
parameters:
- description: Component type request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.CreateComponentTypeRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.CreateComponentTypeResponse'
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 type
tags:
- component-type
/api/v1/component-types/{id}:
delete:
consumes:
- application/json
description: Delete a component type by its unique identifier
parameters:
- description: Component type 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 type
tags:
- component-type
get:
consumes:
- application/json
description: Retrieve a single component type using its unique identifier
parameters:
- description: Component type 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.ComponentType'
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 type by ID
tags:
- component-type
put:
consumes:
- application/json
description: Update an existing component type by its ID. Only non-empty fields
will be updated.
parameters:
- description: Component type ID
in: path
name: id
required: true
type: integer
- description: Component type request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.UpdateComponentTypeRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.UpdateComponentTypeResponse'
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 type
tags:
- component-type
/auth/register:
post:
consumes: