feat: add components management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-11 10:35:38 +07:00
parent 50564e9b78
commit bf20286f04
15 changed files with 1662 additions and 1 deletions

View File

@@ -288,6 +288,279 @@ const docTemplate = `{
}
}
},
"/api/v1/components": {
"get": {
"description": "Retrieve a list of all components ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "List all components",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Component"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Create a new component",
"parameters": [
{
"description": "Component request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/components/{id}": {
"get": {
"description": "Retrieve a single component using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Get component by ID",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.Component"
}
}
}
]
}
},
"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 by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Update component",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentResponse"
}
}
}
]
}
},
"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 by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Delete component",
"parameters": [
{
"type": "integer",
"description": "Component 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",
@@ -1762,6 +2035,44 @@ const docTemplate = `{
}
}
},
"models.Component": {
"type": "object",
"properties": {
"componentTypeId": {
"type": "integer"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"totalQuantity": {
"type": "integer"
},
"unit": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
@@ -1936,6 +2247,38 @@ const docTemplate = `{
}
}
},
"requests.CreateComponentRequest": {
"type": "object",
"required": [
"componentTypeId",
"minQuantity",
"name",
"unit"
],
"properties": {
"componentTypeId": {
"type": "integer"
},
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
}
}
},
"requests.CreateComponentTypeRequest": {
"type": "object",
"required": [
@@ -2056,6 +2399,32 @@ const docTemplate = `{
}
}
},
"requests.UpdateComponentRequest": {
"type": "object",
"properties": {
"componentTypeId": {
"type": "integer"
},
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
}
}
},
"requests.UpdateComponentTypeRequest": {
"type": "object",
"properties": {
@@ -2184,6 +2553,14 @@ const docTemplate = `{
}
}
},
"responses.CreateComponentResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateComponentTypeResponse": {
"type": "object",
"properties": {
@@ -2241,6 +2618,29 @@ const docTemplate = `{
}
}
},
"responses.UpdateComponentResponse": {
"type": "object",
"properties": {
"componentTypeId": {
"type": "integer"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
}
}
},
"responses.UpdateComponentTypeResponse": {
"type": "object",
"properties": {

View File

@@ -282,6 +282,279 @@
}
}
},
"/api/v1/components": {
"get": {
"description": "Retrieve a list of all components ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "List all components",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Component"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new component with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Create a new component",
"parameters": [
{
"description": "Component request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateComponentRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateComponentResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/api/v1/components/{id}": {
"get": {
"description": "Retrieve a single component using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Get component by ID",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.Component"
}
}
}
]
}
},
"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 by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Update component",
"parameters": [
{
"type": "integer",
"description": "Component ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Component request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateComponentRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateComponentResponse"
}
}
}
]
}
},
"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 by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"component"
],
"summary": "Delete component",
"parameters": [
{
"type": "integer",
"description": "Component 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",
@@ -1756,6 +2029,44 @@
}
}
},
"models.Component": {
"type": "object",
"properties": {
"componentTypeId": {
"type": "integer"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"totalQuantity": {
"type": "integer"
},
"unit": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"models.ComponentType": {
"type": "object",
"properties": {
@@ -1930,6 +2241,38 @@
}
}
},
"requests.CreateComponentRequest": {
"type": "object",
"required": [
"componentTypeId",
"minQuantity",
"name",
"unit"
],
"properties": {
"componentTypeId": {
"type": "integer"
},
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
}
}
},
"requests.CreateComponentTypeRequest": {
"type": "object",
"required": [
@@ -2050,6 +2393,32 @@
}
}
},
"requests.UpdateComponentRequest": {
"type": "object",
"properties": {
"componentTypeId": {
"type": "integer"
},
"description": {
"type": "string"
},
"metadata": {
"type": "array",
"items": {
"type": "integer"
}
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
}
}
},
"requests.UpdateComponentTypeRequest": {
"type": "object",
"properties": {
@@ -2178,6 +2547,14 @@
}
}
},
"responses.CreateComponentResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateComponentTypeResponse": {
"type": "object",
"properties": {
@@ -2235,6 +2612,29 @@
}
}
},
"responses.UpdateComponentResponse": {
"type": "object",
"properties": {
"componentTypeId": {
"type": "integer"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"minQuantity": {
"type": "integer"
},
"name": {
"type": "string"
},
"unit": {
"type": "string"
}
}
},
"responses.UpdateComponentTypeResponse": {
"type": "object",
"properties": {

View File

@@ -15,6 +15,31 @@ definitions:
updatedAt:
type: string
type: object
models.Component:
properties:
componentTypeId:
type: integer
createdAt:
type: string
description:
type: string
id:
type: integer
metadata:
items:
type: integer
type: array
minQuantity:
type: integer
name:
type: string
totalQuantity:
type: integer
unit:
type: string
updatedAt:
type: string
type: object
models.ComponentType:
properties:
createdAt:
@@ -130,6 +155,28 @@ definitions:
- name
- roomId
type: object
requests.CreateComponentRequest:
properties:
componentTypeId:
type: integer
description:
type: string
metadata:
items:
type: integer
type: array
minQuantity:
type: integer
name:
type: string
unit:
type: string
required:
- componentTypeId
- minQuantity
- name
- unit
type: object
requests.CreateComponentTypeRequest:
properties:
description:
@@ -210,6 +257,23 @@ definitions:
name:
type: string
type: object
requests.UpdateComponentRequest:
properties:
componentTypeId:
type: integer
description:
type: string
metadata:
items:
type: integer
type: array
minQuantity:
type: integer
name:
type: string
unit:
type: string
type: object
requests.UpdateComponentTypeRequest:
properties:
description:
@@ -293,6 +357,11 @@ definitions:
id:
type: integer
type: object
responses.CreateComponentResponse:
properties:
id:
type: integer
type: object
responses.CreateComponentTypeResponse:
properties:
id:
@@ -329,6 +398,21 @@ definitions:
roomId:
type: integer
type: object
responses.UpdateComponentResponse:
properties:
componentTypeId:
type: integer
description:
type: string
id:
type: integer
minQuantity:
type: integer
name:
type: string
unit:
type: string
type: object
responses.UpdateComponentTypeResponse:
properties:
description:
@@ -569,6 +653,176 @@ paths:
summary: Update component type
tags:
- component-type
/api/v1/components:
get:
consumes:
- application/json
description: Retrieve a list of all components ordered by creation date
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.Component'
type: array
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: List all components
tags:
- component
post:
consumes:
- application/json
description: Create a new component with the provided details
parameters:
- description: Component request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.CreateComponentRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.CreateComponentResponse'
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
tags:
- component
/api/v1/components/{id}:
delete:
consumes:
- application/json
description: Delete a component by its unique identifier
parameters:
- description: Component 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
tags:
- component
get:
consumes:
- application/json
description: Retrieve a single component using its unique identifier
parameters:
- description: Component 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.Component'
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 by ID
tags:
- component
put:
consumes:
- application/json
description: Update an existing component by its ID. Only non-empty fields will
be updated.
parameters:
- description: Component ID
in: path
name: id
required: true
type: integer
- description: Component request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.UpdateComponentRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.UpdateComponentResponse'
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
tags:
- component
/auth/register:
post:
consumes: