add missing path property handling

This commit is contained in:
Jeffrey Duroyon
2020-05-18 00:56:43 +02:00
parent ca8e42388b
commit f6e0a826a1
21 changed files with 292 additions and 114 deletions

View File

@@ -21,16 +21,16 @@ func (hc *handlersContext) getAllGames(c *gin.Context) {
}
func (hc *handlersContext) getAGame(c *gin.Context) {
gameId := c.Param("gameId")
gameID := c.Param("gameID")
err := hc.validator.VarCtx(c, gameId, "uuid4")
err := hc.validator.VarCtx(c, gameID, "uuid4")
if err != nil {
utils.JSONError(c.Writer, validators.NewDataValidationAPIError(err))
return
}
game, err := hc.gameService.GetAGameById(gameId)
if e, ok := err.(*dao.DAOError); ok {
game, err := hc.gameService.GetAGameByID(gameID)
if e, ok := err.(*dao.Error); ok {
switch {
case e.Type == dao.ErrTypeNotFound:
utils.JSONErrorWithMessage(c.Writer, model.ErrNotFound, "Game not found")
@@ -76,7 +76,7 @@ func (hc *handlersContext) createAGame(c *gin.Context) {
}
err = hc.db.CreateGame(&gameToCreate)
if e, ok := err.(*dao.DAOError); ok {
if e, ok := err.(*dao.Error); ok {
switch {
case e.Type == dao.ErrTypeDuplicate:
utils.JSONErrorWithMessage(c.Writer, model.ErrAlreadyExists, "Game already exists")
@@ -101,7 +101,7 @@ func (hc *handlersContext) updateAGame(c *gin.Context) {
func (hc *handlersContext) deleteAGame(c *gin.Context) {
gameID := c.Param("gameId")
gameID := c.Param("gameID")
err := hc.validator.VarCtx(c, gameID, "uuid4")
if err != nil {
@@ -110,8 +110,8 @@ func (hc *handlersContext) deleteAGame(c *gin.Context) {
}
// check game id given in URL exists
_, err = hc.db.GetGameById(gameID)
if e, ok := err.(*dao.DAOError); ok {
_, err = hc.db.GetGameByID(gameID)
if e, ok := err.(*dao.Error); ok {
switch {
case e.Type == dao.ErrTypeNotFound:
utils.JSONErrorWithMessage(c.Writer, model.ErrNotFound, "Game to delete not found")
@@ -128,7 +128,7 @@ func (hc *handlersContext) deleteAGame(c *gin.Context) {
}
err = hc.db.DeleteGame(gameID)
if e, ok := err.(*dao.DAOError); ok {
if e, ok := err.(*dao.Error); ok {
switch {
case e.Type == dao.ErrTypeNotFound:
utils.JSONErrorWithMessage(c.Writer, model.ErrNotFound, "Game to delete not found")
@@ -148,5 +148,20 @@ func (hc *handlersContext) deleteAGame(c *gin.Context) {
}
func (hc *handlersContext) getHamstersOfGame(c *gin.Context) {
gameID := c.Param("gameID")
err := hc.validator.VarCtx(c, gameID, "uuid4")
if err != nil {
utils.JSONError(c.Writer, validators.NewDataValidationAPIError(err))
return
}
games, err := hc.db.GetHamstersOfGame(gameID)
if err != nil {
utils.GetLoggerFromCtx(c).WithError(err).Error("error while getting games")
utils.JSONErrorWithMessage(c.Writer, model.ErrInternalServer, "Error while getting games")
return
}
utils.JSON(c.Writer, http.StatusOK, games)
}