func (gs GameService) updateGame(c *gin.Context) { var game domain.Game c.Bind(&game) gs.doSaveGame(game, c) }
func (ls LeagueService) updateLeague(c *gin.Context) { var league domain.League c.Bind(&league) ls.doSaveLeague(league, c) }
func (ps PlayerService) updatePlayer(c *gin.Context) { var player domain.Player c.Bind(&player) ps.doSavePlayer(player, c) }
func (cds contextDefinitionService) saveContext(c *gin.Context) { var contextDefinition ContextDefinition c.Bind(&contextDefinition) if !cds._isValid(contextDefinition) { c.AbortWithStatus(http.StatusBadRequest) return } user := getCurrentUserFromGinContext(c) // Run all of this in a transaction (even if we are on service level) err := datastore.RunInTransaction(getGaeContext(c), func(gaeCtx appengine.Context) error { contextDao := contextDefinitionDao{dao{gaeCtx}} idExists, err := contextDao.checkIDExists(contextDefinition.ID) if err != nil { return err } if idExists { return ErrIDAlreadyExists } contextDefinition.Owner = datastore.NewKey(gaeCtx, entityUser, user.UserID, 0, nil) contextDefinition.Active = true err = contextDao.saveContext(contextDefinition) if err != nil { return err } return nil }, &datastore.TransactionOptions{ XG: true, }) if err != nil { returnStatus := http.StatusInternalServerError if err == ErrIDAlreadyExists { returnStatus = http.StatusConflict } c.AbortWithError(returnStatus, err) return } contextDefinition.RemoveLink(relCreate) contextDefinition.RemoveLink(relCheckID) if productionDomain := os.Getenv("PRODUCTION_DOMAIN"); productionDomain != "" { contextDefinition.AddLink(relSelf, fmt.Sprintf("http://%s.%s", contextDefinition.ID, productionDomain)) } c.JSON(200, contextDefinition) }
func (ls LeagueService) createLeague(c *gin.Context) { var league domain.League c.Bind(&league) league.ID = 0 league.Active = true ls.doSaveLeague(league, c) }
func (ps PlayerService) createPlayer(c *gin.Context) { var player domain.Player c.Bind(&player) player.ID = 0 player.Active = true ps.doSavePlayer(player, c) }
func (gs GameService) createGame(c *gin.Context) { leagueID := getLeagueIDFromURL(c) var game domain.Game c.Bind(&game) game.ID = 0 game.LeagueID = leagueID gs.doSaveGame(game, c) }
func (as AdminService) importScoreBoardV1(c *gin.Context) { var importDefinition domain.ScoreBoardV1Import c.Bind(&importDefinition) if importDefinition.DbDumpUrl == "" { c.AbortWithStatus(http.StatusBadRequest) return } createTask := &taskqueue.Task{ Path: "/tasks/import/scoreboardv1", Payload: []byte(importDefinition.DbDumpUrl), } hostName, _ := appengine.ModuleHostname(utils.GetGaeRootContext(c), appengine.ModuleName(utils.GetGaeRootContext(c)), "", "") createTask.Header = http.Header{} createTask.Header.Set("Host", hostName) createTask.Header.Set(utils.NamespaceHeader, utils.GetNamespace(c)) _, err := taskqueue.Add(utils.GetGaeRootContext(c), createTask, "contextqueue") if err != nil { utils.GetGaeRootContext(c).Errorf("Error calling taskqueue.Add in importScoreBoardV1: %v", err) c.AbortWithError(http.StatusInternalServerError, err) return } importDao := dao.CreateImportDao(c) importStatus, err := importDao.SetStatus(true, 0, 0, 0, 0, 0, 0) if err != nil { utils.GetGaeRootContext(c).Errorf("Error calling importDao.setStatus in importScoreBoardV1: %v", err) c.AbortWithError(http.StatusInternalServerError, err) return } importStatus.AddLink(relImportStatus, "/api/admin/import/scoreboardv1/status") c.JSON(200, importStatus) }