Add Daily sales

This commit is contained in:
aditya.siregar
2024-08-02 02:27:57 +07:00
parent d50cefbc7f
commit 4e4d9d3a90
7 changed files with 90 additions and 0 deletions
+36
View File
@@ -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
}
+6
View File
@@ -111,3 +111,9 @@ type CreateOrderItemResponse struct {
Price float64 `json:"price"`
Name string `json:"name"`
}
type ProductDailySales struct {
Day time.Time
ProductID int64
TotalQuantity int
}