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

getMeでDBを叩くように変更 #763

Open
wants to merge 10 commits into
base: v2
Choose a base branch
from
12 changes: 11 additions & 1 deletion router/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/samber/lo"
"github.com/traPtitech/Jomon/ent"
"github.com/traPtitech/Jomon/model"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -85,11 +86,20 @@ func (h Handlers) GetMe(c echo.Context) error {
h.Logger.Error("failed to get session", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
user, ok := sess.Values[sessionUserKey].(User)
userInSession, ok := sess.Values[sessionUserKey].(User)
if !ok {
h.Logger.Error("failed to parse stored session as user info")
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user info")
}

user, err := h.Repository.GetUserByID(c.Request().Context(), userInSession.ID)
if err != nil {
if ent.IsNotFound(err) {
h.Logger.Error("failed to find user from DB by ID")
return c.JSON(http.StatusNotFound, err)
}
h.Logger.Error("failed to get user by ID")
return c.JSON(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, user)
}
Loading