Skip to content

Commit

Permalink
delete game
Browse files Browse the repository at this point in the history
  • Loading branch information
colin014 committed Mar 27, 2018
1 parent f8a24b2 commit 27ca1e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions api/games.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ func GetGames(c *gin.Context) {

}

func DeleteGame(c *gin.Context) {
log := logger.WithFields(logrus.Fields{"tag": "Delete game"})

log.Info("Start deleting game")

gameId, isOk := getGameId(c)
if !isOk {
return
}

if err := model.DeleteGame(uint(gameId)); err != nil {
log.Errorf("Error during delete game: %s", err.Error())
c.JSON(http.StatusBadRequest, components.ErrorResponse{
Code: http.StatusBadRequest,
Message: "Error during deleting",
Error: err.Error(),
})
return
}

log.Info("Delete succeeded")
c.Status(http.StatusOK)

}

func CreateEvents(c *gin.Context) {

log := logger.WithFields(logrus.Fields{"tag": "Add events"})
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func main() {

v1.POST("/games", api.CreateGame)
v1.GET("/games", api.GetGames)
v1.DELETE("/games/:gameid", api.DeleteGame)

v1.POST("games/:gameid/result", api.CreateResult)
v1.DELETE("games/:gameid/result", api.DeleteResult)
Expand Down
4 changes: 4 additions & 0 deletions model/games.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ func (r *ResultModel) SaveResult(gameId uint) error {
func DeleteResult(gameId uint) error {
return db.Delete(ResultModel{GameId: gameId}).Error
}

func DeleteGame(gameId uint) error {
return db.Delete(GameModel{BaseModel: BaseModel{ID: gameId}}).Error
}

0 comments on commit 27ca1e5

Please sign in to comment.