feat(aisle): Update Aisle entity and DTO to include dimensional fields and improve response structure
This commit is contained in:
parent
6038e52837
commit
3d638530eb
|
|
@ -9,7 +9,9 @@ type MAisleEntity struct {
|
||||||
IsleX string `gorm:"type:varchar(50);" json:"isle_x"`
|
IsleX string `gorm:"type:varchar(50);" json:"isle_x"`
|
||||||
BinY string `gorm:"type:varchar(50);" json:"bin_y"`
|
BinY string `gorm:"type:varchar(50);" json:"bin_y"`
|
||||||
LevelZ string `gorm:"type:varchar(50);" json:"level_z"`
|
LevelZ string `gorm:"type:varchar(50);" json:"level_z"`
|
||||||
Dimension string `gorm:"type:varchar(100);" json:"dimension"`
|
DimLength string `gorm:"type:varchar(100);" json:"dim_length"`
|
||||||
|
DimWidth string `gorm:"type:varchar(100);" json:"dim_width"`
|
||||||
|
DimHeight string `gorm:"type:varchar(100);" json:"dim_height"`
|
||||||
Weight string `gorm:"type:varchar(100);" json:"weight"`
|
Weight string `gorm:"type:varchar(100);" json:"weight"`
|
||||||
QrCodeAisle string `gorm:"type:text;" json:"qr_code_aisle"`
|
QrCodeAisle string `gorm:"type:text;" json:"qr_code_aisle"`
|
||||||
IsActive bool `gorm:"type:boolean;default:true;" json:"is_active"`
|
IsActive bool `gorm:"type:boolean;default:true;" json:"is_active"`
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package dto
|
package dto
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MESSAGE_FAILED_CREATE_AISLE = "failed create aisle"
|
MESSAGE_FAILED_CREATE_AISLE = "failed create aisle"
|
||||||
|
|
@ -27,7 +31,9 @@ type AisleCreateRequest struct {
|
||||||
IsleX string `json:"isle_x"`
|
IsleX string `json:"isle_x"`
|
||||||
BinY string `json:"bin_y"`
|
BinY string `json:"bin_y"`
|
||||||
LevelZ string `json:"level_z"`
|
LevelZ string `json:"level_z"`
|
||||||
Dimension string `json:"dimension"`
|
DimLength string `json:"dim_length"`
|
||||||
|
DimWidth string `json:"dim_width"`
|
||||||
|
DimHeight string `json:"dim_height"`
|
||||||
Weight string `json:"weight"`
|
Weight string `json:"weight"`
|
||||||
QrCodeAisle string `json:"qr_code_aisle"`
|
QrCodeAisle string `json:"qr_code_aisle"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
|
|
@ -43,7 +49,9 @@ type AisleUpdateRequest struct {
|
||||||
IsleX string `json:"isle_x"`
|
IsleX string `json:"isle_x"`
|
||||||
BinY string `json:"bin_y"`
|
BinY string `json:"bin_y"`
|
||||||
LevelZ string `json:"level_z"`
|
LevelZ string `json:"level_z"`
|
||||||
Dimension string `json:"dimension"`
|
DimLength string `json:"dim_length"`
|
||||||
|
DimWidth string `json:"dim_width"`
|
||||||
|
DimHeight string `json:"dim_height"`
|
||||||
Weight string `json:"weight"`
|
Weight string `json:"weight"`
|
||||||
QrCodeAisle string `json:"qr_code_aisle"`
|
QrCodeAisle string `json:"qr_code_aisle"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
|
|
@ -56,12 +64,14 @@ type AisleResponse struct {
|
||||||
IsleX string `json:"isle_x"`
|
IsleX string `json:"isle_x"`
|
||||||
BinY string `json:"bin_y"`
|
BinY string `json:"bin_y"`
|
||||||
LevelZ string `json:"level_z"`
|
LevelZ string `json:"level_z"`
|
||||||
Dimension string `json:"dimension"`
|
DimLength string `json:"dim_length"`
|
||||||
|
DimWidth string `json:"dim_width"`
|
||||||
|
DimHeight string `json:"dim_height"`
|
||||||
Weight string `json:"weight"`
|
Weight string `json:"weight"`
|
||||||
QrCodeAisle string `json:"qr_code_aisle"`
|
QrCodeAisle string `json:"qr_code_aisle"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
ZoneID string `json:"zone_id"`
|
Zone pkgdto.IdNameResponse `json:"zone"`
|
||||||
DimUomID string `json:"dim_uom_id"`
|
DimUom pkgdto.IdNameResponse `json:"dim_uom_id"`
|
||||||
WeightUomID string `json:"weight_uom_id"`
|
WeightUom pkgdto.IdNameResponse `json:"weight_uom_id"`
|
||||||
ClientID string `json:"client_id"`
|
Client pkgdto.IdNameResponse `json:"client_id"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ func (r *aisleRepository) Update(ctx context.Context, tx *gorm.DB, aisle entitie
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
tx = r.db
|
tx = r.db
|
||||||
}
|
}
|
||||||
if err := tx.WithContext(ctx).Save(&aisle).Error; err != nil {
|
if err := tx.WithContext(ctx).Model(&aisle).Where("id = ?", aisle.ID).Select("*").Updates(aisle).Error; err != nil {
|
||||||
return aisle, err
|
return aisle, err
|
||||||
}
|
}
|
||||||
return aisle, nil
|
return aisle, nil
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/dto"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/dto"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/query"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/query"
|
||||||
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/repository"
|
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/repository"
|
||||||
|
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
@ -25,6 +26,30 @@ type aisleService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func toAisleResponse(e entities.MAisleEntity) dto.AisleResponse {
|
func toAisleResponse(e entities.MAisleEntity) dto.AisleResponse {
|
||||||
|
zona := pkgdto.IdNameResponse{}
|
||||||
|
if e.Zona.ID != uuid.Nil {
|
||||||
|
zona.ID = e.Zona.ID.String()
|
||||||
|
zona.Name = e.Zona.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
dimUom := pkgdto.IdNameResponse{}
|
||||||
|
if e.DimUom.ID != uuid.Nil {
|
||||||
|
dimUom.ID = e.DimUom.ID.String()
|
||||||
|
dimUom.Name = e.DimUom.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
weightUom := pkgdto.IdNameResponse{}
|
||||||
|
if e.WeightUom.ID != uuid.Nil {
|
||||||
|
weightUom.ID = e.WeightUom.ID.String()
|
||||||
|
weightUom.Name = e.WeightUom.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
client := pkgdto.IdNameResponse{}
|
||||||
|
if e.Client.ID != uuid.Nil {
|
||||||
|
client.ID = e.Client.ID.String()
|
||||||
|
client.Name = e.Client.Name
|
||||||
|
}
|
||||||
|
|
||||||
return dto.AisleResponse{
|
return dto.AisleResponse{
|
||||||
ID: e.ID.String(),
|
ID: e.ID.String(),
|
||||||
Code: e.Code,
|
Code: e.Code,
|
||||||
|
|
@ -32,14 +57,16 @@ func toAisleResponse(e entities.MAisleEntity) dto.AisleResponse {
|
||||||
IsleX: e.IsleX,
|
IsleX: e.IsleX,
|
||||||
BinY: e.BinY,
|
BinY: e.BinY,
|
||||||
LevelZ: e.LevelZ,
|
LevelZ: e.LevelZ,
|
||||||
Dimension: e.Dimension,
|
DimLength: e.DimLength,
|
||||||
|
DimWidth: e.DimWidth,
|
||||||
|
DimHeight: e.DimHeight,
|
||||||
Weight: e.Weight,
|
Weight: e.Weight,
|
||||||
QrCodeAisle: e.QrCodeAisle,
|
QrCodeAisle: e.QrCodeAisle,
|
||||||
IsActive: e.IsActive,
|
IsActive: e.IsActive,
|
||||||
ZoneID: e.ZoneID.String(),
|
Zone: zona,
|
||||||
DimUomID: e.DimUomID.String(),
|
DimUom: dimUom,
|
||||||
WeightUomID: e.WeightUomID.String(),
|
WeightUom: weightUom,
|
||||||
ClientID: e.ClientID.String(),
|
Client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +103,9 @@ func (s *aisleService) Create(ctx context.Context, req dto.AisleCreateRequest) (
|
||||||
IsleX: req.IsleX,
|
IsleX: req.IsleX,
|
||||||
BinY: req.BinY,
|
BinY: req.BinY,
|
||||||
LevelZ: req.LevelZ,
|
LevelZ: req.LevelZ,
|
||||||
Dimension: req.Dimension,
|
DimLength: req.DimLength,
|
||||||
|
DimWidth: req.DimWidth,
|
||||||
|
DimHeight: req.DimHeight,
|
||||||
Weight: req.Weight,
|
Weight: req.Weight,
|
||||||
QrCodeAisle: req.QrCodeAisle,
|
QrCodeAisle: req.QrCodeAisle,
|
||||||
IsActive: req.IsActive,
|
IsActive: req.IsActive,
|
||||||
|
|
@ -148,8 +177,14 @@ func (s *aisleService) Update(ctx context.Context, req dto.AisleUpdateRequest, a
|
||||||
if req.LevelZ != "" {
|
if req.LevelZ != "" {
|
||||||
aisle.LevelZ = req.LevelZ
|
aisle.LevelZ = req.LevelZ
|
||||||
}
|
}
|
||||||
if req.Dimension != "" {
|
if req.DimLength != "" {
|
||||||
aisle.Dimension = req.Dimension
|
aisle.DimLength = req.DimLength
|
||||||
|
}
|
||||||
|
if req.DimWidth != "" {
|
||||||
|
aisle.DimWidth = req.DimWidth
|
||||||
|
}
|
||||||
|
if req.DimHeight != "" {
|
||||||
|
aisle.DimHeight = req.DimHeight
|
||||||
}
|
}
|
||||||
if req.Weight != "" {
|
if req.Weight != "" {
|
||||||
aisle.Weight = req.Weight
|
aisle.Weight = req.Weight
|
||||||
|
|
@ -164,7 +199,11 @@ func (s *aisleService) Update(ctx context.Context, req dto.AisleUpdateRequest, a
|
||||||
return dto.AisleResponse{}, err
|
return dto.AisleResponse{}, err
|
||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
return toAisleResponse(updated), nil
|
result, err := s.aisleRepo.GetById(ctx, nil, updated.ID.String())
|
||||||
|
if err != nil {
|
||||||
|
return dto.AisleResponse{}, err
|
||||||
|
}
|
||||||
|
return toAisleResponse(result), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *aisleService) Delete(ctx context.Context, aisleId string) error {
|
func (s *aisleService) Delete(ctx context.Context, aisleId string) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue