fix: validation role for history order

This commit is contained in:
ferdiansyah783
2024-07-26 13:39:08 +07:00
parent 5a68a1daa4
commit 5ef14f3043
5 changed files with 31 additions and 8 deletions
+12 -1
View File
@@ -7,6 +7,7 @@ import (
"furtuna-be/internal/handlers/response"
"furtuna-be/internal/services"
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -170,13 +171,23 @@ func (h *Handler) toHistoryOrderResponse(resp *entity.HistoryOrder) response.His
}
func (h *Handler) GetAllHistoryOrders(c *gin.Context) {
tokenString := c.GetHeader("Authorization")
if tokenString == "" {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Authorization header is required"})
c.Abort()
return
}
tokenString = strings.TrimPrefix(tokenString, "Bearer ")
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())
orders, total, err := h.service.GetAllHistoryOrders(c.Request.Context(), tokenString, req.ToEntity())
if err != nil {
response.ErrorWrapper(c, err)
return