package dto import ( "time" entity "gitlab.com/mbugroup/lti-api.git/internal/entities" productWarehouseDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/inventory/product-warehouses/dto" ) // === DTO Structs === type MarketingProductDTO struct { Id uint `json:"id"` Qty float64 `json:"qty"` UnitPrice float64 `json:"unit_price"` AvgWeight float64 `json:"avg_weight"` TotalWeight float64 `json:"total_weight"` TotalPrice float64 `json:"total_price"` ProductWarehouse *productWarehouseDTO.ProductWarehousNestedDTO `json:"product_warehouse,omitempty"` } type SalesOrdersListDTO struct { Id uint `json:"id"` SoNumber string `json:"so_number"` SoDate time.Time `json:"so_date"` Notes string `json:"notes,omitempty"` SalesOrder []MarketingProductDTO `json:"sales_order,omitempty"` } // === Mapper Functions === func ToMarketingProductDTO(e entity.MarketingProduct) MarketingProductDTO { var productWarehouse *productWarehouseDTO.ProductWarehousNestedDTO if e.ProductWarehouse.Id != 0 { mapped := productWarehouseDTO.ToProductWarehouseNestedDTO(e.ProductWarehouse) productWarehouse = &mapped } return MarketingProductDTO{ Id: e.Id, Qty: e.Qty, UnitPrice: e.UnitPrice, AvgWeight: e.AvgWeight, TotalWeight: e.TotalWeight, TotalPrice: e.TotalPrice, ProductWarehouse: productWarehouse, } } func ToSalesOrdersListDTO(e entity.Marketing) SalesOrdersListDTO { products := make([]MarketingProductDTO, len(e.Products)) for i, p := range e.Products { products[i] = ToMarketingProductDTO(p) } return SalesOrdersListDTO{ Id: e.Id, SoNumber: e.SoNumber, SoDate: e.SoDate, Notes: e.Notes, SalesOrder: products, } } func ToSalesOrdersListDTOFromMarketing(e entity.Marketing) SalesOrdersListDTO { var salesOrder []MarketingProductDTO if len(e.Products) > 0 { salesOrder = make([]MarketingProductDTO, len(e.Products)) for i, product := range e.Products { salesOrder[i] = ToMarketingProductDTO(product) } } return SalesOrdersListDTO{ Id: e.Id, SoNumber: e.SoNumber, SoDate: e.SoDate, Notes: e.Notes, SalesOrder: salesOrder, } } func ToSalesOrdersListDTOsFromMarketing(e []entity.Marketing) []SalesOrdersListDTO { result := make([]SalesOrdersListDTO, len(e)) for i, r := range e { result[i] = ToSalesOrdersListDTOFromMarketing(r) } return result }