diff --git a/controller/PollController.go b/controller/PollController.go index a1f3afb..3da1430 100644 --- a/controller/PollController.go +++ b/controller/PollController.go @@ -6,6 +6,7 @@ import ( "net/http" "strconv" + "github.com/CalebRose/SimFBA/dbprovider" "github.com/CalebRose/SimFBA/managers" "github.com/CalebRose/SimFBA/structs" "github.com/gorilla/mux" @@ -48,7 +49,11 @@ func GetPollSubmission(w http.ResponseWriter, r *http.Request) { } func SyncCollegePoll(w http.ResponseWriter, r *http.Request) { - managers.SyncCollegePollSubmissionForCurrentWeek() + db := dbprovider.GetInstance().GetDB() + ts := managers.GetTimestamp() + managers.SyncCollegePollSubmissionForCurrentWeek(uint(ts.CollegeWeek), uint(ts.CollegeWeekID), uint(ts.CollegeSeasonID)) + ts.TogglePollRan() + db.Save(&ts) } func GetOfficialPollsBySeasonID(w http.ResponseWriter, r *http.Request) { diff --git a/managers/AdminManager.go b/managers/AdminManager.go index f7fa0e5..9c490ce 100644 --- a/managers/AdminManager.go +++ b/managers/AdminManager.go @@ -45,8 +45,10 @@ func MoveUpWeek() structs.Timestamp { RecoverPlayers() CheckNFLRookiesForLetterGrade(strconv.Itoa(int(ts.NFLSeasonID))) ts.SyncToNextWeek() + if ts.CollegeWeek < 21 && !ts.CollegeSeasonOver && !ts.IsOffSeason && !ts.CFBSpringGames { - SyncCollegePollSubmissionForCurrentWeek() + SyncCollegePollSubmissionForCurrentWeek(uint(ts.CollegeWeek), uint(ts.CollegeWeekID), uint(ts.CollegeSeasonID)) + ts.TogglePollRan() } if ts.NFLWeek > 15 { SyncExtensionOffers() diff --git a/managers/PollManager.go b/managers/PollManager.go index 8532d4b..e3ab66d 100644 --- a/managers/PollManager.go +++ b/managers/PollManager.go @@ -50,15 +50,13 @@ func GetPollSubmissionByUsernameWeekAndSeason(username string) structs.CollegePo return submission } -func SyncCollegePollSubmissionForCurrentWeek() { +func SyncCollegePollSubmissionForCurrentWeek(week, weekID, seasonID uint) { db := dbprovider.GetInstance().GetDB() - ts := GetTimestamp() - - weekID := strconv.Itoa(int(ts.CollegeWeekID)) - seasonID := strconv.Itoa(int(ts.CollegeSeasonID)) + weekIDStr := strconv.Itoa(int(weekID)) + seasonIDStr := strconv.Itoa(int(seasonID)) - submissions := GetAllCollegePollsByWeekIDAndSeasonID(weekID, seasonID) + submissions := GetAllCollegePollsByWeekIDAndSeasonID(weekIDStr, seasonIDStr) allCollegeTeams := GetAllCollegeTeams() @@ -113,9 +111,9 @@ func SyncCollegePollSubmissionForCurrentWeek() { }) officialPoll := structs.CollegePollOfficial{ - WeekID: uint(ts.CollegeWeekID), - Week: uint(ts.CollegeWeek), - SeasonID: uint(ts.CollegeSeasonID), + WeekID: weekID, + Week: week, + SeasonID: seasonID, } for idx, v := range allVotes { if idx > 24 { @@ -124,26 +122,24 @@ func SyncCollegePollSubmissionForCurrentWeek() { officialPoll.AssignRank(idx, v) // Get Standings teamID := strconv.Itoa(int(v.TeamID)) - teamStandings := GetCollegeStandingsRecordByTeamID(teamID, seasonID) + teamStandings := GetCollegeStandingsRecordByTeamID(teamID, seasonIDStr) rank := idx + 1 teamStandings.AssignRank(rank) db.Save(&teamStandings) - matches := GetCollegeGamesByTeamIdAndSeasonId(teamID, seasonID) + matches := GetCollegeGamesByTeamIdAndSeasonId(teamID, seasonIDStr) for _, m := range matches { - if m.Week < ts.CollegeWeek { + if m.Week < int(week) { continue } - if m.Week > ts.CollegeWeek { + if m.Week > int(week) { break } m.AssignRank(v.TeamID, uint(rank)) db.Save(&m) } } - ts.TogglePollRan() - db.Save(&ts) db.Create(&officialPoll) }