mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
Feat[BE]: refactor document handling in transfer service and introduce document type constants
This commit is contained in:
@@ -7,8 +7,6 @@ import (
|
||||
userDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/users/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
|
||||
type TransferRelationDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
TransferReason string `json:"transfer_reason"`
|
||||
@@ -17,7 +15,6 @@ type TransferRelationDTO struct {
|
||||
DestinationWarehouse *WarehouseDetailDTO `json:"destination_warehouse,omitempty"`
|
||||
}
|
||||
|
||||
// Only id and name for warehouse simple view
|
||||
type WarehouseSimpleDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
@@ -65,7 +62,6 @@ type TransferListDTO struct {
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Details []TransferDetailItemDTO `json:"details"`
|
||||
Deliveries []TransferDeliveryDTO `json:"deliveries"`
|
||||
Documents []DocumentDTO `json:"documents"`
|
||||
}
|
||||
|
||||
type TransferDetailDTO struct {
|
||||
@@ -74,14 +70,12 @@ type TransferDetailDTO struct {
|
||||
Deliveries []TransferDeliveryDTO `json:"deliveries"`
|
||||
}
|
||||
|
||||
// Detail produk
|
||||
type TransferDetailItemDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
Proudct ProductSimpleDTO `json:"product"`
|
||||
Product ProductSimpleDTO `json:"product"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
}
|
||||
|
||||
// Delivery ekspedisi
|
||||
type TransferDeliveryDTO struct {
|
||||
Id uint64 `json:"id"`
|
||||
Supplier SupplierSimpleDTO `json:"supplier"`
|
||||
@@ -91,6 +85,7 @@ type TransferDeliveryDTO struct {
|
||||
ShippingCostItem float64 `json:"shipping_cost_item"`
|
||||
ShippingCostTotal float64 `json:"shipping_cost_total"`
|
||||
Items []TransferDeliveryItemDTO `json:"items"`
|
||||
Documents []DocumentDTO `json:"documents"`
|
||||
}
|
||||
|
||||
type TransferDeliveryItemDTO struct {
|
||||
@@ -99,10 +94,7 @@ type TransferDeliveryItemDTO struct {
|
||||
Quantity float64 `json:"quantity"`
|
||||
}
|
||||
|
||||
// === Mapper Functions ===
|
||||
|
||||
func ToTransferRelationDTO(e entity.StockTransfer) TransferRelationDTO {
|
||||
|
||||
var sourceWarehouse *WarehouseDetailDTO
|
||||
if e.FromWarehouse != nil && e.FromWarehouse.Id != 0 {
|
||||
sourceWarehouse = toWarehouseDetailDTO(e.FromWarehouse)
|
||||
@@ -148,7 +140,7 @@ func toWarehouseDetailDTO(w *entity.Warehouse) *WarehouseDetailDTO {
|
||||
Id: w.Id,
|
||||
Name: w.Name,
|
||||
Location: toLocationDTO(w.Location),
|
||||
Area: toAreaDTO(&w.Area), // Ambil area langsung dari warehouse (area_id)
|
||||
Area: toAreaDTO(&w.Area),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,22 +150,21 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||
mapped := userDTO.ToUserRelationDTO(*e.CreatedUser)
|
||||
createdUser = &mapped
|
||||
}
|
||||
// Map details
|
||||
|
||||
var details []TransferDetailItemDTO
|
||||
for _, d := range e.Details {
|
||||
details = append(details, TransferDetailItemDTO{
|
||||
Id: d.Id,
|
||||
Proudct: ProductSimpleDTO{
|
||||
Product: ProductSimpleDTO{
|
||||
Id: d.Product.Id,
|
||||
Name: d.Product.Name,
|
||||
},
|
||||
Quantity: d.Quantity,
|
||||
})
|
||||
}
|
||||
// Map deliveries
|
||||
|
||||
var deliveries []TransferDeliveryDTO
|
||||
for _, del := range e.Deliveries {
|
||||
// Map delivery items
|
||||
var items []TransferDeliveryItemDTO
|
||||
for _, item := range del.Items {
|
||||
items = append(items, TransferDeliveryItemDTO{
|
||||
@@ -183,6 +174,17 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||
})
|
||||
}
|
||||
|
||||
var documents []DocumentDTO
|
||||
for _, doc := range del.Documents {
|
||||
documents = append(documents, DocumentDTO{
|
||||
Id: doc.Id,
|
||||
Path: doc.Path,
|
||||
Name: doc.Name,
|
||||
Ext: doc.Ext,
|
||||
Size: doc.Size,
|
||||
})
|
||||
}
|
||||
|
||||
deliveries = append(deliveries, TransferDeliveryDTO{
|
||||
Id: del.Id,
|
||||
Supplier: SupplierSimpleDTO{
|
||||
@@ -195,16 +197,7 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||
ShippingCostItem: del.ShippingCostItem,
|
||||
ShippingCostTotal: del.ShippingCostTotal,
|
||||
Items: items,
|
||||
})
|
||||
}
|
||||
var documents []DocumentDTO
|
||||
for _, doc := range e.Documents {
|
||||
documents = append(documents, DocumentDTO{
|
||||
Id: doc.Id,
|
||||
Path: doc.Path,
|
||||
Name: doc.Name,
|
||||
Ext: doc.Ext,
|
||||
Size: doc.Size,
|
||||
Documents: documents,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -215,7 +208,6 @@ func ToTransferListDTO(e entity.StockTransfer) TransferListDTO {
|
||||
UpdatedAt: e.UpdatedAt,
|
||||
Details: details,
|
||||
Deliveries: deliveries,
|
||||
Documents: documents,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,21 +220,31 @@ func ToTransferListDTOs(e []entity.StockTransfer) []TransferListDTO {
|
||||
}
|
||||
|
||||
func ToTransferDetailDTO(e entity.StockTransfer) TransferDetailDTO {
|
||||
// Map details
|
||||
var details []TransferDetailItemDTO
|
||||
for _, d := range e.Details {
|
||||
details = append(details, TransferDetailItemDTO{
|
||||
Id: d.Id,
|
||||
Proudct: ProductSimpleDTO{
|
||||
Product: ProductSimpleDTO{
|
||||
Id: d.Product.Id,
|
||||
Name: d.Product.Name,
|
||||
},
|
||||
Quantity: d.Quantity,
|
||||
})
|
||||
}
|
||||
// Map deliveries
|
||||
|
||||
var deliveries []TransferDeliveryDTO
|
||||
for _, del := range e.Deliveries {
|
||||
var documents []DocumentDTO
|
||||
for _, doc := range del.Documents {
|
||||
documents = append(documents, DocumentDTO{
|
||||
Id: doc.Id,
|
||||
Path: doc.Path,
|
||||
Name: doc.Name,
|
||||
Ext: doc.Ext,
|
||||
Size: doc.Size,
|
||||
})
|
||||
}
|
||||
|
||||
deliveries = append(deliveries, TransferDeliveryDTO{
|
||||
Id: del.Id,
|
||||
Supplier: SupplierSimpleDTO{
|
||||
@@ -254,8 +256,10 @@ func ToTransferDetailDTO(e entity.StockTransfer) TransferDetailDTO {
|
||||
DocumentNumber: del.DocumentNumber,
|
||||
ShippingCostItem: del.ShippingCostItem,
|
||||
ShippingCostTotal: del.ShippingCostTotal,
|
||||
Documents: documents,
|
||||
})
|
||||
}
|
||||
|
||||
return TransferDetailDTO{
|
||||
TransferListDTO: ToTransferListDTO(e),
|
||||
Details: details,
|
||||
|
||||
Reference in New Issue
Block a user