diff --git a/internal/modules/production/recordings/dto/recording.dto.go b/internal/modules/production/recordings/dto/recording.dto.go index 4a6b4818..52c5fb56 100644 --- a/internal/modules/production/recordings/dto/recording.dto.go +++ b/internal/modules/production/recordings/dto/recording.dto.go @@ -48,17 +48,27 @@ type RecordingBodyWeightDTO struct { } type RecordingDepletionDTO struct { - ProductWarehouseId uint `json:"product_warehouse_id"` - Total int64 `json:"total"` - Notes *string `json:"notes,omitempty"` + ProductWarehouseId uint `json:"product_warehouse_id"` + Total int64 `json:"total"` + Notes *string `json:"notes,omitempty"` + ProductWarehouse *RecordingProductWarehouseDTO `json:"product_warehouse,omitempty"` } type RecordingStockDTO struct { - ProductWarehouseId uint `json:"product_warehouse_id"` - Increase *float64 `json:"increase,omitempty"` - Decrease *float64 `json:"decrease,omitempty"` - UsageAmount *int64 `json:"usage_amount,omitempty"` - Notes *string `json:"notes,omitempty"` + ProductWarehouseId uint `json:"product_warehouse_id"` + Increase *float64 `json:"increase,omitempty"` + Decrease *float64 `json:"decrease,omitempty"` + UsageAmount *int64 `json:"usage_amount,omitempty"` + Notes *string `json:"notes,omitempty"` + ProductWarehouse *RecordingProductWarehouseDTO `json:"product_warehouse,omitempty"` +} + +type RecordingProductWarehouseDTO struct { + Id uint `json:"id"` + ProductId uint `json:"product_id"` + ProductName string `json:"product_name"` + WarehouseId uint `json:"warehouse_id"` + WarehouseName string `json:"warehouse_name"` } // === Mapper Functions === @@ -145,6 +155,7 @@ func ToRecordingDepletionDTOs(depletions []entity.RecordingDepletion) []Recordin ProductWarehouseId: d.ProductWarehouseId, Total: d.Total, Notes: d.Notes, + ProductWarehouse: toRecordingProductWarehouseDTO(&d.ProductWarehouse), } } return result @@ -159,7 +170,29 @@ func ToRecordingStockDTOs(stocks []entity.RecordingStock) []RecordingStockDTO { Decrease: s.Decrease, UsageAmount: s.UsageAmount, Notes: s.Notes, + ProductWarehouse: toRecordingProductWarehouseDTO(&s.ProductWarehouse), } } return result } + +func toRecordingProductWarehouseDTO(pw *entity.ProductWarehouse) *RecordingProductWarehouseDTO { + if pw == nil || pw.Id == 0 { + return nil + } + + dto := RecordingProductWarehouseDTO{ + Id: pw.Id, + ProductId: pw.ProductId, + WarehouseId: pw.WarehouseId, + } + + if pw.Product.Id != 0 { + dto.ProductName = pw.Product.Name + } + if pw.Warehouse.Id != 0 { + dto.WarehouseName = pw.Warehouse.Name + } + + return &dto +}