Add Daily Sales and Distributed Payment
This commit is contained in:
@@ -26,6 +26,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route.GET("/ticket-sold", jwt, h.CountSoldOfTicket)
|
||||
route.GET("/sum-amount", jwt, h.SumAmount)
|
||||
route.GET("/daily-sales", jwt, h.GetDailySalesTicket)
|
||||
route.GET("/payment-distribution", jwt, h.GetPaymentDistributionChart)
|
||||
}
|
||||
|
||||
func NewHandler(service services.Order) *Handler {
|
||||
@@ -264,6 +265,29 @@ func (h *Handler) GetDailySalesTicket(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) GetPaymentDistributionChart(c *gin.Context) {
|
||||
var req request.OrderParam
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
resp, err := h.service.GetPaymentDistribution(ctx, req.ToOrderEntity(ctx))
|
||||
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: h.toPaymentDistributionChart(resp),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.OrderParam) response.HistoryOrderList {
|
||||
var orders []response.HistoryOrder
|
||||
for _, b := range resp {
|
||||
@@ -291,3 +315,14 @@ func (h *Handler) toDailySales(resp []entity.ProductDailySales) []response.Produ
|
||||
}
|
||||
return dailySales
|
||||
}
|
||||
|
||||
func (h *Handler) toPaymentDistributionChart(resp []entity.PaymentTypeDistribution) []response.PaymentDistribution {
|
||||
var dailySales []response.PaymentDistribution
|
||||
for _, b := range resp {
|
||||
dailySales = append(dailySales, response.PaymentDistribution{
|
||||
PaymentType: b.PaymentType,
|
||||
Count: b.Count,
|
||||
})
|
||||
}
|
||||
return dailySales
|
||||
}
|
||||
|
||||
@@ -119,3 +119,8 @@ type ProductDailySales struct {
|
||||
PaymentType string `json:"payment_type"`
|
||||
Total float64 `json:"total"`
|
||||
}
|
||||
|
||||
type PaymentDistribution struct {
|
||||
PaymentType string `json:"payment_type"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user