Skip to content

Commit

Permalink
Merge pull request #62 from yaken-org/check-name
Browse files Browse the repository at this point in the history
nameから取るようにした
  • Loading branch information
rokuosan authored Sep 15, 2024
2 parents e199b1d + 95c3a0a commit a1f996b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
11 changes: 11 additions & 0 deletions backend/internal/server/handler/user_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ func GetUserAccountBySub(c echo.Context) error {

return c.JSON(http.StatusOK, account)
}

func GetUserAccountByName(c echo.Context) error {
name := c.Param("name")

account, err := service.FindUserAccountByName(name)
if err != nil {
return c.NoContent(http.StatusNotFound)
}

return c.JSON(http.StatusOK, account)
}
9 changes: 5 additions & 4 deletions backend/internal/server/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ func (s *Server) configureRoute() {
e.GET("/health", handler.Health)

api := e.Group("/api")
api.POST("/account", handler.CreateUserAccount) // アカウント作成
api.GET("/account/:id", handler.GetUserAcocunt) // アカウントの詳細取得
api.GET("/account/:id/posts", handler.GetUserPosts) // アカウントの投稿一覧取得
api.GET("/account/sub/:id", handler.GetUserAccountBySub) // フォローしているかどうか
api.POST("/account", handler.CreateUserAccount) // アカウント作成
api.GET("/account/:id", handler.GetUserAcocunt) // アカウントの詳細取得
api.GET("/account/:id/posts", handler.GetUserPosts) // アカウントの投稿一覧取得
api.GET("/account/sub/:id", handler.GetUserAccountBySub) // subからアカウント取得
api.GET("/account/name/:name", handler.GetUserAccountByName) // nameからアカウント取得

api.GET("/post", handler.GetAllPosts) // 投稿一覧取得
api.POST("/post", handler.CreatePost) // 投稿作成
Expand Down
11 changes: 11 additions & 0 deletions backend/internal/service/user_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ func FindUserAccountById(id int64) (*model.UserAccount, error) {
return user, nil
}

func FindUserAccountByName(name string) (*model.UserAccount, error) {
db := database.New()

user := new(model.UserAccount)
if err := model.QueryRow(db.DB, user, "SELECT * FROM user_account WHERE name = ?", name); err != nil {
return nil, err
}

return user, nil
}

func FindUserAccountBySub(sub string) (*model.UserAccount, error) {
db := database.New()
subnumber, err := strconv.ParseInt(sub, 10, 64)
Expand Down

0 comments on commit a1f996b

Please sign in to comment.