Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コースの存在チェックの書き方統一 #602

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions webapp/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,16 +910,18 @@ func (h *handlers) SetCourseStatus(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid format.")
}

result, err := h.DB.Exec("UPDATE `courses` SET `status` = ? WHERE `id` = ?", req.Status, courseID)
if err != nil {
var count int
if err := h.DB.Get(&count, "SELECT COUNT(*) FROM `courses` WHERE `id` = ?", courseID); err != nil {
c.Logger().Error(err)
return c.NoContent(http.StatusInternalServerError)
}
if num, err := result.RowsAffected(); err != nil {
if count == 0 {
return echo.NewHTTPError(http.StatusNotFound, "No such course.")
}

if _, err := h.DB.Exec("UPDATE `courses` SET `status` = ? WHERE `id` = ?", req.Status, courseID); err != nil {
c.Logger().Error(err)
return c.NoContent(http.StatusInternalServerError)
} else if num == 0 {
return echo.NewHTTPError(http.StatusNotFound, "No such course.")
}

return c.NoContent(http.StatusOK)
Expand Down