Revert partial changes from 6193fe2, keeping changes to preview_middleware and teams_new
This commit is contained in:
@@ -2,7 +2,6 @@ package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
@@ -33,26 +32,15 @@ func SeasonPage(
|
||||
return false, errors.Wrap(err, "db.GetSeason")
|
||||
}
|
||||
|
||||
if season.Type != db.SeasonTypeDraft.String() {
|
||||
leaguesWithTeams, err = season.MapTeamsToLeagues(ctx, tx)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "season.MapTeamsToLeagues")
|
||||
}
|
||||
leaguesWithTeams, err = season.MapTeamsToLeagues(ctx, tx)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "season.MapTeamsToLeagues")
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}); !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if season.Type == db.SeasonTypeDraft.String() {
|
||||
// Redirect draft seasons to their default tab
|
||||
defaultTab := season.GetDefaultTab()
|
||||
redirectURL := fmt.Sprintf("/seasons/%s/%s", seasonStr, defaultTab)
|
||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
renderSafely(seasonsview.DetailPage(season, leaguesWithTeams), s, r, w)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -50,11 +50,7 @@ func SeasonLeagueAddTeam(
|
||||
}
|
||||
|
||||
// Redirect to refresh the page
|
||||
redirectURL := fmt.Sprintf("/seasons/%s/leagues/%s/teams", season.ShortName, league.ShortName)
|
||||
if season.Type == db.SeasonTypeDraft.String() {
|
||||
redirectURL = fmt.Sprintf("/seasons/%s/teams", season.ShortName)
|
||||
}
|
||||
w.Header().Set("HX-Redirect", redirectURL)
|
||||
w.Header().Set("HX-Redirect", fmt.Sprintf("/seasons/%s/leagues/%s/teams", season.ShortName, league.ShortName))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
notify.Success(s, w, r, "Team Added", fmt.Sprintf(
|
||||
"Successfully added '%s' to the league.",
|
||||
|
||||
@@ -39,14 +39,6 @@ func SeasonLeaguePage(
|
||||
}
|
||||
|
||||
defaultTab := season.GetDefaultTab()
|
||||
|
||||
// Draft seasons redirect to /seasons/{short}/{tab} instead
|
||||
if season.Type == db.SeasonTypeDraft.String() {
|
||||
redirectURL := fmt.Sprintf("/seasons/%s/%s", seasonStr, defaultTab)
|
||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
redirectURL := fmt.Sprintf(
|
||||
"/seasons/%s/leagues/%s/%s",
|
||||
seasonStr, leagueStr, defaultTab,
|
||||
|
||||
@@ -39,9 +39,6 @@ func SeasonLeagueFinalsPage(
|
||||
return
|
||||
}
|
||||
|
||||
if redirectDraftSeasonLeague(season, "finals", w, r) {
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" {
|
||||
renderSafely(seasonsview.SeasonLeagueFinalsPage(season, league), s, r, w)
|
||||
} else {
|
||||
|
||||
@@ -41,9 +41,6 @@ func SeasonLeagueFixturesPage(
|
||||
return
|
||||
}
|
||||
|
||||
if redirectDraftSeasonLeague(season, "fixtures", w, r) {
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" {
|
||||
renderSafely(seasonsview.SeasonLeagueFixturesPage(season, league, fixtures), s, r, w)
|
||||
} else {
|
||||
|
||||
@@ -39,9 +39,6 @@ func SeasonLeagueStatsPage(
|
||||
return
|
||||
}
|
||||
|
||||
if redirectDraftSeasonLeague(season, "stats", w, r) {
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" {
|
||||
renderSafely(seasonsview.SeasonLeagueStatsPage(season, league), s, r, w)
|
||||
} else {
|
||||
|
||||
@@ -38,9 +38,6 @@ func SeasonLeagueTablePage(
|
||||
}); !ok {
|
||||
return
|
||||
}
|
||||
if redirectDraftSeasonLeague(season, "table", w, r) {
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" {
|
||||
renderSafely(seasonsview.SeasonLeagueTablePage(season, league), s, r, w)
|
||||
} else {
|
||||
|
||||
@@ -50,9 +50,6 @@ func SeasonLeagueTeamsPage(
|
||||
return
|
||||
}
|
||||
|
||||
if redirectDraftSeasonLeague(season, "teams", w, r) {
|
||||
return
|
||||
}
|
||||
if r.Method == "GET" {
|
||||
renderSafely(seasonsview.SeasonLeagueTeamsPage(season, league, teams, available), s, r, w)
|
||||
} else {
|
||||
|
||||
@@ -25,21 +25,7 @@ func SeasonAddLeague(
|
||||
var season *db.Season
|
||||
var allLeagues []*db.League
|
||||
if ok := conn.WithNotifyTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
// Check if season is a draft season
|
||||
seasonCheck, err := db.GetSeason(ctx, tx, seasonShortName)
|
||||
if err != nil {
|
||||
if db.IsBadRequest(err) {
|
||||
respond.NotFound(w, err)
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, "db.GetSeason")
|
||||
}
|
||||
if seasonCheck.Type == db.SeasonTypeDraft.String() {
|
||||
respond.BadRequest(w, errors.New("cannot manually manage leagues for draft seasons"))
|
||||
return false, nil
|
||||
}
|
||||
|
||||
err = db.NewSeasonLeague(ctx, tx, seasonShortName, leagueShortName, db.NewAuditFromRequest(r))
|
||||
err := db.NewSeasonLeague(ctx, tx, seasonShortName, leagueShortName, db.NewAuditFromRequest(r))
|
||||
if err != nil {
|
||||
if db.IsBadRequest(err) {
|
||||
respond.BadRequest(w, err)
|
||||
@@ -89,10 +75,6 @@ func SeasonRemoveLeague(
|
||||
}
|
||||
return false, errors.Wrap(err, "db.GetSeason")
|
||||
}
|
||||
if season.Type == db.SeasonTypeDraft.String() {
|
||||
respond.BadRequest(w, errors.New("cannot manually manage leagues for draft seasons"))
|
||||
return false, nil
|
||||
}
|
||||
err = season.RemoveLeague(ctx, tx, leagueStr, db.NewAuditFromRequest(r))
|
||||
if err != nil {
|
||||
if db.IsBadRequest(err) {
|
||||
|
||||
Reference in New Issue
Block a user