Example #1
0
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)
}
Example #2
0
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)
}
Example #3
0
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)
}
Example #4
0
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)
}
Example #5
0
// 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)
}
Example #6
0
func GetPlayer(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	seasonId := r.FormValue("SeasonId")
	playerId := r.FormValue("PlayerId")
	c.Infof("Looking up '%v' for season '%v'", playerId, seasonId)
	var player *model.Player
	var season *model.Season
	if seasonId == "" {
		c.Infof("Lookup season")
		tmpSeason := GetActiveSeasonWithContext(c)
		season = &tmpSeason
	} else {
		season = LoadSeasonById(c, seasonId)
	}
	player = model.LoadPlayer(c, season, playerId)
	c.Infof("%v", player)
	c.Infof(string(player.Bonds))
	playerJson := player.CreatePlayerJson()
	data, err := json.Marshal(playerJson)
	if err != nil {
		panic(err)
	}
	w.Write(data)
}