Skip to content

Commit

Permalink
djiscord command changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebRose committed Apr 15, 2024
1 parent bd714e7 commit ce047f9
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 19 deletions.
26 changes: 25 additions & 1 deletion controller/DiscordController.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func GetNFLPlayer(w http.ResponseWriter, r *http.Request) {
panic("User did not provide a first name")
}

player := managers.GetCollegePlayerViaDiscord(id)
player := managers.GetNFLPlayerViaDiscord(id)

json.NewEncoder(w).Encode(player)
}
Expand Down Expand Up @@ -232,3 +232,27 @@ func GetNFLGameStreams(w http.ResponseWriter, r *http.Request) {
streams := managers.GetNFLPlayByPlayStreamData(timeslot, week)
json.NewEncoder(w).Encode(streams)
}

// GetCollegeGamesByConference
func AssignDiscordIDtoCollegeTeam(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
teamID := vars["teamID"]
discordID := vars["discordID"]
if len(teamID) == 0 {
panic("User did not provide conference name")
}

managers.AssignDiscordIDToCollegeTeam(teamID, discordID)
}

// GetCollegeGamesByConference
func AssignDiscordIDtoNFLTeam(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
teamID := vars["teamID"]
discordID := vars["discordID"]
if len(teamID) == 0 {
panic("User did not provide conference name")
}

managers.AssignDiscordIDToNFLTeam(teamID, discordID)
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ func handleRequests() {
myRouter.HandleFunc("/teams/ds/college/week/team/{week}/{team}/", controller.GetWeeklyTeamStatsByTeamAbbrAndWeek).Methods("GET")
myRouter.HandleFunc("/teams/ds/college/season/team/{season}/{team}/", controller.GetSeasonTeamStatsByTeamAbbrAndSeason).Methods("GET")
myRouter.HandleFunc("/ds/cfb/player/{id}", controller.GetCollegePlayer).Methods("GET")
myRouter.HandleFunc("/ds/cfb/assign/discord/{teamID}/{discordID}", controller.AssignDiscordIDtoCollegeTeam).Methods("GET")
myRouter.HandleFunc("/ds/nfl/player/{id}", controller.GetNFLPlayer).Methods("GET")
myRouter.HandleFunc("/ds/nfl/assign/discord/{teamID}/{discordID}", controller.AssignDiscordIDtoNFLTeam).Methods("GET")
myRouter.HandleFunc("/ds/cfb/croots/class/{teamID}/", controller.GetRecruitingClassByTeamID).Methods("GET")
myRouter.HandleFunc("/ds/cfb/croot/{id}", controller.GetRecruitViaDiscord).Methods("GET")
myRouter.HandleFunc("/schedule/ds/current/week/{league}/", controller.GetCurrentWeekGamesByLeague).Methods("GET")
Expand Down
24 changes: 24 additions & 0 deletions managers/DiscordManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"strconv"
"sync"

"github.com/CalebRose/SimFBA/dbprovider"
"github.com/CalebRose/SimFBA/repository"
"github.com/CalebRose/SimFBA/structs"
"github.com/CalebRose/SimFBA/util"
)
Expand Down Expand Up @@ -304,10 +306,12 @@ func GetCFBPlayByPlayStreamData(timeslot, week string, isFBS bool) []structs.Str
HomeTeamCoach: game.HomeTeamCoach,
HomeTeamRank: game.HomeTeamRank,
HomeLabel: homeTeam.TeamName + " " + homeTeam.Mascot,
HomeTeamDiscordID: homeTeam.DiscordID,
AwayTeamID: uint(game.AwayTeamID),
AwayTeam: game.AwayTeam,
AwayTeamCoach: game.AwayTeam,
AwayTeamRank: game.AwayTeamRank,
AwayTeamDiscordID: awayTeam.DiscordID,
AwayLabel: awayTeam.TeamName + " " + awayTeam.Mascot,
HomeOffensiveScheme: homeGameplan.OffensiveScheme,
HomeDefensiveScheme: homeGameplan.DefensiveScheme,
Expand Down Expand Up @@ -423,3 +427,23 @@ func GetNFLPlayByPlayStreamData(timeslot, week string) []structs.StreamResponse

return streams
}

func AssignDiscordIDToCollegeTeam(tID, dID string) {
db := dbprovider.GetInstance().GetDB()

team := GetTeamByTeamID(tID)

team.AssignDiscordID(dID)

repository.SaveCollegeTeamRecord(team, db)
}

func AssignDiscordIDToNFLTeam(tID, dID string) {
db := dbprovider.GetInstance().GetDB()

team := GetNFLTeamByTeamID(tID)

team.AssignDiscordID(dID)

repository.SaveNFLTeamRecord(team, db)
}
42 changes: 27 additions & 15 deletions managers/PlayerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,38 @@ func GetCollegePlayerByCollegePlayerId(CollegePlayerId string) structs.CollegePl
return CollegePlayer
}

func GetCollegePlayerViaDiscord(id string) models.CollegePlayerCSV {
func GetCollegePlayerViaDiscord(id string) models.DiscordPlayerResponse {
db := dbprovider.GetInstance().GetDB()
ts := GetTimestamp()

var CollegePlayer structs.CollegePlayer
seasonID := strconv.Itoa(ts.CollegeSeasonID)
var collegePlayer structs.CollegePlayer

db.Where("id = ?", id).Find(&CollegePlayer)
db.Preload("SeasonStats", "season_id = ?", seasonID).Where("id = ?", id).Find(&collegePlayer)

collegePlayerResponse := models.MapPlayerToCSVModel(CollegePlayer)
collegePlayerResponse := models.MapPlayerToCSVModel(collegePlayer)

return collegePlayerResponse
return models.DiscordPlayerResponse{
Player: collegePlayerResponse,
CollegeStats: collegePlayer.SeasonStats,
}
}

func GetNFLPlayerViaDiscord(id string) models.DiscordPlayerResponse {
db := dbprovider.GetInstance().GetDB()
ts := GetTimestamp()

seasonID := strconv.Itoa(ts.NFLSeasonID)
var nflPlayer structs.NFLPlayer

db.Preload("SeasonStats", "season_id = ?", seasonID).Where("id = ?", id).Find(&nflPlayer)

nflPlayerResponse := models.MapNFLPlayerToCSVModel(nflPlayer)

return models.DiscordPlayerResponse{
Player: nflPlayerResponse,
NFLStats: nflPlayer.SeasonStats,
}
}

func GetCollegePlayerByIdAndWeek(id, week string) models.CollegePlayerCSV {
Expand Down Expand Up @@ -188,16 +210,6 @@ func SetRedshirtStatusForPlayer(playerId string) structs.CollegePlayer {
return player
}

func GetNFLPlayerViaDiscord(id string) structs.NFLPlayer {
db := dbprovider.GetInstance().GetDB()

var nflPlayer structs.NFLPlayer

db.Where("id = ?", id).Find(&nflPlayer)

return nflPlayer
}

func GetAllNFLDraftees() []models.NFLDraftee {
db := dbprovider.GetInstance().GetDB()

Expand Down
8 changes: 5 additions & 3 deletions managers/RequestsManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"

"github.com/CalebRose/SimFBA/dbprovider"
"github.com/CalebRose/SimFBA/repository"
"github.com/CalebRose/SimFBA/structs"
)

Expand Down Expand Up @@ -226,8 +227,9 @@ func RemoveUserFromTeam(teamId string) {
coach.SetAsInactive()

team.RemoveUserFromTeam()
team.AssignDiscordID("")

db.Save(&team)
repository.SaveCollegeTeamRecord(team, db)

db.Save(&coach)

Expand All @@ -238,7 +240,7 @@ func RemoveUserFromTeam(teamId string) {
for _, game := range seasonalGames {
if game.Week >= timestamp.CollegeWeek {
game.UpdateCoach(int(team.ID), "AI")
db.Save(&game)
repository.SaveCFBGameRecord(game, db)
}

}
Expand All @@ -253,7 +255,7 @@ func RemoveUserFromTeam(teamId string) {
recruitingProfile.ActivateAI()
}

db.Save(&recruitingProfile)
repository.SaveRecruitingTeamProfile(recruitingProfile, db)

newsLog := structs.NewsLog{
TeamID: 0,
Expand Down
6 changes: 6 additions & 0 deletions models/CollegePlayerResponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ type NFLPlayerResponse struct {
Stats structs.NFLPlayerStats
SeasonStats structs.NFLPlayerSeasonStats
}

type DiscordPlayerResponse struct {
Player CollegePlayerCSV
CollegeStats structs.CollegePlayerSeasonStats
NFLStats structs.NFLPlayerSeasonStats
}
30 changes: 30 additions & 0 deletions repository/SaveCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,33 @@ func SaveRecruitProfile(profile structs.RecruitPlayerProfile, db *gorm.DB) {
log.Panicln("Could not save team profile")
}
}

func SaveCollegeTeamRecord(team structs.CollegeTeam, db *gorm.DB) {
team.CollegeCoach = structs.CollegeCoach{}
team.RecruitingProfile = structs.RecruitingTeamProfile{}
team.TeamStats = nil
team.TeamStandings = nil
team.TeamRecord = structs.CollegeTeamRecords{}
team.TeamGameplan = structs.CollegeGameplan{}
team.TeamDepthChart = structs.CollegeTeamDepthChart{}
team.TeamSeasonStats = structs.CollegeTeamSeasonStats{}
err := db.Save(&team).Error
if err != nil {
log.Panicln("Could not save team profile")
}
}

func SaveNFLTeamRecord(team structs.NFLTeam, db *gorm.DB) {
team.Capsheet = structs.NFLCapsheet{}
team.Contracts = nil
team.TeamStats = nil
team.Standings = nil
team.DraftPicks = nil
team.TeamGameplan = structs.NFLGameplan{}
team.TeamDepthChart = structs.NFLDepthChart{}
team.TeamSeasonStats = nil
err := db.Save(&team).Error
if err != nil {
log.Panicln("Could not save team profile")
}
}
5 changes: 5 additions & 0 deletions structs/BaseTeam.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type BaseTeam struct {
ColorOne string
ColorTwo string
ColorThree string
DiscordID string
}

func (bt *BaseTeam) RemoveUserFromTeam() {
Expand All @@ -26,3 +27,7 @@ func (bt *BaseTeam) RemoveUserFromTeam() {
func (bt *BaseTeam) AssignUserToTeam(user string) {
bt.Coach = user
}

func (bt *BaseTeam) AssignDiscordID(id string) {
bt.DiscordID = id
}
2 changes: 2 additions & 0 deletions structs/GameResultsResponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ type StreamResponse struct {
HomeLabel string
HomeTeam string
HomeTeamCoach string
HomeTeamDiscordID string
HomeTeamRank uint
HomeOffensiveScheme string
HomeDefensiveScheme string
AwayTeamID uint
AwayLabel string
AwayTeam string
AwayTeamCoach string
AwayTeamDiscordID string
AwayTeamRank uint
AwayOffensiveScheme string
AwayDefensiveScheme string
Expand Down

0 comments on commit ce047f9

Please sign in to comment.