Skip to content

Commit

Permalink
fix: handler binding
Browse files Browse the repository at this point in the history
gin-gonic/gin#633 <- closed, but still an issue
  • Loading branch information
dnabil committed Dec 9, 2023
1 parent 9bab3a1 commit 6490e62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion todo-list-be/app/http/handler/todo_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewTodoHandler(log *logrus.Logger, service *service.TodoService) *TodoHandl

func (h *TodoHandler) Create(c *gin.Context){
req := new(dto.CreateTodoRequest)
if err := c.BindJSON(&req); err != nil {
if err := c.ShouldBindJSON(&req); err != nil {
Response(c, http.StatusBadRequest, "bad request", nil)
return
}
Expand Down
4 changes: 2 additions & 2 deletions todo-list-be/app/http/handler/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewUserHandler(log *logrus.Logger, service *service.UserService) *UserHandl

func (h *UserHandler) Create(c *gin.Context){
req := new(dto.CreateUserRequest)
if err := c.BindJSON(&req); err != nil {
if err := c.ShouldBindJSON(&req); err != nil {
Response(c, http.StatusBadRequest, "bad request", nil)
return
}
Expand All @@ -44,7 +44,7 @@ func (h *UserHandler) Create(c *gin.Context){

func (h *UserHandler) Login(c *gin.Context){
req := new(dto.LoginUserRequest)
if err := c.BindJSON(&req); err != nil {
if err := c.ShouldBindJSON(&req); err != nil {
h.Log.Warnln("bad request:", err)
Response(c, http.StatusBadRequest, "bad request", nil)
return
Expand Down

0 comments on commit 6490e62

Please sign in to comment.