feat: add cabinet management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-08 15:26:31 +07:00
parent 459ff6b384
commit 58cfe890a1
14 changed files with 1981 additions and 856 deletions

View File

@@ -105,6 +105,279 @@ const docTemplate = `{
}
}
},
"/v1/cabinets": {
"get": {
"description": "Retrieve a list of all cabinets ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cabinet"
],
"summary": "List all cabinets",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Cabinet"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new cabinet with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cabinet"
],
"summary": "Create a new cabinet",
"parameters": [
{
"description": "Cabinet request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CreateCabinetRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateCabinetResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/cabinets/{id}": {
"get": {
"description": "Retrieve a single cabinet using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cabinet"
],
"summary": "Get cabinet by ID",
"parameters": [
{
"type": "integer",
"description": "Cabinet ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.Cabinet"
}
}
}
]
}
},
"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 cabinet by its ID. Only non-empty fields will be updated.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cabinet"
],
"summary": "Update cabinet",
"parameters": [
{
"type": "integer",
"description": "Cabinet ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Cabinet request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.UpdateCabinetRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateCabinetResponse"
}
}
}
]
}
},
"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 cabinet by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"cabinet"
],
"summary": "Delete cabinet",
"parameters": [
{
"type": "integer",
"description": "Cabinet 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"
}
}
}
}
},
"/v1/rooms": {
"get": {
"description": "Retrieve a list of all rooms ordered by creation date",
@@ -647,6 +920,29 @@ const docTemplate = `{
}
},
"definitions": {
"models.Cabinet": {
"type": "object",
"properties": {
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"roomId": {
"type": "integer"
},
"updatedAt": {
"type": "string"
}
}
},
"models.Room": {
"type": "object",
"properties": {
@@ -716,6 +1012,24 @@ const docTemplate = `{
}
}
},
"requests.CreateCabinetRequest": {
"type": "object",
"required": [
"name",
"roomId"
],
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
},
"roomId": {
"type": "integer"
}
}
},
"requests.CreateRoomRequest": {
"type": "object",
"required": [
@@ -752,6 +1066,17 @@ const docTemplate = `{
}
}
},
"requests.UpdateCabinetRequest": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"requests.UpdateRoomRequest": {
"type": "object",
"properties": {
@@ -818,6 +1143,14 @@ const docTemplate = `{
}
}
},
"responses.CreateCabinetResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.CreateRoomResponse": {
"type": "object",
"properties": {
@@ -834,6 +1167,23 @@ const docTemplate = `{
}
}
},
"responses.UpdateCabinetResponse": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"roomId": {
"type": "integer"
}
}
},
"responses.UpdateRoomResponse": {
"type": "object",
"properties": {

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,20 @@
basePath: /api/v1
definitions:
models.Cabinet:
properties:
createdAt:
type: string
description:
type: string
id:
type: integer
name:
type: string
roomId:
type: integer
updatedAt:
type: string
type: object
models.Room:
properties:
createdAt:
@@ -46,6 +61,18 @@ definitions:
- password
- username
type: object
requests.CreateCabinetRequest:
properties:
description:
type: string
name:
type: string
roomId:
type: integer
required:
- name
- roomId
type: object
requests.CreateRoomRequest:
properties:
description:
@@ -70,6 +97,13 @@ definitions:
- address
- name
type: object
requests.UpdateCabinetRequest:
properties:
description:
type: string
name:
type: string
type: object
requests.UpdateRoomRequest:
properties:
description:
@@ -113,6 +147,11 @@ definitions:
id:
type: string
type: object
responses.CreateCabinetResponse:
properties:
id:
type: integer
type: object
responses.CreateRoomResponse:
properties:
id:
@@ -123,6 +162,17 @@ definitions:
id:
type: integer
type: object
responses.UpdateCabinetResponse:
properties:
description:
type: string
id:
type: integer
name:
type: string
roomId:
type: integer
type: object
responses.UpdateRoomResponse:
properties:
description:
@@ -208,6 +258,176 @@ paths:
summary: Health check
tags:
- health
/v1/cabinets:
get:
consumes:
- application/json
description: Retrieve a list of all cabinets ordered by creation date
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.Cabinet'
type: array
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: List all cabinets
tags:
- cabinet
post:
consumes:
- application/json
description: Create a new cabinet with the provided details
parameters:
- description: Cabinet request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.CreateCabinetRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.CreateCabinetResponse'
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 cabinet
tags:
- cabinet
/v1/cabinets/{id}:
delete:
consumes:
- application/json
description: Delete a cabinet by its unique identifier
parameters:
- description: Cabinet 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 cabinet
tags:
- cabinet
get:
consumes:
- application/json
description: Retrieve a single cabinet using its unique identifier
parameters:
- description: Cabinet 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.Cabinet'
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 cabinet by ID
tags:
- cabinet
put:
consumes:
- application/json
description: Update an existing cabinet by its ID. Only non-empty fields will
be updated.
parameters:
- description: Cabinet ID
in: path
name: id
required: true
type: integer
- description: Cabinet request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.UpdateCabinetRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.UpdateCabinetResponse'
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 cabinet
tags:
- cabinet
/v1/rooms:
get:
consumes: