From d36abe8fcb5418b225c6814a21bb90fb55a3a25b Mon Sep 17 00:00:00 2001 From: litsynp Date: Sun, 12 May 2024 11:22:58 +0900 Subject: [PATCH] feat: add FindUserByID API --- cmd/server/handler/user_handler.go | 28 ++++++++++++++++++++++++++++ cmd/server/router.go | 1 + internal/domain/user/model.go | 8 ++++++++ 3 files changed, 37 insertions(+) diff --git a/cmd/server/handler/user_handler.go b/cmd/server/handler/user_handler.go index b747c147..e87bfc75 100644 --- a/cmd/server/handler/user_handler.go +++ b/cmd/server/handler/user_handler.go @@ -128,6 +128,34 @@ func (h *UserHandler) FindUsers(c echo.Context) error { return c.JSON(http.StatusOK, res) } +// FindUserByID godoc +// @Summary 단일 사용자 정보를 조회합니다. +// @Description +// @Tags users +// @Produce json +// @Security FirebaseAuth +// @Param userID path int true "사용자 ID" +// @Success 200 {object} user.WithoutPrivateInfo +// @Router /users/{userID} [get] +func (h *UserHandler) FindUserByID(c echo.Context) error { + // _, err := h.authService.VerifyAuthAndGetUser(c.Request().Context(), c.Request().Header.Get("Authorization")) + // if err != nil { + // return c.JSON(err.StatusCode, err) + // } + + userID, err := pnd.ParseIDFromPath(c, "userID") + if err != nil { + return c.JSON(err.StatusCode, err) + } + + res, err := h.userService.FindUser(c.Request().Context(), user.FindUserParams{ID: userID}) + if err != nil { + return c.JSON(err.StatusCode, err) + } + + return c.JSON(http.StatusOK, res) +} + // FindMyProfile godoc // @Summary 내 프로필 정보를 조회합니다. // @Description diff --git a/cmd/server/router.go b/cmd/server/router.go index 8383f73f..65947eaa 100644 --- a/cmd/server/router.go +++ b/cmd/server/router.go @@ -107,6 +107,7 @@ func NewRouter(app *firebaseinfra.FirebaseApp) (*echo.Echo, error) { userAPIGroup.POST("/check/nickname", userHandler.CheckUserNickname) userAPIGroup.POST("/status", userHandler.FindUserStatusByEmail) userAPIGroup.GET("", userHandler.FindUsers) + userAPIGroup.GET("/:userID", userHandler.FindUserByID) userAPIGroup.GET("/me", userHandler.FindMyProfile) userAPIGroup.PUT("/me", userHandler.UpdateMyProfile) userAPIGroup.DELETE("/me", userHandler.DeleteMyAccount) diff --git a/internal/domain/user/model.go b/internal/domain/user/model.go index a5cfe793..0f9b4852 100644 --- a/internal/domain/user/model.go +++ b/internal/domain/user/model.go @@ -75,3 +75,11 @@ func (u *WithProfileImage) ToMyProfileView() *MyProfileView { FirebaseProviderType: u.FirebaseProviderType, } } + +func (u *WithProfileImage) ToWithoutPrivateInfo() *WithoutPrivateInfo { + return &WithoutPrivateInfo{ + ID: u.ID, + Nickname: u.Nickname, + ProfileImageURL: u.ProfileImageURL, + } +}