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"`
|
||||
BinY string `gorm:"type:varchar(50);" json:"bin_y"`
|
||||
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"`
|
||||
QrCodeAisle string `gorm:"type:text;" json:"qr_code_aisle"`
|
||||
IsActive bool `gorm:"type:boolean;default:true;" json:"is_active"`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
package dto
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"errors"
|
||||
|
||||
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||
)
|
||||
|
||||
const (
|
||||
MESSAGE_FAILED_CREATE_AISLE = "failed create aisle"
|
||||
|
|
@ -27,7 +31,9 @@ type AisleCreateRequest struct {
|
|||
IsleX string `json:"isle_x"`
|
||||
BinY string `json:"bin_y"`
|
||||
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"`
|
||||
QrCodeAisle string `json:"qr_code_aisle"`
|
||||
IsActive bool `json:"is_active"`
|
||||
|
|
@ -43,25 +49,29 @@ type AisleUpdateRequest struct {
|
|||
IsleX string `json:"isle_x"`
|
||||
BinY string `json:"bin_y"`
|
||||
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"`
|
||||
QrCodeAisle string `json:"qr_code_aisle"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
type AisleResponse struct {
|
||||
ID string `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
IsleX string `json:"isle_x"`
|
||||
BinY string `json:"bin_y"`
|
||||
LevelZ string `json:"level_z"`
|
||||
Dimension string `json:"dimension"`
|
||||
Weight string `json:"weight"`
|
||||
QrCodeAisle string `json:"qr_code_aisle"`
|
||||
IsActive bool `json:"is_active"`
|
||||
ZoneID string `json:"zone_id"`
|
||||
DimUomID string `json:"dim_uom_id"`
|
||||
WeightUomID string `json:"weight_uom_id"`
|
||||
ClientID string `json:"client_id"`
|
||||
ID string `json:"id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
IsleX string `json:"isle_x"`
|
||||
BinY string `json:"bin_y"`
|
||||
LevelZ string `json:"level_z"`
|
||||
DimLength string `json:"dim_length"`
|
||||
DimWidth string `json:"dim_width"`
|
||||
DimHeight string `json:"dim_height"`
|
||||
Weight string `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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ func (r *aisleRepository) Update(ctx context.Context, tx *gorm.DB, aisle entitie
|
|||
if tx == nil {
|
||||
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, 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/query"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/aisle/repository"
|
||||
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
|
@ -25,6 +26,30 @@ type aisleService struct {
|
|||
}
|
||||
|
||||
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{
|
||||
ID: e.ID.String(),
|
||||
Code: e.Code,
|
||||
|
|
@ -32,14 +57,16 @@ func toAisleResponse(e entities.MAisleEntity) dto.AisleResponse {
|
|||
IsleX: e.IsleX,
|
||||
BinY: e.BinY,
|
||||
LevelZ: e.LevelZ,
|
||||
Dimension: e.Dimension,
|
||||
DimLength: e.DimLength,
|
||||
DimWidth: e.DimWidth,
|
||||
DimHeight: e.DimHeight,
|
||||
Weight: e.Weight,
|
||||
QrCodeAisle: e.QrCodeAisle,
|
||||
IsActive: e.IsActive,
|
||||
ZoneID: e.ZoneID.String(),
|
||||
DimUomID: e.DimUomID.String(),
|
||||
WeightUomID: e.WeightUomID.String(),
|
||||
ClientID: e.ClientID.String(),
|
||||
Zone: zona,
|
||||
DimUom: dimUom,
|
||||
WeightUom: weightUom,
|
||||
Client: client,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +103,9 @@ func (s *aisleService) Create(ctx context.Context, req dto.AisleCreateRequest) (
|
|||
IsleX: req.IsleX,
|
||||
BinY: req.BinY,
|
||||
LevelZ: req.LevelZ,
|
||||
Dimension: req.Dimension,
|
||||
DimLength: req.DimLength,
|
||||
DimWidth: req.DimWidth,
|
||||
DimHeight: req.DimHeight,
|
||||
Weight: req.Weight,
|
||||
QrCodeAisle: req.QrCodeAisle,
|
||||
IsActive: req.IsActive,
|
||||
|
|
@ -148,8 +177,14 @@ func (s *aisleService) Update(ctx context.Context, req dto.AisleUpdateRequest, a
|
|||
if req.LevelZ != "" {
|
||||
aisle.LevelZ = req.LevelZ
|
||||
}
|
||||
if req.Dimension != "" {
|
||||
aisle.Dimension = req.Dimension
|
||||
if req.DimLength != "" {
|
||||
aisle.DimLength = req.DimLength
|
||||
}
|
||||
if req.DimWidth != "" {
|
||||
aisle.DimWidth = req.DimWidth
|
||||
}
|
||||
if req.DimHeight != "" {
|
||||
aisle.DimHeight = req.DimHeight
|
||||
}
|
||||
if 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
|
||||
}
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue