Merge pull request 'history-order-list' (#3) from history-order-list into main

Reviewed-on: https://git.altru.id/Furtuna/furtuna-backend/pulls/3
This commit is contained in:
2024-07-28 06:05:49 +00:00
14 changed files with 285 additions and 24 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))
+27 -1
View File
@@ -26,6 +26,7 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
route.PUT("/:id", jwt, h.Update)
route.GET("/:id", jwt, h.GetByID)
route.DELETE("/:id", jwt, h.Delete)
route.GET("/count", jwt, h.Count)
}
func NewHandler(service services.Site) *Handler {
@@ -148,7 +149,8 @@ func (h *Handler) GetAll(c *gin.Context) {
return
}
Sites, total, err := h.service.GetAll(c.Request.Context(), req.ToEntity())
ctx := request.GetMyContext(c)
Sites, total, err := h.service.GetAll(c.Request.Context(), req.ToEntity(ctx))
if err != nil {
response.ErrorWrapper(c, err)
return
@@ -242,6 +244,30 @@ func (h *Handler) GetByID(c *gin.Context) {
})
}
func (h *Handler) Count(c *gin.Context) {
var req request.SiteParam
if err := c.ShouldBindQuery(&req); err != nil {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
ctx := request.GetMyContext(c)
res, err := h.service.Count(ctx, req.ToEntity(ctx))
if err != nil {
response.ErrorWrapper(c, err)
return
}
c.JSON(http.StatusOK, response.BaseResponse{
Success: true,
Status: http.StatusOK,
Data: response.SiteCount{
Count: res.Count,
},
})
}
func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
return response.Site{
ID: &resp.ID,
+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,
}
+4 -1
View File
@@ -1,6 +1,7 @@
package request
import (
"furtuna-be/internal/common/mycontext"
"furtuna-be/internal/entity"
)
@@ -65,8 +66,10 @@ type SiteParam struct {
Offset int `form:"offset,default=0"`
}
func (r *SiteParam) ToEntity() entity.SiteSearch {
func (r *SiteParam) ToEntity(ctx mycontext.Context) entity.SiteSearch {
return entity.SiteSearch{
PartnerID: ctx.GetPartnerID(),
IsAdmin: ctx.IsAdmin(),
Search: r.Search,
Name: r.Name,
Limit: r.Limit,
+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"`
+4
View File
@@ -24,6 +24,10 @@ type SiteName struct {
Name string `json:"name"`
}
type SiteCount struct {
Count int `json:"count"`
}
type SiteList struct {
Sites []Site `json:"sites"`
Total int64 `json:"total"`