update Order History
This commit is contained in:
@@ -2,12 +2,12 @@ package order
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/common/errors"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/entity"
|
||||
"furtuna-be/internal/handlers/request"
|
||||
"furtuna-be/internal/handlers/response"
|
||||
"furtuna-be/internal/services"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -171,23 +171,14 @@ 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(), tokenString, req.ToEntity())
|
||||
ctx := mycontext.NewContext(c.Request.Context())
|
||||
orders, total, err := h.service.GetAllHistoryOrders(ctx, req.ToEntity(ctx))
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/constants/transaction"
|
||||
"furtuna-be/internal/entity"
|
||||
)
|
||||
@@ -12,14 +13,16 @@ type Order struct {
|
||||
}
|
||||
|
||||
type HistoryOrderParam struct {
|
||||
Limit int `form:"limit" json:"limit" example:"10"`
|
||||
Offset int `form:"offset" json:"offset" example:"0"`
|
||||
Limit int `form:"limit" json:"limit" example:"10"`
|
||||
Offset int `form:"offset" json:"offset" example:"0"`
|
||||
}
|
||||
|
||||
func (o *HistoryOrderParam) ToEntity() entity.HistoryOrderSearch {
|
||||
func (o *HistoryOrderParam) ToEntity(ctx mycontext.Context) entity.HistoryOrderSearch {
|
||||
return entity.HistoryOrderSearch{
|
||||
Limit: o.Limit,
|
||||
Offset: o.Offset,
|
||||
PartnerID: ctx.GetPartnerID(),
|
||||
IsAdmin: ctx.IsAdmin(),
|
||||
Limit: o.Limit,
|
||||
Offset: o.Offset,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user