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

@@ -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: