mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Migrate to TBA v3 API.
This commit is contained in:
@@ -264,7 +264,6 @@ func (web *Web) getOfficialTeamInfo(teamId int) (*model.Team, error) {
|
||||
// Create the team variable that stores the result
|
||||
var team model.Team
|
||||
|
||||
// If team info download is enabled, download the current teams data (caching isn't easy with the new paging system in the api)
|
||||
if web.arena.EventSettings.TBADownloadEnabled {
|
||||
tbaTeam, err := web.arena.TbaClient.GetTeam(teamId)
|
||||
if err != nil {
|
||||
@@ -287,16 +286,18 @@ func (web *Web) getOfficialTeamInfo(teamId int) (*model.Team, error) {
|
||||
|
||||
var accomplishmentsBuffer bytes.Buffer
|
||||
|
||||
// Generate accomplishments string
|
||||
for _, award := range recentAwards {
|
||||
// Generate string of recent awards in reverse chronological order.
|
||||
for i := len(recentAwards) - 1; i >= 0; i-- {
|
||||
award := recentAwards[i]
|
||||
if time.Now().Year()-award.Year <= 2 {
|
||||
accomplishmentsBuffer.WriteString(fmt.Sprintf("<p>%d %s - %s</p>", award.Year, award.EventName, award.Name))
|
||||
accomplishmentsBuffer.WriteString(fmt.Sprintf("<p>%d %s - %s</p>", award.Year, award.EventName,
|
||||
award.Name))
|
||||
}
|
||||
}
|
||||
|
||||
// Use those variables to make a team object
|
||||
team = model.Team{Id: teamId, Name: tbaTeam.Name, Nickname: tbaTeam.Nickname, City: tbaTeam.Locality,
|
||||
StateProv: tbaTeam.Reigon, Country: tbaTeam.Country, RookieYear: tbaTeam.RookieYear,
|
||||
team = model.Team{Id: teamId, Name: tbaTeam.Name, Nickname: tbaTeam.Nickname, City: tbaTeam.City,
|
||||
StateProv: tbaTeam.StateProv, Country: tbaTeam.Country, RookieYear: tbaTeam.RookieYear,
|
||||
RobotName: robotName, Accomplishments: accomplishmentsBuffer.String()}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -25,23 +25,23 @@ func TestSetupTeams(t *testing.T) {
|
||||
teamInfoBody := `{
|
||||
"website": "http://www.team254.com",
|
||||
"name": "NASA Ames Research Center",
|
||||
"locality": "San Jose",
|
||||
"city": "San Jose",
|
||||
"rookie_year": 1999,
|
||||
"region": "CA",
|
||||
"state_prov": "CA",
|
||||
"team_number": 254,
|
||||
"location": "San Jose, CA, USA",
|
||||
"key": "frc254",
|
||||
"country_name": "USA",
|
||||
"country": "USA",
|
||||
"nickname": "The Cheesy Poofs"
|
||||
}`
|
||||
teamRobotsBody := `{
|
||||
"2017": {
|
||||
teamRobotsBody := `[
|
||||
{
|
||||
"team_key": "frc33",
|
||||
"name": "Buzz 22",
|
||||
"key": "frc33_2017",
|
||||
"year": 2017
|
||||
}
|
||||
}`
|
||||
]`
|
||||
teamAwardsBody := `[{
|
||||
"event_key": "2014cmp",
|
||||
"award_type": 1,
|
||||
@@ -68,9 +68,9 @@ func TestSetupTeams(t *testing.T) {
|
||||
}]`
|
||||
eventBody := `{ "name": "Championship" }`
|
||||
tbaServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.Contains(r.RequestURI, "history/robots") {
|
||||
if strings.Contains(r.RequestURI, "robots") {
|
||||
fmt.Fprintln(w, teamRobotsBody)
|
||||
} else if strings.Contains(r.RequestURI, "history/awards") {
|
||||
} else if strings.Contains(r.RequestURI, "awards") {
|
||||
fmt.Fprintln(w, teamAwardsBody)
|
||||
} else if strings.Contains(r.RequestURI, "team") {
|
||||
fmt.Fprintln(w, teamInfoBody)
|
||||
|
||||
Reference in New Issue
Block a user