Skip to content

Commit

Permalink
add validator to PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitoyama committed Oct 24, 2023
1 parent fa55f46 commit cc7b5dd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions router/questions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ func (q *Question) EditQuestion(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest)
}

validate, err := getValidator(c)
if err != nil {
c.Logger().Errorf("failed to get validator: %+v", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

err = validate.Struct(req)
if err != nil {
c.Logger().Infof("validation failed: %+v", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

switch req.QuestionType {
case "Text":
//正規表現のチェック
Expand Down
12 changes: 12 additions & 0 deletions router/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ func (r *Response) EditResponse(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest)
}

validate, err := getValidator(c)
if err != nil {
c.Logger().Errorf("failed to get validator: %+v", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

err = validate.Struct(req)
if err != nil {
c.Logger().Infof("validation failed: %+v", err)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

limit, err := r.GetQuestionnaireLimit(c.Request().Context(), req.ID)
if err != nil {
if errors.Is(err, model.ErrRecordNotFound) {
Expand Down

0 comments on commit cc7b5dd

Please sign in to comment.