mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat[BE-222]: Completed SO and DO API
This commit is contained in:
+2
@@ -36,10 +36,12 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetByMarketingId(ctx context.Co
|
||||
var deliveryProducts []entity.MarketingDeliveryProduct
|
||||
|
||||
// Raw query untuk mengambil delivery products berdasarkan marketing ID dengan preload MarketingProduct
|
||||
// Filter: hanya ambil yang sudah memiliki delivery_date (delivery date tidak null)
|
||||
if err := r.DB().WithContext(ctx).
|
||||
Preload("MarketingProduct").
|
||||
Joins("INNER JOIN marketing_products mp ON marketing_delivery_products.marketing_product_id = mp.id").
|
||||
Where("mp.marketing_id = ?", marketingId).
|
||||
Where("marketing_delivery_products.delivery_date IS NOT NULL").
|
||||
Order("marketing_delivery_products.id ASC").
|
||||
Find(&deliveryProducts).Error; err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
productDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/products/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
@@ -15,13 +16,19 @@ type ProductWarehouseBaseDTO struct {
|
||||
Quantity float64 `json:"quantity"`
|
||||
}
|
||||
|
||||
type ProductWarehousNestedDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
}
|
||||
|
||||
type ProductWarehouseListDTO struct {
|
||||
ProductWarehouseBaseDTO
|
||||
Product *ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
CreatedUser *UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
|
||||
Warehouse *WarehouseBaseDTO `json:"warehouse,omitempty"`
|
||||
CreatedUser *UserBaseDTO `json:"created_user,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UserBaseDTO struct {
|
||||
@@ -75,6 +82,19 @@ func ToProductWarehouseBaseDTO(e entity.ProductWarehouse) ProductWarehouseBaseDT
|
||||
}
|
||||
}
|
||||
|
||||
func ToProductWarehouseNestedDTO(e entity.ProductWarehouse) ProductWarehousNestedDTO {
|
||||
product := productDTO.ToProductBaseDTO(e.Product)
|
||||
|
||||
return ProductWarehousNestedDTO{
|
||||
Id: e.Id,
|
||||
Product: &product,
|
||||
Warehouse: &WarehouseBaseDTO{
|
||||
Id: e.Warehouse.Id,
|
||||
Name: e.Warehouse.Name,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDTO {
|
||||
dto := ProductWarehouseListDTO{
|
||||
ProductWarehouseBaseDTO: ToProductWarehouseBaseDTO(e),
|
||||
@@ -84,18 +104,7 @@ func ToProductWarehouseListDTO(e entity.ProductWarehouse) ProductWarehouseListDT
|
||||
|
||||
// Map Product relation jika ada
|
||||
if e.Product.Id != 0 {
|
||||
product := ProductBaseDTO{
|
||||
Id: e.Product.Id,
|
||||
Name: e.Product.Name,
|
||||
}
|
||||
if e.Product.Sku != nil {
|
||||
product.Sku = *e.Product.Sku
|
||||
}
|
||||
if len(e.Product.Flags) > 0 {
|
||||
for _, f := range e.Product.Flags {
|
||||
product.Flags = append(product.Flags, f.Name)
|
||||
}
|
||||
}
|
||||
product := productDTO.ToProductBaseDTO(e.Product)
|
||||
dto.Product = &product
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user