refactor: now validate request with middleware
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"nos-comptes/handler"
|
||||
"nos-comptes/internal/storage/dao/postgresql"
|
||||
"nos-comptes/internal/storage/model"
|
||||
"nos-comptes/internal/storage/validators"
|
||||
"nos-comptes/internal/utils"
|
||||
"strings"
|
||||
|
||||
@@ -78,8 +77,6 @@ func (hc *Context) ConnectUser(c *gin.Context) {
|
||||
utils.JSONError(c.Writer, model.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
fmt.Println("Found the user " + user.Email)
|
||||
fmt.Println("Return 200")
|
||||
utils.JSON(c.Writer, 200, user)
|
||||
}
|
||||
|
||||
@@ -130,27 +127,6 @@ func (hc *Context) CreateUser(c *gin.Context) {
|
||||
|
||||
func (hc *Context) GetUser(c *gin.Context) {
|
||||
userID := c.Param("userId")
|
||||
|
||||
err := hc.Validator.VarCtx(c, userID, "uuid4")
|
||||
if err != nil {
|
||||
utils.JSONError(c.Writer, validators.NewDataValidationAPIError(err))
|
||||
return
|
||||
}
|
||||
|
||||
user, err := hc.service.GetUserById(userID)
|
||||
if e, ok := err.(*model.APIError); ok {
|
||||
utils.GetLoggerFromCtx(c).WithError(err).WithField("type", e.Type).Error("error GetUser: get user error")
|
||||
utils.JSONErrorWithMessage(c.Writer, *e, e.Description)
|
||||
} else if err != nil {
|
||||
utils.GetLoggerFromCtx(c).WithError(err).Error("error while get user")
|
||||
utils.JSONError(c.Writer, model.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
utils.JSONErrorWithMessage(c.Writer, model.ErrNotFound, "User not found")
|
||||
return
|
||||
}
|
||||
|
||||
user, _ := hc.service.GetUserById(userID)
|
||||
utils.JSON(c.Writer, http.StatusOK, user)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user