Skip to content

Commit

Permalink
add tournaments to big list
Browse files Browse the repository at this point in the history
  • Loading branch information
quorauk committed Sep 28, 2018
1 parent 10b63ea commit d2b409c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ definitions:
type: string
format: url
example: https://www.acme-corp.com
created_at:
type: string
format: int32
example: 2018-09-09T12:28:16.031Z
# Added by API Auto Mocking Plugin
host: brackets.superminerbattle.farm
basePath: /api/1.0.0
Expand Down
3 changes: 3 additions & 0 deletions gen/models/tournament.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions gen/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/challonge/tournaments.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,23 @@ func GetTournamentsForDate(date time.Time) (models []*models.Tournament, err err
}
return models, nil
}

func GetTournamentDateMap() (map[string][]*models.Tournament, error) {
tournaments, err := GetTournaments()
if err != nil {
return nil, err
}
tournamentMap := make(map[string][]*models.Tournament)
for _, tournament := range tournaments {
start, err := time.Parse("2006-01-02T15:04:05.000-07:00", tournament.CreatedAt)
if err == nil {
formatted := start.Format("2006-01-02")
if val, ok := tournamentMap[formatted]; ok {
tournamentMap[formatted] = append(val, tournament)
} else {
tournamentMap[formatted] = []*models.Tournament{tournament}
}
}
}
return tournamentMap, nil
}
17 changes: 17 additions & 0 deletions pkg/handlers/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,22 @@ func SearchEventsHandler(params operations.SearchEventsParams) middleware.Respon
fmt.Println(err)
return operations.NewSearchEventsBadRequest()
}
tournamentMap, err := challonge.GetTournamentDateMap()
if err != nil {
fmt.Println(err)
return operations.NewSearchEventsOK().WithPayload(response)
}
for _, event := range response {
eventStart, err := time.Parse("2006-01-02T15:04:05-0700", event.StartTime)
if err != nil {
fmt.Println("couldn't parse event date", err)
}
formatted := eventStart.Format("2006-01-02")
if err == nil {
if val, ok := tournamentMap[formatted]; ok {
event.Tournaments = val
}
}
}
return operations.NewSearchEventsOK().WithPayload(response)
}

0 comments on commit d2b409c

Please sign in to comment.