diff --git a/database/entities/m_warehouse_entity.go b/database/entities/m_warehouse_entity.go index 8b9147a..0e2bb56 100644 --- a/database/entities/m_warehouse_entity.go +++ b/database/entities/m_warehouse_entity.go @@ -13,8 +13,9 @@ type MWarehouseEntity struct { PICID *uuid.UUID `gorm:"type:uuid;index;" json:"pic_id"` ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"` - Client M_Client `gorm:"foreignKey:ClientID;references:ID"` - PIC M_User `gorm:"foreignKey:PICID;references:ID"` + Client M_Client `gorm:"foreignKey:ClientID;references:ID"` + PIC M_User `gorm:"foreignKey:PICID;references:ID"` + Zonas []MZonaEntity `gorm:"foreignKey:WarehouseID;references:ID"` FullAuditTrail } diff --git a/database/entities/m_zona_entity.go b/database/entities/m_zona_entity.go index 5a6b38e..dc9d017 100644 --- a/database/entities/m_zona_entity.go +++ b/database/entities/m_zona_entity.go @@ -14,9 +14,10 @@ type MZonaEntity struct { WarehouseID uuid.UUID `gorm:"type:uuid;index;" json:"warehouse_id"` ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"` - - Warehouse MWarehouseEntity `gorm:"foreignKey:WarehouseID;references:ID"` - Client M_Client `gorm:"foreignKey:ClientID;references:ID"` + + Warehouse MWarehouseEntity `gorm:"foreignKey:WarehouseID;references:ID"` + Client M_Client `gorm:"foreignKey:ClientID;references:ID"` + Aisles []MAisleEntity `gorm:"foreignKey:ZoneID;references:ID"` FullAuditTrail } diff --git a/modules/warehouse/dto/warehouse_dto.go b/modules/warehouse/dto/warehouse_dto.go index 858ef61..e5282f7 100644 --- a/modules/warehouse/dto/warehouse_dto.go +++ b/modules/warehouse/dto/warehouse_dto.go @@ -46,12 +46,45 @@ type WarehouseUpdateRequest struct { } 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"` + 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:"zones"` +} + +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 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"` } diff --git a/modules/warehouse/repository/warehouse_repository.go b/modules/warehouse/repository/warehouse_repository.go index a198c29..509d210 100644 --- a/modules/warehouse/repository/warehouse_repository.go +++ b/modules/warehouse/repository/warehouse_repository.go @@ -42,6 +42,13 @@ func (r *warehouseRepository) GetById(ctx context.Context, tx *gorm.DB, warehous if err := tx.WithContext(ctx). Preload("Client"). Preload("PIC"). + Preload("Zonas"). + Preload("Zonas.Client"). + Preload("Zonas.Aisles"). + Preload("Zonas.Aisles.Client"). + Preload("Zonas.Aisles.Zona"). + Preload("Zonas.Aisles.DimUom"). + Preload("Zonas.Aisles.WeightUom"). First(&warehouse, "id = ?", warehouseId).Error; err != nil { return warehouse, err } diff --git a/modules/warehouse/service/warehouse_service.go b/modules/warehouse/service/warehouse_service.go index 595bd67..d188928 100644 --- a/modules/warehouse/service/warehouse_service.go +++ b/modules/warehouse/service/warehouse_service.go @@ -43,6 +43,57 @@ func toWarehouseResponse(e entities.MWarehouseEntity) dtodomain.WarehouseRespons } } + zonas := make([]dtodomain.WarehouseZonaResponse, 0) + for _, zona := range e.Zonas { + zonas = append(zonas, dtodomain.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([]dtodomain.ZonaAisleResponse, 0), + }) + for _, aisle := range zona.Aisles { + zonas[len(zonas)-1].Aisles = append(zonas[len(zonas)-1].Aisles, dtodomain.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 dtodomain.WarehouseResponse{ ID: e.ID.String(), Code: e.Code, @@ -52,6 +103,7 @@ func toWarehouseResponse(e entities.MWarehouseEntity) dtodomain.WarehouseRespons DissallowNegativeInventory: e.DissallowNegativeInventory, Client: client, PIC: &pic, + Zonas: zonas, } }