Merge branch 'fix/marketing-delivery' into 'development'

[FIX][BE]: fix get detail marketing delivery

See merge request mbugroup/lti-api!402
This commit is contained in:
Adnan Zahir
2026-04-08 16:54:53 +07:00
@@ -31,6 +31,8 @@ type MarketingDeliveryProductRepositoryImpl struct {
*commonRepo.BaseRepositoryImpl[entity.MarketingDeliveryProduct]
}
const marketingDeliveryProductSelectWithNullAttributed = "marketing_delivery_products.*, NULL AS attributed_project_flock_kandang_id"
func NewMarketingDeliveryProductRepository(db *gorm.DB) MarketingDeliveryProductRepository {
return &MarketingDeliveryProductRepositoryImpl{
BaseRepositoryImpl: commonRepo.NewBaseRepository[entity.MarketingDeliveryProduct](db),
@@ -43,9 +45,9 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetDeliveryProductsByProjectFlo
attributionQuery := commonRepo.MarketingDeliveryAttributionRowsQuery(r.DB().WithContext(ctx))
db := r.DB().WithContext(ctx).
Select("DISTINCT "+marketingDeliveryProductSelectWithNullAttributed).
Joins("JOIN (?) AS mda ON mda.marketing_delivery_product_id = marketing_delivery_products.id", attributionQuery).
Where("mda.project_flock_id = ?", projectFlockID).
Distinct("marketing_delivery_products.*")
Where("mda.project_flock_id = ?", projectFlockID)
if callback != nil {
db = callback(db)
@@ -110,6 +112,7 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetByMarketingId(ctx context.Co
// JOIN untuk filter by marketing_id yang ada di related table
db := r.DB().WithContext(ctx).
Select(marketingDeliveryProductSelectWithNullAttributed).
Joins("JOIN marketing_products ON marketing_products.id = marketing_delivery_products.marketing_product_id").
Where("marketing_products.marketing_id = ?", marketingId)
@@ -124,6 +127,8 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetByMarketingProductID(ctx con
var deliveryProduct entity.MarketingDeliveryProduct
if err := r.DB().WithContext(ctx).
Model(&entity.MarketingDeliveryProduct{}).
Select(marketingDeliveryProductSelectWithNullAttributed).
Where("marketing_product_id = ?", marketingProductID).
First(&deliveryProduct).Error; err != nil {
return nil, err
@@ -132,6 +137,27 @@ func (r *MarketingDeliveryProductRepositoryImpl) GetByMarketingProductID(ctx con
return &deliveryProduct, nil
}
func (r *MarketingDeliveryProductRepositoryImpl) GetByID(
ctx context.Context,
id uint,
modifier func(*gorm.DB) *gorm.DB,
) (*entity.MarketingDeliveryProduct, error) {
var deliveryProduct entity.MarketingDeliveryProduct
q := r.DB().WithContext(ctx).
Model(&entity.MarketingDeliveryProduct{}).
Select(marketingDeliveryProductSelectWithNullAttributed)
if modifier != nil {
q = modifier(q)
}
if err := q.First(&deliveryProduct, id).Error; err != nil {
return nil, err
}
return &deliveryProduct, nil
}
func (r *MarketingDeliveryProductRepositoryImpl) GetAttributionRowsByDeliveryProductIDs(ctx context.Context, deliveryProductIDs []uint) ([]commonRepo.MarketingDeliveryAttributionRow, error) {
if len(deliveryProductIDs) == 0 {
return []commonRepo.MarketingDeliveryAttributionRow{}, nil
@@ -211,6 +237,7 @@ func (r *MarketingDeliveryProductRepositoryImpl) fetchClosingDeliveryProducts(
}
query := r.closingDeliveryProductsQuery(ctx).
Select(marketingDeliveryProductSelectWithNullAttributed).
Where("marketing_delivery_products.id IN ?", deliveryIDs).
Order("marketing_delivery_products.delivery_date DESC")