feat(warehouse): Enhance Warehouse entity and DTO to include Zonas and Aisles details in responses
Deploy Application / deploy (push) Successful in 25s Details

This commit is contained in:
Habib Fatkhul Rohman 2025-11-11 12:03:58 +07:00
parent 3d638530eb
commit 46706e655a
5 changed files with 107 additions and 13 deletions

View File

@ -15,6 +15,7 @@ type MWarehouseEntity struct {
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
PIC M_User `gorm:"foreignKey:PICID;references:ID"`
Zonas []MZonaEntity `gorm:"foreignKey:WarehouseID;references:ID"`
FullAuditTrail
}

View File

@ -17,6 +17,7 @@ type MZonaEntity struct {
Warehouse MWarehouseEntity `gorm:"foreignKey:WarehouseID;references:ID"`
Client M_Client `gorm:"foreignKey:ClientID;references:ID"`
Aisles []MAisleEntity `gorm:"foreignKey:ZoneID;references:ID"`
FullAuditTrail
}

View File

@ -54,4 +54,37 @@ type WarehouseResponse struct {
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"`
}

View File

@ -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
}

View File

@ -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,
}
}