Add Checkin
This commit is contained in:
@@ -24,6 +24,8 @@ func (h *Handler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
route.POST("/execute", jwt, h.Execute)
|
||||
route.GET("/history", jwt, h.GetAllHistoryOrders)
|
||||
route.GET("/ticket-sold", jwt, h.CountSoldOfTicket)
|
||||
route.POST("/checkin/inquiry", jwt, h.CheckInInquiry)
|
||||
route.POST("/checkin/execute", jwt, h.CheckInExecute)
|
||||
route.GET("/sum-amount", jwt, h.SumAmount)
|
||||
route.GET("/daily-sales", jwt, h.GetDailySalesTicket)
|
||||
route.GET("/payment-distribution", jwt, h.GetPaymentDistributionChart)
|
||||
@@ -106,6 +108,66 @@ func (h *Handler) Execute(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) CheckInInquiry(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.Checkin
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.IsCasheer() || req.QRCode == "" {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
partnerID := ctx.GetPartnerID()
|
||||
|
||||
resp, err := h.service.CheckInInquiry(ctx, req.QRCode, partnerID)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.CheckingInquiryResponse{
|
||||
Token: resp.Token,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) CheckInExecute(c *gin.Context) {
|
||||
ctx := request.GetMyContext(c)
|
||||
|
||||
var req request.CheckinExecute
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.IsCasheer() || req.Token == "" {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
partnerID := ctx.GetPartnerID()
|
||||
|
||||
resp, err := h.service.CheckInExecute(ctx, req.Token, partnerID)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: MapOrderToExecuteCheckinResponse(resp.Order),
|
||||
})
|
||||
}
|
||||
|
||||
func MapOrderToCreateOrderResponse(orderResponse *entity.OrderResponse) response.CreateOrderResponse {
|
||||
order := orderResponse.Order
|
||||
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
||||
@@ -162,20 +224,44 @@ func MapOrderToExecuteOrderResponse(orderResponse *entity.ExecuteOrderResponse)
|
||||
}
|
||||
}
|
||||
|
||||
func MapOrderToExecuteCheckinResponse(order *entity.Order) response.ExecuteCheckinResponse {
|
||||
orderItems := make([]response.CreateOrderItemResponse, len(order.OrderItems))
|
||||
for i, item := range order.OrderItems {
|
||||
orderItems[i] = response.CreateOrderItemResponse{
|
||||
ID: item.ID,
|
||||
ItemID: item.ItemID,
|
||||
Quantity: item.Quantity,
|
||||
Price: item.Price,
|
||||
Name: item.Product.Name,
|
||||
}
|
||||
}
|
||||
|
||||
return response.ExecuteCheckinResponse{
|
||||
ID: order.ID,
|
||||
RefID: order.RefID,
|
||||
PartnerID: order.PartnerID,
|
||||
Status: order.Status,
|
||||
Amount: order.Amount,
|
||||
PaymentType: order.PaymentType,
|
||||
CreatedAt: order.CreatedAt,
|
||||
OrderItems: orderItems,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) toHistoryOrderResponse(resp *entity.HistoryOrder) response.HistoryOrder {
|
||||
return response.HistoryOrder{
|
||||
ID: resp.ID,
|
||||
Employee: resp.Employee,
|
||||
Site: resp.Site,
|
||||
Timestamp: resp.Timestamp.Format(time.RFC3339),
|
||||
BookingTime: resp.BookingTime.Format(time.RFC3339),
|
||||
Tickets: resp.Tickets,
|
||||
PaymentType: resp.PaymentType,
|
||||
Status: resp.Status,
|
||||
Amount: resp.Amount,
|
||||
VisitDate: resp.VisitDate.Format(time.RFC3339),
|
||||
ID: resp.ID,
|
||||
Employee: resp.Employee,
|
||||
Site: resp.Site,
|
||||
Timestamp: resp.Timestamp.Format(time.RFC3339),
|
||||
BookingTime: resp.BookingTime.Format(time.RFC3339),
|
||||
Tickets: resp.Tickets,
|
||||
PaymentType: resp.PaymentType,
|
||||
Status: resp.Status,
|
||||
Amount: resp.Amount,
|
||||
VisitDate: resp.VisitDate.Format(time.RFC3339),
|
||||
TicketStatus: resp.TicketStatus,
|
||||
Source: resp.Source,
|
||||
Source: resp.Source,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user