im actually goated
This commit is contained in:
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -69,6 +70,7 @@ func UpdateFixtures(
|
||||
leagueShortName := getter.String("league_short_name").TrimSpace().Required().Value
|
||||
allocations := getter.GetMaps("allocations")
|
||||
if !getter.ValidateAndNotify(s, w, r) {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
updates, err := mapUpdates(allocations)
|
||||
@@ -91,6 +93,7 @@ func UpdateFixtures(
|
||||
}
|
||||
var valid bool
|
||||
fixtures, valid = updateFixtures(fixtures, updates)
|
||||
fmt.Println(len(fixtures))
|
||||
if !valid {
|
||||
notify.Warn(s, w, r, "Invalid game weeks", "A game week is missing or has no games", nil)
|
||||
return false, nil
|
||||
@@ -158,10 +161,27 @@ func updateFixtures(fixtures []*db.Fixture, updates map[int]int) ([]*db.Fixture,
|
||||
gameWeeks := map[int]int{}
|
||||
for _, fixture := range fixtures {
|
||||
if gameWeek, exists := updates[fixture.ID]; exists {
|
||||
fixture.GameWeek = &gameWeek
|
||||
updated = append(updated, fixture)
|
||||
var newValue *int
|
||||
var oldValue int
|
||||
if fixture.GameWeek != nil {
|
||||
oldValue = *fixture.GameWeek
|
||||
} else {
|
||||
oldValue = 0
|
||||
}
|
||||
if gameWeek == 0 {
|
||||
newValue = nil
|
||||
} else {
|
||||
newValue = &gameWeek
|
||||
}
|
||||
if gameWeek != oldValue {
|
||||
fixture.GameWeek = newValue
|
||||
updated = append(updated, fixture)
|
||||
}
|
||||
// fuck i hate pointers sometimes
|
||||
}
|
||||
if fixture.GameWeek != nil {
|
||||
gameWeeks[*fixture.GameWeek]++
|
||||
}
|
||||
gameWeeks[*fixture.GameWeek]++
|
||||
}
|
||||
for i := range len(gameWeeks) {
|
||||
count, exists := gameWeeks[i+1]
|
||||
|
||||
Reference in New Issue
Block a user