Skip to content

Commit

Permalink
Merge pull request #95 from ryo-arima/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ryo-arima authored Sep 16, 2024
2 parents 0799350 + a9e89da commit a6378f3
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 28 deletions.
10 changes: 7 additions & 3 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ root = "."
testdata_dir = "testdata"
bin_dir = "bin"

[env]
PORT = "8080"
MARK1_CONFIG_PATH="etc/main.yaml"

[build]
args_bin = []
bin = "./bin/main"
cmd = "go build -o ./bin/main ."
bin = "./bin/server"
cmd = "dlv debug --headless --listen=:8080 --log --api-version=2 --output=debug/__debug_bin cmd/server/main.go"
after = "rm -f debug/__debug_bin*"
delay = 1000
exclude_dir = ["assets", "bin", "vendor", "testdata"]
exclude_file = []
Expand All @@ -17,7 +22,6 @@ bin_dir = "bin"
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
etc/main.yaml
etc/.mark1
bin/
bin/
__debug_*
debug/
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ update-readme:
./tool/main.sh update-readme

go-test:
./test/main.sh test
./test/main.sh test

debug-server:
dlv connect localhost:8080
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func main() {
panic(err)
}

//hoge
dbConnector := config.NewDBConnector()
redisConnector := config.NewRedisConnector()

Expand Down
37 changes: 34 additions & 3 deletions pkg/client/controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,45 @@ func InitGetUserCmdForAdminUser(conf config.BaseConfig) *cobra.Command {
Short: "get the value of a key",
Long: "get the value of a key",
Run: func(cmd *cobra.Command, args []string) {
option, err := cmd.Flags().GetString("key")
_id, err := cmd.Flags().GetString("id")
if err != nil {
log.Fatal(err)
}
fmt.Println(option)
_uuid, err := cmd.Flags().GetString("uuid")
if err != nil {
log.Fatal(err)
}
_email, err := cmd.Flags().GetString("email")
if err != nil {
log.Fatal(err)
}
_name, err := cmd.Flags().GetString("name")
if err != nil {
log.Fatal(err)
}
_status, err := cmd.Flags().GetString("status")
if err != nil {
log.Fatal(err)
}
_request := request.UserRequest{
User: request.User{
ID: _id,
UUID: _uuid,
Email: _email,
Name: _name,
Status: _status,
},
}
userRepository := repository.NewUserRepository(conf)
userUsecase := usecase.NewUserUsecase(userRepository)
userUsecase.GetUserForPrivate(_request)
},
}
getUserCmd.Flags().StringP("key", "k", "", "cache key")
getUserCmd.Flags().StringP("id", "", "", "id")
getUserCmd.Flags().StringP("uuid", "", "", "uuid")
getUserCmd.Flags().StringP("email", "", "", "email")
getUserCmd.Flags().StringP("name", "", "", "name")
getUserCmd.Flags().StringP("status", "", "", "status")
return getUserCmd
}

Expand Down
28 changes: 22 additions & 6 deletions pkg/client/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

type UserRepository interface {
BootstrapUserForDB(request request.UserRequest) (response response.UserResponse)
GetUserForPublic(request request.UserRequest) (response response.UserResponse)
GetUserForInternal(request request.UserRequest) (response response.UserResponse)
GetUserForPrivate(request request.UserRequest) (response response.UserResponse)
CreateUserForPublic(request request.UserRequest) (response response.UserResponse)
Expand All @@ -39,17 +38,34 @@ func (userRepository userRepository) BootstrapUserForDB(request request.UserRequ
}

// GET
func (userRepository userRepository) GetUserForPublic(request request.UserRequest) (response response.UserResponse) {
return response
}

func (userRepository userRepository) GetUserForInternal(request request.UserRequest) (response response.UserResponse) {
fmt.Println("GetUserForInternal")
return response
}

func (userRepository userRepository) GetUserForPrivate(request request.UserRequest) (response response.UserResponse) {
fmt.Println("GetUserForPrivate")
URL := userRepository.BaseConfig.YamlConfig.Application.Client.ServerEndpoint + "/api/private/users"

resp, err := http.Get(URL)
if err != nil {
return response
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return response
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return response
}

err = json.Unmarshal(body, &response)
if err != nil {
return response
}

return response
}

Expand Down
6 changes: 0 additions & 6 deletions pkg/client/usecase/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

type UserUsecase interface {
BootstrapUserForDB(request request.UserRequest)
GetUserForPublic(request request.UserRequest)
GetUserForInternal(request request.UserRequest)
GetUserForPrivate(request request.UserRequest)
CreateUserForPublic(request request.UserRequest)
Expand All @@ -32,11 +31,6 @@ func (userUsecase userUsecase) BootstrapUserForDB(request request.UserRequest) {
}

// GET
func (userUsecase userUsecase) GetUserForPublic(request request.UserRequest) {
users := userUsecase.UserRepository.GetUserForPublic(request)
fmt.Println(users)
}

func (userUsecase userUsecase) GetUserForInternal(request request.UserRequest) {
users := userUsecase.UserRepository.GetUserForInternal(request)
fmt.Println(users)
Expand Down
5 changes: 3 additions & 2 deletions pkg/entity/request/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ type UserRequest struct {
type User struct {
ID string `json:"id"`
UUID string `json:"uuid"`
Email string `json:"email" validate:"required"`
Email string `json:"email"`
Name string `json:"name"`
Password string `json:"password" validate:"required"`
Password string `json:"password"`
Status string `json:"status"`
}
8 changes: 2 additions & 6 deletions pkg/server/controller/user_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func (userController userControllerForPrivate) GetUsers(c *gin.Context) {
return
}


func (userController userControllerForPrivate) CreateUser(c *gin.Context) {
var userRequest request.UserRequest
if err := c.Bind(&userRequest); err != nil {
Expand All @@ -45,7 +44,6 @@ func (userController userControllerForPrivate) CreateUser(c *gin.Context) {
return
}


func (userController userControllerForPrivate) UpdateUser(c *gin.Context) {
var userRequest request.UserRequest
if err := c.Bind(&userRequest); err != nil {
Expand All @@ -58,7 +56,6 @@ func (userController userControllerForPrivate) UpdateUser(c *gin.Context) {
return
}


func (userController userControllerForPrivate) DeleteUser(c *gin.Context) {
var userRequest request.UserRequest
if err := c.Bind(&userRequest); err != nil {
Expand All @@ -71,7 +68,6 @@ func (userController userControllerForPrivate) DeleteUser(c *gin.Context) {
return
}


func NewUserControllerForPrivate(userRepository repository.UserRepository) UserControllerForPrivate {
return &userControllerForPrivate{ UserRepository: userRepository}
}
return &userControllerForPrivate{UserRepository: userRepository}
}

0 comments on commit a6378f3

Please sign in to comment.