Feat[BE]:: adjust marketing report API

This commit is contained in:
aguhh18
2025-12-17 11:30:49 +07:00
parent afe4b2ffe3
commit 40f192660d
5 changed files with 131 additions and 48 deletions
@@ -11,6 +11,17 @@ import (
"github.com/gofiber/fiber/v2"
)
// === Marketing Report Response ===
type MarketingReportResponse struct {
Code int `json:"code"`
Status string `json:"status"`
Message string `json:"message"`
Meta response.Meta `json:"meta"`
Data []dto.RepportMarketingItemDTO `json:"data"`
Total *dto.Summary `json:"total,omitempty"`
}
type RepportController struct {
RepportService service.RepportService
}
@@ -85,8 +96,31 @@ func (c *RepportController) GetMarketing(ctx *fiber.Ctx) error {
return err
}
// Calculate total summary from result items
var total *dto.Summary
if len(result) > 0 {
totalQty := 0
totalWeightKg := 0.0
totalSalesAmount := int64(0)
totalHppAmount := int64(0)
for _, item := range result {
totalQty += int(item.Qty)
totalWeightKg += item.TotalWeightKg
totalSalesAmount += int64(item.SalesAmount)
totalHppAmount += int64(item.HppAmount)
}
total = &dto.Summary{
TotalQty: totalQty,
TotalWeightKg: totalWeightKg,
TotalSalesAmount: totalSalesAmount,
TotalHppAmount: totalHppAmount,
}
}
return ctx.Status(fiber.StatusOK).
JSON(response.SuccessWithPaginate[dto.RepportMarketingItemDTO]{
JSON(MarketingReportResponse{
Code: fiber.StatusOK,
Status: "success",
Message: "Get marketing report successfully",
@@ -96,6 +130,7 @@ func (c *RepportController) GetMarketing(ctx *fiber.Ctx) error {
TotalPages: int64(math.Ceil(float64(totalResults) / float64(query.Limit))),
TotalResults: totalResults,
},
Data: result,
Data: result,
Total: total,
})
}