Base Project

This commit is contained in:
Tran Anh Tuan
2026-05-08 14:32:24 +07:00
parent 5a9249c9ea
commit 6a4a96e0ca
74 changed files with 6749 additions and 0 deletions

526
docs/swagger/docs.go Normal file
View File

@@ -0,0 +1,526 @@
// Package swagger Code generated by swaggo/swag. DO NOT EDIT
package swagger
import "github.com/swaggo/swag"
const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/auth/register": {
"post": {
"description": "Register with email, username and password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Register a new user",
"parameters": [
{
"description": "Register request",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.BodyRegisterRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.BodyRegisterResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"409": {
"description": "Conflict",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/ping": {
"get": {
"description": "Check server is running",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"health"
],
"summary": "Health check",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/v1/warehouses": {
"get": {
"description": "Retrieve a list of all warehouses ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "List all warehouses",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Warehouse"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new warehouse with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Create a new warehouse",
"parameters": [
{
"description": "Warehouse request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CUWarehouseRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateWarehouseResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/warehouses/{id}": {
"get": {
"description": "Retrieve a single warehouse using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Get warehouse by ID",
"parameters": [
{
"type": "integer",
"description": "Warehouse ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.Warehouse"
}
}
}
]
}
},
"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 warehouse by its ID with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Update warehouse",
"parameters": [
{
"type": "integer",
"description": "Warehouse ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Warehouse request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CUWarehouseRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateWarehouseResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"delete": {
"description": "Delete a warehouse by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Delete warehouse",
"parameters": [
{
"type": "integer",
"description": "Warehouse 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"
}
}
}
}
}
},
"definitions": {
"models.Warehouse": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"requests.BodyRegisterRequest": {
"type": "object",
"required": [
"email",
"password",
"username"
],
"properties": {
"email": {
"type": "string"
},
"fullName": {
"type": "string"
},
"password": {
"type": "string",
"minLength": 8
},
"username": {
"type": "string"
}
}
},
"requests.CUWarehouseRequest": {
"type": "object",
"required": [
"address",
"name"
],
"properties": {
"address": {
"type": "string"
},
"description": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"response.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
},
"now": {
"type": "integer"
},
"status": {
"type": "integer"
}
}
},
"response.SuccessResponse": {
"type": "object",
"properties": {
"data": {},
"message": {
"type": "string"
},
"option": {},
"reason_status_code": {
"type": "string"
},
"status": {
"type": "integer"
}
}
},
"responses.BodyRegisterResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"responses.CreateWarehouseResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.UpdateWarehouseResponse": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "localhost:3000",
BasePath: "/api/v1",
Schemes: []string{},
Title: "Warehouse Management API",
Description: "This is the Warehouse Management API server.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}

502
docs/swagger/swagger.json Normal file
View File

@@ -0,0 +1,502 @@
{
"swagger": "2.0",
"info": {
"description": "This is the Warehouse Management API server.",
"title": "Warehouse Management API",
"contact": {},
"version": "1.0"
},
"host": "localhost:3000",
"basePath": "/api/v1",
"paths": {
"/auth/register": {
"post": {
"description": "Register with email, username and password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"auth"
],
"summary": "Register a new user",
"parameters": [
{
"description": "Register request",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.BodyRegisterRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.BodyRegisterResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"409": {
"description": "Conflict",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/ping": {
"get": {
"description": "Check server is running",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"health"
],
"summary": "Health check",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/v1/warehouses": {
"get": {
"description": "Retrieve a list of all warehouses ordered by creation date",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "List all warehouses",
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Warehouse"
}
}
}
}
]
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"post": {
"description": "Create a new warehouse with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Create a new warehouse",
"parameters": [
{
"description": "Warehouse request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CUWarehouseRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.CreateWarehouseResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
}
},
"/v1/warehouses/{id}": {
"get": {
"description": "Retrieve a single warehouse using its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Get warehouse by ID",
"parameters": [
{
"type": "integer",
"description": "Warehouse ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.Warehouse"
}
}
}
]
}
},
"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 warehouse by its ID with the provided details",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Update warehouse",
"parameters": [
{
"type": "integer",
"description": "Warehouse ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Warehouse request body",
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/requests.CUWarehouseRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/response.SuccessResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/responses.UpdateWarehouseResponse"
}
}
}
]
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrorResponse"
}
}
}
},
"delete": {
"description": "Delete a warehouse by its unique identifier",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"warehouse"
],
"summary": "Delete warehouse",
"parameters": [
{
"type": "integer",
"description": "Warehouse 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"
}
}
}
}
}
},
"definitions": {
"models.Warehouse": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"createdAt": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"requests.BodyRegisterRequest": {
"type": "object",
"required": [
"email",
"password",
"username"
],
"properties": {
"email": {
"type": "string"
},
"fullName": {
"type": "string"
},
"password": {
"type": "string",
"minLength": 8
},
"username": {
"type": "string"
}
}
},
"requests.CUWarehouseRequest": {
"type": "object",
"required": [
"address",
"name"
],
"properties": {
"address": {
"type": "string"
},
"description": {
"type": "string"
},
"name": {
"type": "string"
}
}
},
"response.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer"
},
"message": {
"type": "string"
},
"now": {
"type": "integer"
},
"status": {
"type": "integer"
}
}
},
"response.SuccessResponse": {
"type": "object",
"properties": {
"data": {},
"message": {
"type": "string"
},
"option": {},
"reason_status_code": {
"type": "string"
},
"status": {
"type": "integer"
}
}
},
"responses.BodyRegisterResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
},
"responses.CreateWarehouseResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
},
"responses.UpdateWarehouseResponse": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"description": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
}
}
}

317
docs/swagger/swagger.yaml Normal file
View File

@@ -0,0 +1,317 @@
basePath: /api/v1
definitions:
models.Warehouse:
properties:
address:
type: string
createdAt:
type: string
description:
type: string
id:
type: integer
name:
type: string
updatedAt:
type: string
type: object
requests.BodyRegisterRequest:
properties:
email:
type: string
fullName:
type: string
password:
minLength: 8
type: string
username:
type: string
required:
- email
- password
- username
type: object
requests.CUWarehouseRequest:
properties:
address:
type: string
description:
type: string
name:
type: string
required:
- address
- name
type: object
response.ErrorResponse:
properties:
code:
type: integer
message:
type: string
now:
type: integer
status:
type: integer
type: object
response.SuccessResponse:
properties:
data: {}
message:
type: string
option: {}
reason_status_code:
type: string
status:
type: integer
type: object
responses.BodyRegisterResponse:
properties:
id:
type: string
type: object
responses.CreateWarehouseResponse:
properties:
id:
type: integer
type: object
responses.UpdateWarehouseResponse:
properties:
address:
type: string
description:
type: string
id:
type: integer
name:
type: string
type: object
host: localhost:3000
info:
contact: {}
description: This is the Warehouse Management API server.
title: Warehouse Management API
version: "1.0"
paths:
/auth/register:
post:
consumes:
- application/json
description: Register with email, username and password
parameters:
- description: Register request
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.BodyRegisterRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.BodyRegisterResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"409":
description: Conflict
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Register a new user
tags:
- auth
/ping:
get:
consumes:
- application/json
description: Check server is running
produces:
- application/json
responses:
"200":
description: OK
schema:
additionalProperties:
type: string
type: object
summary: Health check
tags:
- health
/v1/warehouses:
get:
consumes:
- application/json
description: Retrieve a list of all warehouses ordered by creation date
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
items:
$ref: '#/definitions/models.Warehouse'
type: array
type: object
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: List all warehouses
tags:
- warehouse
post:
consumes:
- application/json
description: Create a new warehouse with the provided details
parameters:
- description: Warehouse request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.CUWarehouseRequest'
produces:
- application/json
responses:
"201":
description: Created
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.CreateWarehouseResponse'
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 warehouse
tags:
- warehouse
/v1/warehouses/{id}:
delete:
consumes:
- application/json
description: Delete a warehouse by its unique identifier
parameters:
- description: Warehouse 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 warehouse
tags:
- warehouse
get:
consumes:
- application/json
description: Retrieve a single warehouse using its unique identifier
parameters:
- description: Warehouse 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.Warehouse'
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 warehouse by ID
tags:
- warehouse
put:
consumes:
- application/json
description: Update an existing warehouse by its ID with the provided details
parameters:
- description: Warehouse ID
in: path
name: id
required: true
type: integer
- description: Warehouse request body
in: body
name: body
required: true
schema:
$ref: '#/definitions/requests.CUWarehouseRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/response.SuccessResponse'
- properties:
data:
$ref: '#/definitions/responses.UpdateWarehouseResponse'
type: object
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrorResponse'
summary: Update warehouse
tags:
- warehouse
swagger: "2.0"