-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: v2
Are you sure you want to change the base?
getMeでDBを叩くように変更 #763
Conversation
@@ -82,11 +82,27 @@ 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) | |||
user_in_session, ok := sess.Values[sessionUserKey].(User) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
めちゃ横槍で申し訳ないけど、プライベートな変数はローワーキャメルケースが標準な気がします
user_in_session, ok := sess.Values[sessionUserKey].(User) | |
userInSession, ok := sess.Values[sessionUserKey].(User) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:koreni_natteru:
router/user.go
Outdated
users, err := h.Repository.GetUsers(c.Request().Context()) | ||
if err != nil { | ||
h.Logger.Error("failed to get users from repository", zap.Error(err)) | ||
return echo.NewHTTPError(http.StatusInternalServerError, err) | ||
} | ||
for _, user_i := range users { | ||
if user_i.ID == user_in_session.ID { | ||
return c.JSON(http.StatusOK, user_i) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
おかしい
UserRepository.GetUserByID
があるのでそちらを使うべきです
Line 23 in 444568f
GetUserByID(ctx context.Context, userID uuid.UUID) (*User, error) |
userが存在しない場合は何かしらのerrが返ってくるはずなので、それに応じて後に処理を続けてください
とりあえずこれ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
まずは変数名をcamelCaseにしてください
#725