Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions controller/AdminController.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (

// GetTimeStamp
func GetCurrentTimestamp(w http.ResponseWriter, r *http.Request) {

timestamp := managers.GetTimestamp()

json.NewEncoder(w).Encode(timestamp)
}

Expand All @@ -29,23 +27,18 @@ func SyncTimestamp(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

newTimestamp := managers.UpdateTimestamp(updateTimestampDto)

json.NewEncoder(w).Encode(newTimestamp)
}

func SyncRecruiting(w http.ResponseWriter, r *http.Request) {
ts := managers.GetTimestamp()

managers.SyncRecruiting(ts)

json.NewEncoder(w).Encode("Sync Complete")
}

func SyncWeek(w http.ResponseWriter, r *http.Request) {
newTimestamp := managers.MoveUpWeek()

json.NewEncoder(w).Encode(newTimestamp)
}

Expand All @@ -55,16 +48,13 @@ func SyncTimeslot(w http.ResponseWriter, r *http.Request) {
if len(timeslot) == 0 {
log.Panicln("Missing timeslot!")
}

managers.SyncTimeslot(timeslot)

json.NewEncoder(w).Encode("Timeslot updated")
}

func SyncFreeAgencyRound(w http.ResponseWriter, r *http.Request) {
managers.SyncFreeAgencyOffers()
managers.MoveUpInOffseasonFreeAgency()
// managers.AttemptToDecreaseMinimumValues()
json.NewEncoder(w).Encode("Moved to next free agency round")
}

Expand All @@ -76,39 +66,15 @@ func GetWeeksInSeason(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
seasonID := vars["seasonID"]
weekID := vars["weekID"]

weeks := managers.GetWeeksInASeason(seasonID, weekID)

json.NewEncoder(w).Encode(weeks)
}

// CreateCollegeRecruit?

// CreateNFLPlayer -- Create NFL Player from template, and then synthetically progress them based on the year of input

// UpdateTeamRecruitingProfile

// ApproveCoachForTeam

// RemoveCoachFromTeam

// UpdateTeam

// RunProgressionsForCollege
func RunProgressionsForCollege(w http.ResponseWriter, r *http.Request) {

}

// GenerateWalkons
func GenerateWalkOns(w http.ResponseWriter, r *http.Request) {
managers.GenerateWalkOns()
fmt.Println(w, "Walk ons successfully generated.")
}

// RunProgressionsForNFL

// RunProgressionsForJuco?

func SyncTeamRecruitingRanks(w http.ResponseWriter, r *http.Request) {
managers.SyncTeamRankings()
fmt.Println(w, "Team Ranks successfully generated.")
Expand Down
1 change: 1 addition & 0 deletions controller/TSController.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func CreateTSModelsFile(w http.ResponseWriter, r *http.Request) {
Add(structs.CollegeGame{}).
Add(structs.NFLCapsheet{}).
Add(structs.NFLContract{}).
Add(structs.NFLUDFABoard{}).
Add(structs.FreeAgencyOffer{}).
Add(structs.FreeAgencyOfferDTO{}).
Add(structs.NFLWaiverOffDTO{}).
Expand Down
86 changes: 86 additions & 0 deletions controller/UDFAController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package controller

import (
"encoding/json"
"net/http"

"github.com/CalebRose/SimFBA/managers"
"github.com/CalebRose/SimFBA/structs"
"github.com/gorilla/mux"
)

// GetUDFABoardByTeamID returns the user's specific UDFA bidding board
func GetUDFABoardByTeamID(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
teamID := vars["teamID"]
if len(teamID) == 0 {
panic("User did not provide TeamID")
}

board := managers.GetUDFABoardByTeamID(teamID)
json.NewEncoder(w).Encode(board)
}

// AddPlayerToUDFABoard adds a single player to the user's board
func AddPlayerToUDFABoard(w http.ResponseWriter, r *http.Request) {
var profile structs.NFLUDFAProfile
err := json.NewDecoder(r.Body).Decode(&profile)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// Call the manager to execute the DB logic
managers.AddPlayerToUDFABoard(profile)

// Return success to the frontend
json.NewEncoder(w).Encode(true)
}

// SaveUDFABoard updates the points assigned to all players on the board
func SaveUDFABoard(w http.ResponseWriter, r *http.Request) {
var board structs.NFLUDFABoard
err := json.NewDecoder(r.Body).Decode(&board)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

// Call the manager to execute the DB logic
managers.SaveUDFABoard(board)

// Return success to the frontend
json.NewEncoder(w).Encode(true)
}

// RemovePlayerFromUDFABoard deletes a player from the user's board
func RemovePlayerFromUDFABoard(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
profileID := vars["profileID"]
if len(profileID) == 0 {
panic("User did not provide profileID")
}

// Call the manager to execute the DB logic
managers.RemovePlayerFromUDFABoard(profileID)

// Return success to the frontend
json.NewEncoder(w).Encode(true)
}

// ProcessUDFAs triggers the batch signing process (Used by Admin)
func ProcessUDFAs(w http.ResponseWriter, r *http.Request) {
dryRunParam := r.URL.Query().Get("dryRun")
isDryRun := dryRunParam == "true"

// Trigger the batch signing logic
managers.ProcessUDFAs(isDryRun)

// Return a clean success message to display in the Admin Panel
msg := "LIVE UDFA Signings Executed Successfully!"
if isDryRun {
msg = "Dry Run Complete. Check backend server console for simulation results."
}

json.NewEncoder(w).Encode(msg)
}
2 changes: 2 additions & 0 deletions dbprovider/dbprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func (p *Provider) InitDatabase() bool {
// db.AutoMigrate(&structs.NFLStandings{})
// db.AutoMigrate(&structs.NFLRequest{})
// db.AutoMigrate(&structs.NFLWaiverOffer{})
// db.AutoMigrate(&structs.NFLUDFABoard{})
// db.AutoMigrate(&structs.NFLUDFAProfile{})

// All
// db.AutoMigrate(&structs.AdminRecruitModifier{})
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func handleRequests() http.Handler {
apiRouter.HandleFunc("/admin/trades/accept/sync/{proposalID}", controller.SyncAcceptedTrade).Methods("GET")
apiRouter.HandleFunc("/admin/trades/veto/sync/{proposalID}", controller.VetoAcceptedTrade).Methods("GET")
apiRouter.HandleFunc("/admin/trades/cleanup", controller.CleanUpRejectedTrades).Methods("GET")
apiRouter.HandleFunc("/admin/process-udfas", controller.ProcessUDFAs).Methods("GET")

// Bootstrap
apiRouter.HandleFunc("/bootstrap/teams", controller.BootstrapTeamData).Methods("GET")
Expand Down Expand Up @@ -425,6 +426,13 @@ func handleRequests() http.Handler {
apiRouter.HandleFunc("/portal/player/scout/{id}", controller.GetScoutingDataByTransfer).Methods("GET")
apiRouter.HandleFunc("/portal/export/players/", controller.ExportPortalPlayersToCSV).Methods("GET")

// UDFA Controls

apiRouter.HandleFunc("/nfl/udfa/board/{teamID}", controller.GetUDFABoardByTeamID).Methods("GET")
apiRouter.HandleFunc("/nfl/udfa/board/add", controller.AddPlayerToUDFABoard).Methods("POST")
apiRouter.HandleFunc("/nfl/udfa/board/save", controller.SaveUDFABoard).Methods("POST")
apiRouter.HandleFunc("/nfl/udfa/board/remove/{profileID}", controller.RemovePlayerFromUDFABoard).Methods("GET")

// Discord Controls
apiRouter.HandleFunc("/ds/cfb/team/{teamID}/", controller.GetTeamByTeamIDForDiscord).Methods("GET")
apiRouter.HandleFunc("/ds/college/player/indstats/{id}/{week}/", controller.GetCollegePlayerStatsByNameTeamAndWeek).Methods("GET")
Expand Down
67 changes: 67 additions & 0 deletions managers/ForumManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,70 @@ func buildRecruitingSyncParagraphs(season, week int, signings []string) []string

return paragraphs
}

// ─────────────────────────────────────────────
// NFL UDFA Sync Thread
// ─────────────────────────────────────────────

// CreateNFLUDFASyncForumThread creates a system-generated forum thread in
// the "media-simnfl" subforum summarising the signings from the UDFA period.
func CreateNFLUDFASyncForumThread(season int, signings []string) {
ctx := context.Background()

title := fmt.Sprintf("SimNFL: Season %d UDFA Signings", season)
eventKey := fmt.Sprintf("udfa_sync:nfl:season%d", season)

paragraphs := buildNFLUDFASyncParagraphs(season, signings)
bodyText := strings.Join(paragraphs, "\n\n")
richBody := buildRichPostBody(paragraphs)

input := fbsvc.CreateForumThreadInput{
ForumID: "media-simnfl",
ForumPath: []string{"media", "simnfl"},
Title: title,
AuthorUID: "system",
AuthorUsername: "SimSN",
AuthorDisplayName: "SimSN System",
CreatedByType: fbsvc.CreatedBySystem,
ThreadType: fbsvc.ThreadTypeStandard,
FirstPostBodyText: bodyText,
FirstPostBody: richBody,
ReferencedLeague: "nfl",
ExternalEventKey: eventKey,
}

thread, err := fbsvc.CreateThread(ctx, input)
if err != nil {
log.Printf("ForumManager: failed to create NFL UDFA sync thread for season %d: %v", season, err)
return
}

log.Printf("ForumManager: created NFL UDFA sync thread %s for season %d", thread.ID, season)
}

func buildNFLUDFASyncParagraphs(season int, signings []string) []string {
var paragraphs []string

if len(signings) == 0 {
paragraphs = append(paragraphs,
fmt.Sprintf(
"The Undrafted Free Agency period has concluded for Season %d. No players were signed.",
season,
),
)
} else {
paragraphs = append(paragraphs,
fmt.Sprintf(
"The Undrafted Free Agency period has concluded for Season %d! The following players have signed with new teams:",
season,
),
)
for _, label := range signings {
paragraphs = append(paragraphs, label)
}
}

paragraphs = append(paragraphs, "Discuss the latest UDFA additions and how they fit into their new rosters below!")

return paragraphs
}
Loading
Loading