feat: use username instead of uid (#1977)

* #1916 replace userId to username

* resolve

---------

Co-authored-by: Александр Тумайкин <AATumaykin@tsum.ru>
This commit is contained in:
Alexandr Tumaykin
2023-07-20 14:48:39 +03:00
committed by GitHub
parent 336b32004d
commit f91f09adea
24 changed files with 189 additions and 109 deletions

View File

@ -258,6 +258,26 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) {
return c.JSON(http.StatusOK, userMessage)
})
// GET /user/:username - Get user by username.
g.GET("/user/:username", func(c echo.Context) error {
ctx := c.Request().Context()
username := c.Param("username")
user, err := s.Store.GetUser(ctx, &store.FindUser{Username: &username})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user").SetInternal(err)
}
if user == nil {
return echo.NewHTTPError(http.StatusNotFound, "User not found")
}
userMessage := convertUserFromStore(user)
// data desensitize
userMessage.OpenID = ""
userMessage.Email = ""
return c.JSON(http.StatusOK, userMessage)
})
// PUT /user/:id - Update user by id.
g.PATCH("/user/:id", func(c echo.Context) error {
ctx := c.Request().Context()