Feat[BE-222.223.224]: creating create one delivery order and getone delivery order[Unfinished]

This commit is contained in:
aguhh18
2025-11-13 09:50:34 +07:00
parent 0a0c3f869b
commit 74ec25db5b
8 changed files with 119 additions and 79 deletions
@@ -98,7 +98,7 @@ func (u *SalesOrdersController) CreateOne(c *fiber.Ctx) error {
Code: fiber.StatusCreated,
Status: "success",
Message: "Create salesOrders successfully",
Data: result,
Data: dto.ToSalesOrdersListDTOFromMarketing(*result),
})
}
@@ -32,6 +32,7 @@ type MarketingProductDTO struct {
Product *productDTO.ProductBaseDTO `json:"product,omitempty"`
Warehouse *warehouseDTO.WarehouseBaseDTO `json:"warehouse,omitempty"`
} `json:"product_warehouse,omitempty"`
DeliveryProduct *MarketingDeliveryProductDTO `json:"delivery_product,omitempty"`
}
type MarketingDeliveryProductDTO struct {
@@ -104,6 +105,12 @@ func ToMarketingProductDTO(e entity.MarketingProduct) MarketingProductDTO {
}
}
var deliveryProduct *MarketingDeliveryProductDTO
if e.DeliveryProduct != nil && e.DeliveryProduct.Id != 0 {
mapped := ToMarketingDeliveryProductDTO(*e.DeliveryProduct)
deliveryProduct = &mapped
}
return MarketingProductDTO{
Id: e.Id,
Qty: e.Qty,
@@ -112,6 +119,7 @@ func ToMarketingProductDTO(e entity.MarketingProduct) MarketingProductDTO {
TotalWeight: e.TotalWeight,
TotalPrice: e.TotalPrice,
ProductWarehouse: productWarehouse,
DeliveryProduct: deliveryProduct,
}
}
@@ -11,6 +11,7 @@ import (
type MarketingProductRepository interface {
repository.BaseRepository[entity.MarketingProduct]
GetByMarketingID(ctx context.Context, marketingID uint) ([]entity.MarketingProduct, error)
IdExists(ctx context.Context, id uint) (bool, error)
}
type MarketingProductRepositoryImpl struct {
@@ -33,3 +34,7 @@ func (r *MarketingProductRepositoryImpl) GetByMarketingID(ctx context.Context, m
}
return products, nil
}
func (r *MarketingProductRepositoryImpl) IdExists(ctx context.Context, id uint) (bool, error) {
return repository.Exists[entity.MarketingProduct](ctx, r.DB(), id)
}
@@ -65,7 +65,7 @@ func (s salesOrdersService) withRelations(db *gorm.DB) *gorm.DB {
Preload("SalesPerson").
Preload("Products.ProductWarehouse.Product").
Preload("Products.ProductWarehouse.Warehouse").
Preload("Products.DeliveryProducts")
Preload("Products.DeliveryProduct")
}
func (s salesOrdersService) GetAll(c *fiber.Ctx, params *validation.Query) ([]entity.Marketing, int64, error) {
@@ -255,7 +255,13 @@ func (s *salesOrdersService) CreateOne(c *fiber.Ctx, req *validation.Create) (*e
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to create salesOrders")
}
return s.GetOne(c, marketing.Id)
marketing, err = s.MarketingRepo.GetByID(c.Context(), marketing.Id, s.withRelations)
if err != nil {
s.Log.Errorf("Failed to fetch created marketing: %+v", err)
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch created sales order")
}
return marketing, nil
}
func (s salesOrdersService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uint) (*entity.Marketing, error) {