-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated validation for "name" and "email" fields in user models. Updated the UserHandler to register custom validators using go-playground/validator. Added custom error messages for validation to improve clarity for users.
- Loading branch information
1 parent
4d99f39
commit 3ab1cdc
Showing
4 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
package user | ||
|
||
import ( | ||
userValidate "Go_Food_Delivery/pkg/database/models/user" | ||
"Go_Food_Delivery/pkg/handler" | ||
"Go_Food_Delivery/pkg/service/user" | ||
"github.com/gin-gonic/gin" | ||
"github.com/go-playground/validator/v10" | ||
) | ||
|
||
type UserHandler struct { | ||
Serve *handler.Server | ||
group string | ||
router *gin.RouterGroup | ||
service *user.UsrService | ||
Serve *handler.Server | ||
group string | ||
router *gin.RouterGroup | ||
service *user.UsrService | ||
validate *validator.Validate | ||
} | ||
|
||
func NewUserHandler(s *handler.Server, groupName string, service *user.UsrService) { | ||
func NewUserHandler(s *handler.Server, groupName string, service *user.UsrService, validate *validator.Validate) { | ||
|
||
usrHandler := &UserHandler{ | ||
s, | ||
groupName, | ||
&gin.RouterGroup{}, | ||
service, | ||
validate, | ||
} | ||
usrHandler.router = usrHandler.registerGroup() | ||
usrHandler.routes() | ||
usrHandler.registerValidator() | ||
} | ||
|
||
func (s *UserHandler) registerValidator() { | ||
_ = s.validate.RegisterValidation("name", userValidate.NameValidator) | ||
_ = s.validate.RegisterValidation("email", userValidate.EmailValidator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters