174 lines
6.2 KiB
Go
174 lines
6.2 KiB
Go
package dto
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
|
|
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const (
|
|
MESSAGE_FAILED_CREATE_WAREHOUSE = "failed create warehouse"
|
|
MESSAGE_SUCCESS_CREATE_WAREHOUSE = "success create warehouse"
|
|
MESSAGE_FAILED_GET_WAREHOUSE = "failed get warehouse"
|
|
MESSAGE_SUCCESS_GET_WAREHOUSE = "success get warehouse"
|
|
MESSAGE_FAILED_UPDATE_WAREHOUSE = "failed update warehouse"
|
|
MESSAGE_SUCCESS_UPDATE_WAREHOUSE = "success update warehouse"
|
|
MESSAGE_FAILED_DELETE_WAREHOUSE = "failed delete warehouse"
|
|
MESSAGE_SUCCESS_DELETE_WAREHOUSE = "success delete warehouse"
|
|
MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body"
|
|
)
|
|
|
|
var (
|
|
ErrCreateWarehouse = errors.New("failed to create warehouse")
|
|
ErrGetWarehouseById = errors.New("failed to get warehouse by id")
|
|
ErrUpdateWarehouse = errors.New("failed to update warehouse")
|
|
ErrDeleteWarehouse = errors.New("failed to delete warehouse")
|
|
)
|
|
|
|
type WarehouseCreateRequest struct {
|
|
Code string `json:"code" binding:"required"`
|
|
Name string `json:"name" binding:"required"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status" binding:"required"`
|
|
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
|
PICID *string `json:"pic_id"`
|
|
ClientID string `json:"client_id" binding:"required"`
|
|
}
|
|
|
|
type WarehouseUpdateRequest struct {
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status"`
|
|
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
|
PICID *string `json:"pic_id"`
|
|
ClientID string `json:"client_id"`
|
|
}
|
|
|
|
type WarehouseResponse struct {
|
|
ID string `json:"id"`
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Status string `json:"status"`
|
|
DissallowNegativeInventory bool `json:"dissallow_negative_inventory"`
|
|
Client pkgdto.IdNameResponse `json:"client"`
|
|
PIC *pkgdto.IdNameResponse `json:"pic"`
|
|
Zonas []WarehouseZonaResponse `json:"zonas"`
|
|
}
|
|
|
|
type WarehouseZonaResponse struct {
|
|
ID string `json:"id"`
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"`
|
|
Temperature string `json:"temperature"`
|
|
Hazardous bool `json:"hazardous"`
|
|
QRCodeZone string `json:"qr_code_zone"`
|
|
IsActive bool `json:"is_active"`
|
|
Client pkgdto.IdNameResponse `json:"client"`
|
|
Aisles []ZonaAisleResponse `json:"aisles"`
|
|
}
|
|
|
|
type ZonaAisleResponse struct {
|
|
ID string `json:"id"`
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
IsleX int `json:"isle_x"`
|
|
BinY int `json:"bin_y"`
|
|
LevelZ int `json:"level_z"`
|
|
DimLength float64 `json:"dim_length"`
|
|
DimWidth float64 `json:"dim_width"`
|
|
DimHeight float64 `json:"dim_height"`
|
|
Weight float64 `json:"weight"`
|
|
QrCodeAisle string `json:"qr_code_aisle"`
|
|
IsActive bool `json:"is_active"`
|
|
Zone pkgdto.IdNameResponse `json:"zone"`
|
|
DimUom pkgdto.IdNameResponse `json:"dim_uom_id"`
|
|
WeightUom pkgdto.IdNameResponse `json:"weight_uom_id"`
|
|
Client pkgdto.IdNameResponse `json:"client_id"`
|
|
}
|
|
|
|
func ToWarehouseResponse(e entities.MWarehouseEntity) WarehouseResponse {
|
|
client := pkgdto.IdNameResponse{}
|
|
if e.Client.ID != uuid.Nil {
|
|
client = pkgdto.IdNameResponse{
|
|
ID: e.Client.ID.String(),
|
|
Name: e.Client.Name,
|
|
}
|
|
}
|
|
|
|
pic := pkgdto.IdNameResponse{}
|
|
if e.PIC.ID != uuid.Nil {
|
|
pic = pkgdto.IdNameResponse{
|
|
ID: e.PIC.ID.String(),
|
|
Name: e.PIC.Name,
|
|
}
|
|
}
|
|
|
|
zonas := make([]WarehouseZonaResponse, 0)
|
|
for _, zona := range e.Zonas {
|
|
zonas = append(zonas, WarehouseZonaResponse{
|
|
ID: zona.ID.String(),
|
|
Code: zona.Code,
|
|
Name: zona.Name,
|
|
Type: zona.Type,
|
|
Temperature: zona.Temperature,
|
|
Hazardous: zona.Hazardous,
|
|
QRCodeZone: zona.QRCodeZone,
|
|
IsActive: zona.IsActive,
|
|
Client: pkgdto.IdNameResponse{
|
|
ID: zona.Client.ID.String(),
|
|
Name: zona.Client.Name,
|
|
},
|
|
Aisles: make([]ZonaAisleResponse, 0),
|
|
})
|
|
for _, aisle := range zona.Aisles {
|
|
zonas[len(zonas)-1].Aisles = append(zonas[len(zonas)-1].Aisles, ZonaAisleResponse{
|
|
ID: aisle.ID.String(),
|
|
Code: aisle.Code,
|
|
Name: aisle.Name,
|
|
IsleX: aisle.IsleX,
|
|
BinY: aisle.BinY,
|
|
LevelZ: aisle.LevelZ,
|
|
DimLength: aisle.DimLength,
|
|
DimWidth: aisle.DimWidth,
|
|
DimHeight: aisle.DimHeight,
|
|
Weight: aisle.Weight,
|
|
QrCodeAisle: aisle.QrCodeAisle,
|
|
IsActive: aisle.IsActive,
|
|
Zone: pkgdto.IdNameResponse{
|
|
ID: aisle.Zona.ID.String(),
|
|
Name: aisle.Zona.Name,
|
|
},
|
|
DimUom: pkgdto.IdNameResponse{
|
|
ID: aisle.DimUom.ID.String(),
|
|
Name: aisle.DimUom.Name,
|
|
},
|
|
WeightUom: pkgdto.IdNameResponse{
|
|
ID: aisle.WeightUom.ID.String(),
|
|
Name: aisle.WeightUom.Name,
|
|
},
|
|
Client: pkgdto.IdNameResponse{
|
|
ID: aisle.Client.ID.String(),
|
|
Name: aisle.Client.Name,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
|
|
return WarehouseResponse{
|
|
ID: e.ID.String(),
|
|
Code: e.Code,
|
|
Name: e.Name,
|
|
Description: e.Description,
|
|
Status: e.Status,
|
|
DissallowNegativeInventory: e.DissallowNegativeInventory,
|
|
Client: client,
|
|
PIC: &pic,
|
|
Zonas: zonas,
|
|
}
|
|
}
|