Add Checkin

This commit is contained in:
aditya.siregar
2024-08-13 23:09:05 +07:00
parent 4c8999a3cf
commit e544ef8f71
18 changed files with 362 additions and 101 deletions
@@ -197,6 +197,8 @@ func ConvertEntityToGetByIDResp(resp *entity.Site) *response.SearchSiteByIDRespo
TnC: resp.TnC,
AdditionalInfo: resp.AdditionalInfo,
PartnerID: resp.PartnerID,
Regency: resp.Regency,
Region: resp.Region,
}
}
+97 -11
View File
@@ -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,
}
}
+2
View File
@@ -1,6 +1,7 @@
package site
import (
"fmt"
"furtuna-be/internal/common/errors"
"furtuna-be/internal/entity"
"furtuna-be/internal/handlers/request"
@@ -287,6 +288,7 @@ func (h *Handler) toSiteResponse(resp *entity.Site) response.Site {
CreatedAt: resp.CreatedAt.Format(time.RFC3339),
UpdatedAt: resp.UpdatedAt.Format(time.RFC3339),
Products: h.toProductResponseList(resp.Products),
LatLong: fmt.Sprintf("%f,%f", resp.Lat, resp.Long),
}
}
+8
View File
@@ -47,6 +47,14 @@ type OrderParam struct {
Source string `form:"source" json:"source" example:"tes"`
}
type Checkin struct {
QRCode string `json:"qr_code" validate:"required"`
}
type CheckinExecute struct {
Token string `json:"token" validate:"required"`
}
func (o *OrderParam) ToOrderEntity(ctx mycontext.Context) entity.OrderSearch {
return entity.OrderSearch{
PartnerID: ctx.GetPartnerID(),
+21
View File
@@ -3,6 +3,9 @@ package request
import (
"furtuna-be/internal/common/mycontext"
"furtuna-be/internal/entity"
"log"
"strconv"
"strings"
)
type Site struct {
@@ -21,6 +24,9 @@ type Site struct {
IsSeasonTicket bool `json:"is_season_ticket"`
IsDiscountActive bool `json:"is_discount_active"`
Products []Product `json:"products"`
Region string `json:"region"`
Regency string `json:"regency"`
LatLong string `json:"lat_long"`
}
func (r *Site) ToEntity(createdBy int64) *entity.Site {
@@ -39,6 +45,17 @@ func (r *Site) ToEntity(createdBy int64) *entity.Site {
CreatedBy: createdBy,
})
}
latLong := strings.Split(r.LatLong, ".")
lat, err := strconv.ParseFloat(latLong[0], 64)
if err != nil {
log.Fatalf("Error converting latitude: %v", err)
}
long, err := strconv.ParseFloat(latLong[1], 64)
if err != nil {
log.Fatalf("Error converting longitude: %v", err)
}
return &entity.Site{
ID: r.ID,
@@ -56,6 +73,10 @@ func (r *Site) ToEntity(createdBy int64) *entity.Site {
IsSeasonTicket: r.IsSeasonTicket,
IsDiscountActive: r.IsDiscountActive,
Products: products,
Region: r.Region,
Regency: r.Regency,
Lat: lat,
Long: long,
}
}
+2
View File
@@ -61,6 +61,8 @@ type SearchSiteByIDResponse struct {
TnC string `json:"tn_c"`
AdditionalInfo string `json:"additional_info"`
Status string `json:"status"`
Region string `json:"region"`
Regency string `json:"regency"`
}
type SearchProductSiteByIDResponse struct {
+30 -12
View File
@@ -26,18 +26,18 @@ type OrderAmount struct {
}
type HistoryOrder struct {
ID int64 `json:"id"`
Employee string `json:"employee"`
Site string `json:"site"`
Timestamp string `json:"timestamp"`
BookingTime string `json:"booking_time"`
Tickets []string `json:"tickets"`
PaymentType string `json:"payment_type"`
Status string `json:"status"`
Amount float64 `json:"amount"`
VisitDate string `json:"visit_date"`
TicketStatus string `json:"ticket_status"`
Source string `json:"source"`
ID int64 `json:"id"`
Employee string `json:"employee"`
Site string `json:"site"`
Timestamp string `json:"timestamp"`
BookingTime string `json:"booking_time"`
Tickets []string `json:"tickets"`
PaymentType string `json:"payment_type"`
Status string `json:"status"`
Amount float64 `json:"amount"`
VisitDate string `json:"visit_date"`
TicketStatus string `json:"ticket_status"`
Source string `json:"source"`
}
type OrderItem struct {
@@ -110,6 +110,24 @@ type ExecuteOrderResponse struct {
QRcode string `json:"qr_code"`
}
type ExecuteCheckinResponse struct {
ID int64 `json:"id"`
RefID string `json:"ref_id"`
PartnerID int64 `json:"partner_id"`
Status string `json:"status"`
Amount float64 `json:"amount"`
PaymentType string `json:"payment_type"`
CreatedAt time.Time `json:"created_at"`
OrderItems []CreateOrderItemResponse `json:"order_items"`
PaymentToken string `json:"payment_token"`
RedirectURL string `json:"redirect_url"`
QRcode string `json:"qr_code"`
}
type CheckingInquiryResponse struct {
Token string `json:"token"`
}
type CreateOrderItemResponse struct {
ID int64 `json:"id"`
ItemID int64 `json:"item_id"`
+17 -16
View File
@@ -1,23 +1,24 @@
package response
type Site struct {
ID *int64 `json:"id"`
Name string `json:"name"`
PartnerID int64 `json:"partner_id"`
Image string `json:"image"`
Address string `json:"address"`
LocationLink string `json:"location_link"`
Description string `json:"description"`
Highlight string `json:"highlight"`
ContactPerson string `json:"contact_person"`
TnC string `json:"tnc"`
AdditionalInfo string `json:"additional_info"`
Status string `json:"status"`
IsSeasonTicket bool `json:"is_season_ticket"`
IsDiscountActive bool `json:"is_discount_active"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ID *int64 `json:"id"`
Name string `json:"name"`
PartnerID int64 `json:"partner_id"`
Image string `json:"image"`
Address string `json:"address"`
LocationLink string `json:"location_link"`
Description string `json:"description"`
Highlight string `json:"highlight"`
ContactPerson string `json:"contact_person"`
TnC string `json:"tnc"`
AdditionalInfo string `json:"additional_info"`
Status string `json:"status"`
IsSeasonTicket bool `json:"is_season_ticket"`
IsDiscountActive bool `json:"is_discount_active"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Products []Product `json:"products"`
LatLong string `json:"lat_long"`
}
type SiteName struct {