mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
Feat[BE]:: adjust marketing report API
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user