feat: amount transaction and count of item

This commit is contained in:
ferdiansyah783
2024-07-27 16:47:33 +07:00
parent 4013b12ac9
commit 30aa206d80
9 changed files with 192 additions and 19 deletions
+54 -4
View File
@@ -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))
+1 -1
View File
@@ -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,
},
+7 -5
View File
@@ -12,15 +12,17 @@ type Order struct {
OrderItems []OrderItem `json:"order_items" validate:"required"`
}
type HistoryOrderParam struct {
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
type OrderParam struct {
PaymentType string `form:"payment_type" json:"payment_type" example:"CASH"`
Limit int `form:"limit" json:"limit" example:"10"`
Offset int `form:"offset" json:"offset" example:"0"`
}
func (o *HistoryOrderParam) ToEntity(ctx mycontext.Context) entity.HistoryOrderSearch {
return entity.HistoryOrderSearch{
func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
return entity.OrderSearch{
PartnerID: ctx.GetPartnerID(),
IsAdmin: ctx.IsAdmin(),
PaymentType: o.PaymentType,
Limit: o.Limit,
Offset: o.Offset,
}
+8
View File
@@ -21,6 +21,10 @@ type Order struct {
UpdatedAt string `json:"updated_at"`
}
type OrderAmount struct {
Amount float64 `json:"amount"`
}
type HistoryOrder struct {
ID int64 `json:"id"`
Employee string `json:"employee"`
@@ -58,6 +62,10 @@ type HistoryOrderList struct {
Offset int `json:"offset"`
}
type TicketSold struct {
Count int64 `json:"count"`
}
type OrderMonthlyRevenue struct {
TotalRevenue float64 `json:"total_revenue"`
TotalTransaction int64 `json:"total_transaction"`