refactor/fix: now using pgx errors for postgres error checking instead of trying to look up the error code;
feat: implemented working custom validation; fix: authservice begin/complete registration
This commit is contained in:
@@ -19,9 +19,12 @@ package middleware
|
||||
|
||||
import (
|
||||
"easywish/internal/utils/enums"
|
||||
"easywish/internal/validation"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
type UserInfo struct {
|
||||
@@ -87,6 +90,15 @@ func RequestMiddleware[T any](role enums.Role) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
validate := validation.NewValidator()
|
||||
|
||||
if err := validate.Struct(body); err != nil {
|
||||
errorList := err.(validator.ValidationErrors)
|
||||
c.String(http.StatusBadRequest, fmt.Sprintf("Validation error: %s", errorList))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
request := Request[T]{
|
||||
User: *userInfo,
|
||||
Body: body,
|
||||
|
||||
Reference in New Issue
Block a user