feat: add empty handler
This commit is contained in:
23
handlers/cage_handler.go
Normal file
23
handlers/cage_handler.go
Normal file
@@ -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){
|
||||
|
||||
}
|
||||
27
handlers/game_handler.go
Normal file
27
handlers/game_handler.go
Normal file
@@ -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){
|
||||
|
||||
}
|
||||
23
handlers/hamster_handler.go
Normal file
23
handlers/hamster_handler.go
Normal file
@@ -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){
|
||||
|
||||
}
|
||||
@@ -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("")
|
||||
//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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user