Add Daily sales
This commit is contained in:
@@ -25,6 +25,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route.GET("/history", jwt, h.GetAllHistoryOrders)
|
||||
route.GET("/ticket-sold", jwt, h.CountSoldOfTicket)
|
||||
route.GET("/sum-amount", jwt, h.SumAmount)
|
||||
route.GET("/daily-sales", jwt, h.GetDailySalesTicket)
|
||||
}
|
||||
|
||||
func NewHandler(service services.Order) *Handler {
|
||||
@@ -240,6 +241,29 @@ func (h *Handler) CountSoldOfTicket(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) GetDailySalesTicket(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.GetDailySales(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.toDailySales(resp),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.OrderParam) response.HistoryOrderList {
|
||||
var orders []response.HistoryOrder
|
||||
for _, b := range resp {
|
||||
@@ -253,3 +277,15 @@ func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, r
|
||||
Offset: req.Offset,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) toDailySales(resp []entity.ProductDailySales) []response.ProductDailySales {
|
||||
var dailySales []response.ProductDailySales
|
||||
for _, b := range resp {
|
||||
dailySales = append(dailySales, response.ProductDailySales{
|
||||
Day: b.Day,
|
||||
ProductID: b.ProductID,
|
||||
TotalQuantity: b.TotalQuantity,
|
||||
})
|
||||
}
|
||||
return dailySales
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user