feat: history-order-list

This commit is contained in:
ferdiansyah783
2024-07-26 11:37:22 +07:00
parent f4d782653d
commit 195371f5c6
9 changed files with 218 additions and 6 deletions
+52 -1
View File
@@ -6,9 +6,11 @@ import (
"furtuna-be/internal/handlers/request"
"furtuna-be/internal/handlers/response"
"furtuna-be/internal/services"
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"net/http"
)
type Handler struct {
@@ -20,6 +22,7 @@ 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)
}
func NewHandler(service services.Order) *Handler {
@@ -151,3 +154,51 @@ func MapOrderToExecuteOrderResponse(orderResponse *entity.ExecuteOrderResponse)
RedirectURL: orderResponse.RedirectURL,
}
}
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,
}
}
func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
var req request.HistoryOrderParam
if err := c.ShouldBindQuery(&req); err != nil {
response.ErrorWrapper(c, errors.ErrorBadRequest)
return
}
orders, total, err := h.service.GetAllHistoryOrders(c.Request.Context(), req.ToEntity())
if err != nil {
response.ErrorWrapper(c, err)
return
}
c.JSON(http.StatusOK, response.BaseResponse{
Success: true,
Status: http.StatusOK,
Data: h.toHistoryOrderList(orders, int64(total), req),
})
}
func (h *Handler) toHistoryOrderList(resp []*entity.HistoryOrder, total int64, req request.HistoryOrderParam) response.HistoryOrderList {
var orders []response.HistoryOrder
for _, b := range resp {
orders = append(orders, h.toHistoryOrderResponse(b))
}
return response.HistoryOrderList{
Orders: orders,
Total: total,
Limit: req.Limit,
Offset: req.Offset,
}
}