func SetPlayerName(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) seasonName := r.FormValue("SeasonName") seasonYear := r.FormValue("SeasonYear") playerId := r.FormValue("PlayerId") newPlayerName := r.FormValue("NewPlayerName") c.Infof("Replaceing '%v' with '%v' for season '%v' '%v'", playerId, newPlayerName, seasonName, seasonYear) var season *model.Season if seasonName == "" || seasonYear == "" { c.Infof("Lookup season") tmpSeason := api.GetActiveSeasonWithContext(c) season = &tmpSeason } else { season = api.LoadSeasonByNameYear(c, seasonName, seasonYear) } players := season.GetPlayers(c) targetIndex := playerIndex(players, playerId) replacePlayer := players[targetIndex] replacePlayer.Name = newPlayerName season.Schedule = []byte(strings.Replace(string(season.Schedule), playerId, newPlayerName, -1)) season.Conferences = []byte(strings.Replace(string(season.Conferences), playerId, newPlayerName, -1)) pkey := model.PlayerKey(c, season.Name, season.Year, newPlayerName) season.Players[targetIndex] = pkey err := datastore.RunInTransaction(c, func(c appengine.Context) error { model.SavePlayer(c, season, replacePlayer) err := model.SaveSeason(c, *season) return err }, nil) if err != nil { panic(err) } }
func PlayerBondAddHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) seasonName := r.FormValue("SeasonName") seasonYear := r.FormValue("SeasonYear") playerName := r.FormValue("Player") warcasterName := r.FormValue("Warcaster") warjackName := r.FormValue("Warjack") bondText := r.FormValue("BondText") bondNumber, err := strconv.Atoi(r.FormValue("BondNumber")) if err != nil { panic(err) } season := api.LoadSeasonByNameYear(c, seasonName, seasonYear) player := model.LoadPlayer(c, season, playerName) playerJson := player.CreatePlayerJson() if playerJson.Bonds.ActiveBonds == nil { playerJson.Bonds.ActiveBonds = make([]model.ActiveBond, 0) } newBond := model.ActiveBond{ Warcaster: warcasterName, Warjack: warjackName, BondNumber: bondNumber, BondName: bondText, } playerJson.Bonds.ActiveBonds = append(playerJson.Bonds.ActiveBonds, newBond) updatedPlayer := playerJson.CreatePlayer() model.SavePlayer(c, season, &updatedPlayer) }
func PlayerPotentialBondDeleteHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) seasonName := r.FormValue("SeasonName") seasonYear := r.FormValue("SeasonYear") playerName := r.FormValue("Player") warcasterName := r.FormValue("Warcaster") warjackName := r.FormValue("Warjack") bonus, err := strconv.Atoi(r.FormValue("Bonus")) if err != nil { panic(err) } season := api.LoadSeasonByNameYear(c, seasonName, seasonYear) player := model.LoadPlayer(c, season, playerName) playerJson := player.CreatePlayerJson() index := 0 for ; index < len(playerJson.Bonds.PotentialBonds); index++ { bond := playerJson.Bonds.PotentialBonds[index] if bond.Warcaster == warcasterName && bond.Warjack == warjackName && bond.Bonus == bonus { //We have found the match break } } if index >= len(playerJson.Bonds.PotentialBonds) { http.Error(w, "Could not find matching potential bond", 400) } playerJson.Bonds.PotentialBonds = append(playerJson.Bonds.PotentialBonds[:index], playerJson.Bonds.PotentialBonds[index+1:]...) updatedPlayer := playerJson.CreatePlayer() model.SavePlayer(c, season, &updatedPlayer) }
func PlayerPotentialBondAddHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) c.Infof("Called adad potential bonds") seasonName := r.FormValue("SeasonName") seasonYear := r.FormValue("SeasonYear") playerName := r.FormValue("Player") warcasterName := r.FormValue("Warcaster") warjackName := r.FormValue("Warjack") bonus, err := strconv.Atoi(r.FormValue("Bonus")) if err != nil { panic(err) } season := api.LoadSeasonByNameYear(c, seasonName, seasonYear) player := model.LoadPlayer(c, season, playerName) playerJson := player.CreatePlayerJson() if playerJson.Bonds.PotentialBonds == nil { playerJson.Bonds.PotentialBonds = make([]model.PotentialBond, 0) } newPotential := model.PotentialBond{ Warcaster: warcasterName, Warjack: warjackName, Bonus: bonus, } playerJson.Bonds.PotentialBonds = append(playerJson.Bonds.PotentialBonds, newPotential) updatedPlayer := playerJson.CreatePlayer() model.SavePlayer(c, season, &updatedPlayer) }
func TogglePlayerStandin(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) seasonName := r.FormValue("SeasonName") seasonYear := r.FormValue("SeasonYear") playerId := r.FormValue("PlayerId") var season *model.Season if seasonName == "" || seasonYear == "" { c.Infof("Lookup season") tmpSeason := api.GetActiveSeasonWithContext(c) season = &tmpSeason } else { season = api.LoadSeasonByNameYear(c, seasonName, seasonYear) } player := model.LoadPlayer(c, season, playerId) player.Standin = !player.Standin model.SavePlayer(c, season, player) }
// Handles the update calls of the players func PlayerInjuryUpdateHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) c.Infof("Called player injury update handler") seasonName := r.FormValue("SeasonName") seasonYear := r.FormValue("SeasonYear") playerName := r.FormValue("Player") injuryString := r.FormValue("Injuries") c.Infof("'%v' '%v' '%v' '%v'", seasonName, seasonYear, playerName, injuryString) season := api.LoadSeasonByNameYear(c, seasonName, seasonYear) player := model.LoadPlayer(c, season, playerName) if strings.TrimSpace(injuryString) == "" { player.Injuries = make([]string, 0) } else { player.Injuries = strings.Split(injuryString, ",") } model.SavePlayer(c, season, player) }