feat: amount transaction and count of item
This commit is contained in:
@@ -23,6 +23,8 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route.POST("/inquiry", jwt, h.Inquiry)
|
||||
route.POST("/execute", jwt, h.Execute)
|
||||
route.GET("/history", jwt, h.GetAllHistoryOrders)
|
||||
route.GET("/ticket-sold", jwt, h.CountSoldOfTicket)
|
||||
route.GET("/sum-amount", jwt, h.SumAmount)
|
||||
}
|
||||
|
||||
func NewHandler(service services.Order) *Handler {
|
||||
@@ -169,15 +171,38 @@ func (h *Handler) toHistoryOrderResponse(resp *entity.HistoryOrder) response.His
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
|
||||
var req request.HistoryOrderParam
|
||||
func (h *Handler) SumAmount(c *gin.Context) {
|
||||
var req request.OrderParam
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := request.GetMyContext(c)
|
||||
orders, total, err := h.service.GetAllHistoryOrders(ctx, req.ToEntity(ctx))
|
||||
order, err := h.service.SumAmount(ctx, req.ToOrderEntity(ctx))
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.OrderAmount{
|
||||
Amount: order.Amount,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
|
||||
var req request.OrderParam
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := request.GetMyContext(c)
|
||||
orders, total, err := h.service.GetAllHistoryOrders(ctx, req.ToOrderEntity(ctx))
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
@@ -190,7 +215,32 @@ func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.HistoryOrderParam) response.HistoryOrderList {
|
||||
func (h *Handler) CountSoldOfTicket(c *gin.Context) {
|
||||
var req request.OrderParam
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
res, err := h.service.CountSoldOfTicket(ctx, req.ToOrderEntity(ctx))
|
||||
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.TicketSold{
|
||||
Count: res.Count,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.OrderParam) response.HistoryOrderList {
|
||||
var orders []response.HistoryOrder
|
||||
for _, b := range resp {
|
||||
orders = append(orders, h.toHistoryOrderResponse(b))
|
||||
|
||||
@@ -261,7 +261,7 @@ func (h *Handler) Count(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Status: http.StatusOK,
|
||||
Data: response.SiteCount{
|
||||
Count: res.Count,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user