From 4369438ff2440fd90cd1d43217abf52605eaf1ae Mon Sep 17 00:00:00 2001 From: Jeffrey Duroyon Date: Sun, 10 May 2020 01:28:30 +0200 Subject: [PATCH] feat: add empty handler --- handlers/cage_handler.go | 23 +++++++++++++++++++ handlers/game_handler.go | 27 ++++++++++++++++++++++ handlers/hamster_handler.go | 23 +++++++++++++++++++ handlers/handler.go | 45 ++++++++++++++++++++----------------- handlers/user_handler.go | 12 +++++----- 5 files changed, 103 insertions(+), 27 deletions(-) create mode 100644 handlers/cage_handler.go create mode 100644 handlers/game_handler.go create mode 100644 handlers/hamster_handler.go diff --git a/handlers/cage_handler.go b/handlers/cage_handler.go new file mode 100644 index 0000000..4cd04da --- /dev/null +++ b/handlers/cage_handler.go @@ -0,0 +1,23 @@ +package handlers + +import "github.com/gin-gonic/gin" + +func (hc *handlersContext) getAllCages(c *gin.Context){ + +} + +func (hc *handlersContext) getACage(c *gin.Context){ + +} + +func (hc *handlersContext) createACage(c *gin.Context){ + +} + +func (hc *handlersContext) updateACage(c *gin.Context){ + +} + +func (hc *handlersContext) deleteACage(c *gin.Context){ + +} diff --git a/handlers/game_handler.go b/handlers/game_handler.go new file mode 100644 index 0000000..5a71af5 --- /dev/null +++ b/handlers/game_handler.go @@ -0,0 +1,27 @@ +package handlers + +import "github.com/gin-gonic/gin" + +func (hc *handlersContext) getAllGames(c *gin.Context){ + +} + +func (hc *handlersContext) getAGame(c *gin.Context){ + +} + +func (hc *handlersContext) createAGame(c *gin.Context){ + +} + +func (hc *handlersContext) updateAGame(c *gin.Context){ + +} + +func (hc *handlersContext) deleteAGame(c *gin.Context){ + +} + +func (hc *handlersContext) getHamstersOfGame(c *gin.Context){ + +} \ No newline at end of file diff --git a/handlers/hamster_handler.go b/handlers/hamster_handler.go new file mode 100644 index 0000000..831429d --- /dev/null +++ b/handlers/hamster_handler.go @@ -0,0 +1,23 @@ +package handlers + +import "github.com/gin-gonic/gin" + +func (hc *handlersContext) getAllHamsters(c *gin.Context){ + +} + +func (hc *handlersContext) getAHamster(c *gin.Context){ + +} + +func (hc *handlersContext) createAHamster(c *gin.Context){ + +} + +func (hc *handlersContext) updateAHamster(c *gin.Context){ + +} + +func (hc *handlersContext) deleteAHamster(c *gin.Context){ + +} diff --git a/handlers/handler.go b/handlers/handler.go index aa01ed3..c4675c2 100755 --- a/handlers/handler.go +++ b/handlers/handler.go @@ -62,35 +62,38 @@ func NewRouter(config *Config) *gin.Engine { public.Handle(http.MethodGet, "/_health", hc.GetHealth) userRoute := public.Group("/users") - userRoute.Handle("LOGIN", "", hc.ConnectUser) - userRoute.Handle(http.MethodPost, "", hc.CreateUser) + userRoute.Handle("LOGIN", "", hc.connectUser) + userRoute.Handle(http.MethodPost, "", hc.createUser) - securedUserRoute := userRoute.Group("") + securedUserRoute := userRoute.Group("") //TODO add secure auth - securedUserRoute.Handle(http.MethodGet, "", hc.GetAllUsers) - securedUserRoute.Handle(http.MethodGet, "/:userId", hc.GetUser) - securedUserRoute.Handle(http.MethodPut, "/:userId", hc.UpdateUser) - securedUserRoute.Handle(http.MethodDelete, "/:userId", hc.DeleteUser) + securedUserRoute.Handle(http.MethodGet, "", hc.getAllUsers) + securedUserRoute.Handle(http.MethodGet, "/:userId", hc.getUser) + securedUserRoute.Handle(http.MethodPut, "/:userId", hc.updateUser) + securedUserRoute.Handle(http.MethodDelete, "/:userId", hc.deleteUser) // end: user routes gameRoute := securedUserRoute.Group("/:userId/games") - gameRoute.Handle(http.MethodGet, "", nil) - gameRoute.Handle(http.MethodGet, "/:gameId", nil) - gameRoute.Handle(http.MethodPost, "/:gameId", nil) - gameRoute.Handle(http.MethodPut, "/:gameId",nil) - gameRoute.Handle(http.MethodGet, "/:gameId/hamsters",nil) + gameRoute.Handle(http.MethodGet, "", hc.getAllGames) + gameRoute.Handle(http.MethodGet, "/:gameId", hc.getAGame) + gameRoute.Handle(http.MethodPost, "/:gameId", hc.createAGame) + gameRoute.Handle(http.MethodPut, "/:gameId",hc.updateAGame) + gameRoute.Handle(http.MethodGet, "/:gameId/hamsters",hc.getHamstersOfGame) + gameRoute.Handle(http.MethodDelete, "/:gameId",hc.deleteAGame) cageRoute := gameRoute.Group("/:gameId/cages") - cageRoute.Handle(http.MethodGet, "",nil) - cageRoute.Handle(http.MethodGet, "/:cageId", nil) - cageRoute.Handle(http.MethodPost, "/:cageId", nil) - cageRoute.Handle(http.MethodPut, "/:cageId", nil) + cageRoute.Handle(http.MethodGet, "",hc.getAllCages) + cageRoute.Handle(http.MethodGet, "/:cageId", hc.getACage) + cageRoute.Handle(http.MethodPost, "/:cageId", hc.createACage) + cageRoute.Handle(http.MethodPut, "/:cageId", hc.updateACage) + cageRoute.Handle(http.MethodDelete, "/:cageId",hc.deleteACage) - hamsterRoute := cageRoute.Group("/:cageId/hamster") - hamsterRoute.Handle(http.MethodGet, "",nil) - hamsterRoute.Handle(http.MethodGet, "/:cageId", nil) - hamsterRoute.Handle(http.MethodPost, "/:cageId", nil) - hamsterRoute.Handle(http.MethodPut, "/:cageId", nil) + hamsterRoute := cageRoute.Group("/:cageId/hamsters") + hamsterRoute.Handle(http.MethodGet, "",hc.getAllHamsters) + hamsterRoute.Handle(http.MethodGet, "/:hamsterId", hc.getAHamster) + hamsterRoute.Handle(http.MethodPost, "/:hamsterId", hc.createAHamster) + hamsterRoute.Handle(http.MethodPut, "/:hamsterId", hc.updateAHamster) + hamsterRoute.Handle(http.MethodDelete, "/:hamsterId", hc.deleteAHamster) return router } diff --git a/handlers/user_handler.go b/handlers/user_handler.go index 4e3fbe7..d417e50 100755 --- a/handlers/user_handler.go +++ b/handlers/user_handler.go @@ -16,7 +16,7 @@ import ( var httpClient = &http.Client{} -func (hc *handlersContext) GetAllUsers(c *gin.Context) { +func (hc *handlersContext) getAllUsers(c *gin.Context) { users, err := hc.db.GetAllUsers() if err != nil { utils.GetLoggerFromCtx(c).WithError(err).Error("error while getting users") @@ -26,7 +26,7 @@ func (hc *handlersContext) GetAllUsers(c *gin.Context) { utils.JSON(c.Writer, http.StatusOK, users) } -func (hc *handlersContext) ConnectUser(c *gin.Context) { +func (hc *handlersContext) connectUser(c *gin.Context) { authorizationHeader := c.GetHeader("Authorization") authorizationHeaderSplitted := strings.Split(authorizationHeader, " ") if len(authorizationHeaderSplitted) != 2 { @@ -66,7 +66,7 @@ func (hc *handlersContext) ConnectUser(c *gin.Context) { utils.JSON(c.Writer, 200, user) } -func (hc *handlersContext) CreateUser(c *gin.Context) { +func (hc *handlersContext) createUser(c *gin.Context) { b, err := c.GetRawData() if err != nil { utils.GetLoggerFromCtx(c).WithError(err).Error("error while creating user, read data fail") @@ -111,7 +111,7 @@ func (hc *handlersContext) CreateUser(c *gin.Context) { utils.JSON(c.Writer, http.StatusCreated, user) } -func (hc *handlersContext) GetUser(c *gin.Context) { +func (hc *handlersContext) getUser(c *gin.Context) { userID := c.Param("id") err := hc.validator.VarCtx(c, userID, "uuid4") @@ -145,7 +145,7 @@ func (hc *handlersContext) GetUser(c *gin.Context) { utils.JSON(c.Writer, http.StatusOK, user) } -func (hc *handlersContext) DeleteUser(c *gin.Context) { +func (hc *handlersContext) deleteUser(c *gin.Context) { userID := c.Param("id") err := hc.validator.VarCtx(c, userID, "uuid4") @@ -192,7 +192,7 @@ func (hc *handlersContext) DeleteUser(c *gin.Context) { utils.JSON(c.Writer, http.StatusNoContent, nil) } -func (hc *handlersContext) UpdateUser(c *gin.Context) { +func (hc *handlersContext) updateUser(c *gin.Context) { userID := c.Param("id") err := hc.validator.VarCtx(c, userID, "uuid4")