fixed match win/loss/ties

This commit is contained in:
2021-10-08 17:15:06 +02:00
parent 1fda101a35
commit 1816c5a2b5
28 changed files with 363 additions and 654 deletions

View File

@@ -34,9 +34,7 @@ type MatchMutation struct {
config
op Op
typ string
id *int
match_id *uint64
addmatch_id *uint64
id *uint64
share_code *string
_map *string
date *time.Time
@@ -64,8 +62,8 @@ type MatchMutation struct {
stats map[int]struct{}
removedstats map[int]struct{}
clearedstats bool
players map[int]struct{}
removedplayers map[int]struct{}
players map[uint64]struct{}
removedplayers map[uint64]struct{}
clearedplayers bool
done bool
oldValue func(context.Context) (*Match, error)
@@ -92,7 +90,7 @@ func newMatchMutation(c config, op Op, opts ...matchOption) *MatchMutation {
}
// withMatchID sets the ID field of the mutation.
func withMatchID(id int) matchOption {
func withMatchID(id uint64) matchOption {
return func(m *MatchMutation) {
var (
err error
@@ -142,71 +140,21 @@ func (m MatchMutation) Tx() (*Tx, error) {
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Match entities.
func (m *MatchMutation) SetID(id uint64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *MatchMutation) ID() (id int, exists bool) {
func (m *MatchMutation) ID() (id uint64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// SetMatchID sets the "match_id" field.
func (m *MatchMutation) SetMatchID(u uint64) {
m.match_id = &u
m.addmatch_id = nil
}
// MatchID returns the value of the "match_id" field in the mutation.
func (m *MatchMutation) MatchID() (r uint64, exists bool) {
v := m.match_id
if v == nil {
return
}
return *v, true
}
// OldMatchID returns the old "match_id" field's value of the Match entity.
// If the Match object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MatchMutation) OldMatchID(ctx context.Context) (v uint64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldMatchID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldMatchID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMatchID: %w", err)
}
return oldValue.MatchID, nil
}
// AddMatchID adds u to the "match_id" field.
func (m *MatchMutation) AddMatchID(u uint64) {
if m.addmatch_id != nil {
*m.addmatch_id += u
} else {
m.addmatch_id = &u
}
}
// AddedMatchID returns the value that was added to the "match_id" field in this mutation.
func (m *MatchMutation) AddedMatchID() (r uint64, exists bool) {
v := m.addmatch_id
if v == nil {
return
}
return *v, true
}
// ResetMatchID resets all changes to the "match_id" field.
func (m *MatchMutation) ResetMatchID() {
m.match_id = nil
m.addmatch_id = nil
}
// SetShareCode sets the "share_code" field.
func (m *MatchMutation) SetShareCode(s string) {
m.share_code = &s
@@ -851,9 +799,9 @@ func (m *MatchMutation) ResetStats() {
}
// AddPlayerIDs adds the "players" edge to the Player entity by ids.
func (m *MatchMutation) AddPlayerIDs(ids ...int) {
func (m *MatchMutation) AddPlayerIDs(ids ...uint64) {
if m.players == nil {
m.players = make(map[int]struct{})
m.players = make(map[uint64]struct{})
}
for i := range ids {
m.players[ids[i]] = struct{}{}
@@ -871,9 +819,9 @@ func (m *MatchMutation) PlayersCleared() bool {
}
// RemovePlayerIDs removes the "players" edge to the Player entity by IDs.
func (m *MatchMutation) RemovePlayerIDs(ids ...int) {
func (m *MatchMutation) RemovePlayerIDs(ids ...uint64) {
if m.removedplayers == nil {
m.removedplayers = make(map[int]struct{})
m.removedplayers = make(map[uint64]struct{})
}
for i := range ids {
delete(m.players, ids[i])
@@ -882,7 +830,7 @@ func (m *MatchMutation) RemovePlayerIDs(ids ...int) {
}
// RemovedPlayers returns the removed IDs of the "players" edge to the Player entity.
func (m *MatchMutation) RemovedPlayersIDs() (ids []int) {
func (m *MatchMutation) RemovedPlayersIDs() (ids []uint64) {
for id := range m.removedplayers {
ids = append(ids, id)
}
@@ -890,7 +838,7 @@ func (m *MatchMutation) RemovedPlayersIDs() (ids []int) {
}
// PlayersIDs returns the "players" edge IDs in the mutation.
func (m *MatchMutation) PlayersIDs() (ids []int) {
func (m *MatchMutation) PlayersIDs() (ids []uint64) {
for id := range m.players {
ids = append(ids, id)
}
@@ -923,10 +871,7 @@ func (m *MatchMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *MatchMutation) Fields() []string {
fields := make([]string, 0, 13)
if m.match_id != nil {
fields = append(fields, match.FieldMatchID)
}
fields := make([]string, 0, 12)
if m.share_code != nil {
fields = append(fields, match.FieldShareCode)
}
@@ -971,8 +916,6 @@ func (m *MatchMutation) Fields() []string {
// schema.
func (m *MatchMutation) Field(name string) (ent.Value, bool) {
switch name {
case match.FieldMatchID:
return m.MatchID()
case match.FieldShareCode:
return m.ShareCode()
case match.FieldMap:
@@ -1006,8 +949,6 @@ func (m *MatchMutation) Field(name string) (ent.Value, bool) {
// database failed.
func (m *MatchMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case match.FieldMatchID:
return m.OldMatchID(ctx)
case match.FieldShareCode:
return m.OldShareCode(ctx)
case match.FieldMap:
@@ -1041,13 +982,6 @@ func (m *MatchMutation) OldField(ctx context.Context, name string) (ent.Value, e
// type.
func (m *MatchMutation) SetField(name string, value ent.Value) error {
switch name {
case match.FieldMatchID:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMatchID(v)
return nil
case match.FieldShareCode:
v, ok := value.(string)
if !ok {
@@ -1146,9 +1080,6 @@ func (m *MatchMutation) SetField(name string, value ent.Value) error {
// this mutation.
func (m *MatchMutation) AddedFields() []string {
var fields []string
if m.addmatch_id != nil {
fields = append(fields, match.FieldMatchID)
}
if m.addscore_team_a != nil {
fields = append(fields, match.FieldScoreTeamA)
}
@@ -1172,8 +1103,6 @@ func (m *MatchMutation) AddedFields() []string {
// was not set, or was not defined in the schema.
func (m *MatchMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case match.FieldMatchID:
return m.AddedMatchID()
case match.FieldScoreTeamA:
return m.AddedScoreTeamA()
case match.FieldScoreTeamB:
@@ -1193,13 +1122,6 @@ func (m *MatchMutation) AddedField(name string) (ent.Value, bool) {
// type.
func (m *MatchMutation) AddField(name string, value ent.Value) error {
switch name {
case match.FieldMatchID:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMatchID(v)
return nil
case match.FieldScoreTeamA:
v, ok := value.(int)
if !ok {
@@ -1283,9 +1205,6 @@ func (m *MatchMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema.
func (m *MatchMutation) ResetField(name string) error {
switch name {
case match.FieldMatchID:
m.ResetMatchID()
return nil
case match.FieldShareCode:
m.ResetShareCode()
return nil
@@ -1441,9 +1360,7 @@ type PlayerMutation struct {
config
op Op
typ string
id *int
steamid *uint64
addsteamid *uint64
id *uint64
name *string
avatar_url *string
vanity_url *string
@@ -1459,8 +1376,8 @@ type PlayerMutation struct {
stats map[int]struct{}
removedstats map[int]struct{}
clearedstats bool
matches map[int]struct{}
removedmatches map[int]struct{}
matches map[uint64]struct{}
removedmatches map[uint64]struct{}
clearedmatches bool
done bool
oldValue func(context.Context) (*Player, error)
@@ -1487,7 +1404,7 @@ func newPlayerMutation(c config, op Op, opts ...playerOption) *PlayerMutation {
}
// withPlayerID sets the ID field of the mutation.
func withPlayerID(id int) playerOption {
func withPlayerID(id uint64) playerOption {
return func(m *PlayerMutation) {
var (
err error
@@ -1537,71 +1454,21 @@ func (m PlayerMutation) Tx() (*Tx, error) {
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Player entities.
func (m *PlayerMutation) SetID(id uint64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PlayerMutation) ID() (id int, exists bool) {
func (m *PlayerMutation) ID() (id uint64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// SetSteamid sets the "steamid" field.
func (m *PlayerMutation) SetSteamid(u uint64) {
m.steamid = &u
m.addsteamid = nil
}
// Steamid returns the value of the "steamid" field in the mutation.
func (m *PlayerMutation) Steamid() (r uint64, exists bool) {
v := m.steamid
if v == nil {
return
}
return *v, true
}
// OldSteamid returns the old "steamid" field's value of the Player entity.
// If the Player object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *PlayerMutation) OldSteamid(ctx context.Context) (v uint64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, fmt.Errorf("OldSteamid is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, fmt.Errorf("OldSteamid requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSteamid: %w", err)
}
return oldValue.Steamid, nil
}
// AddSteamid adds u to the "steamid" field.
func (m *PlayerMutation) AddSteamid(u uint64) {
if m.addsteamid != nil {
*m.addsteamid += u
} else {
m.addsteamid = &u
}
}
// AddedSteamid returns the value that was added to the "steamid" field in this mutation.
func (m *PlayerMutation) AddedSteamid() (r uint64, exists bool) {
v := m.addsteamid
if v == nil {
return
}
return *v, true
}
// ResetSteamid resets all changes to the "steamid" field.
func (m *PlayerMutation) ResetSteamid() {
m.steamid = nil
m.addsteamid = nil
}
// SetName sets the "name" field.
func (m *PlayerMutation) SetName(s string) {
m.name = &s
@@ -2142,9 +2009,9 @@ func (m *PlayerMutation) ResetStats() {
}
// AddMatchIDs adds the "matches" edge to the Match entity by ids.
func (m *PlayerMutation) AddMatchIDs(ids ...int) {
func (m *PlayerMutation) AddMatchIDs(ids ...uint64) {
if m.matches == nil {
m.matches = make(map[int]struct{})
m.matches = make(map[uint64]struct{})
}
for i := range ids {
m.matches[ids[i]] = struct{}{}
@@ -2162,9 +2029,9 @@ func (m *PlayerMutation) MatchesCleared() bool {
}
// RemoveMatchIDs removes the "matches" edge to the Match entity by IDs.
func (m *PlayerMutation) RemoveMatchIDs(ids ...int) {
func (m *PlayerMutation) RemoveMatchIDs(ids ...uint64) {
if m.removedmatches == nil {
m.removedmatches = make(map[int]struct{})
m.removedmatches = make(map[uint64]struct{})
}
for i := range ids {
delete(m.matches, ids[i])
@@ -2173,7 +2040,7 @@ func (m *PlayerMutation) RemoveMatchIDs(ids ...int) {
}
// RemovedMatches returns the removed IDs of the "matches" edge to the Match entity.
func (m *PlayerMutation) RemovedMatchesIDs() (ids []int) {
func (m *PlayerMutation) RemovedMatchesIDs() (ids []uint64) {
for id := range m.removedmatches {
ids = append(ids, id)
}
@@ -2181,7 +2048,7 @@ func (m *PlayerMutation) RemovedMatchesIDs() (ids []int) {
}
// MatchesIDs returns the "matches" edge IDs in the mutation.
func (m *PlayerMutation) MatchesIDs() (ids []int) {
func (m *PlayerMutation) MatchesIDs() (ids []uint64) {
for id := range m.matches {
ids = append(ids, id)
}
@@ -2214,10 +2081,7 @@ func (m *PlayerMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PlayerMutation) Fields() []string {
fields := make([]string, 0, 11)
if m.steamid != nil {
fields = append(fields, player.FieldSteamid)
}
fields := make([]string, 0, 10)
if m.name != nil {
fields = append(fields, player.FieldName)
}
@@ -2256,8 +2120,6 @@ func (m *PlayerMutation) Fields() []string {
// schema.
func (m *PlayerMutation) Field(name string) (ent.Value, bool) {
switch name {
case player.FieldSteamid:
return m.Steamid()
case player.FieldName:
return m.Name()
case player.FieldAvatarURL:
@@ -2287,8 +2149,6 @@ func (m *PlayerMutation) Field(name string) (ent.Value, bool) {
// database failed.
func (m *PlayerMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case player.FieldSteamid:
return m.OldSteamid(ctx)
case player.FieldName:
return m.OldName(ctx)
case player.FieldAvatarURL:
@@ -2318,13 +2178,6 @@ func (m *PlayerMutation) OldField(ctx context.Context, name string) (ent.Value,
// type.
func (m *PlayerMutation) SetField(name string, value ent.Value) error {
switch name {
case player.FieldSteamid:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSteamid(v)
return nil
case player.FieldName:
v, ok := value.(string)
if !ok {
@@ -2403,9 +2256,6 @@ func (m *PlayerMutation) SetField(name string, value ent.Value) error {
// this mutation.
func (m *PlayerMutation) AddedFields() []string {
var fields []string
if m.addsteamid != nil {
fields = append(fields, player.FieldSteamid)
}
if m.addvac_count != nil {
fields = append(fields, player.FieldVacCount)
}
@@ -2417,8 +2267,6 @@ func (m *PlayerMutation) AddedFields() []string {
// was not set, or was not defined in the schema.
func (m *PlayerMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case player.FieldSteamid:
return m.AddedSteamid()
case player.FieldVacCount:
return m.AddedVacCount()
}
@@ -2430,13 +2278,6 @@ func (m *PlayerMutation) AddedField(name string) (ent.Value, bool) {
// type.
func (m *PlayerMutation) AddField(name string, value ent.Value) error {
switch name {
case player.FieldSteamid:
v, ok := value.(uint64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddSteamid(v)
return nil
case player.FieldVacCount:
v, ok := value.(int)
if !ok {
@@ -2522,9 +2363,6 @@ func (m *PlayerMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema.
func (m *PlayerMutation) ResetField(name string) error {
switch name {
case player.FieldSteamid:
m.ResetSteamid()
return nil
case player.FieldName:
m.ResetName()
return nil
@@ -2738,9 +2576,9 @@ type StatsMutation struct {
} "json:\"flash,omitempty\""
}
clearedFields map[string]struct{}
matches *int
matches *uint64
clearedmatches bool
players *int
players *uint64
clearedplayers bool
done bool
oldValue func(context.Context) (*Stats, error)
@@ -3409,7 +3247,7 @@ func (m *StatsMutation) ResetExtended() {
}
// SetMatchesID sets the "matches" edge to the Match entity by id.
func (m *StatsMutation) SetMatchesID(id int) {
func (m *StatsMutation) SetMatchesID(id uint64) {
m.matches = &id
}
@@ -3424,7 +3262,7 @@ func (m *StatsMutation) MatchesCleared() bool {
}
// MatchesID returns the "matches" edge ID in the mutation.
func (m *StatsMutation) MatchesID() (id int, exists bool) {
func (m *StatsMutation) MatchesID() (id uint64, exists bool) {
if m.matches != nil {
return *m.matches, true
}
@@ -3434,7 +3272,7 @@ func (m *StatsMutation) MatchesID() (id int, exists bool) {
// MatchesIDs returns the "matches" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// MatchesID instead. It exists only for internal usage by the builders.
func (m *StatsMutation) MatchesIDs() (ids []int) {
func (m *StatsMutation) MatchesIDs() (ids []uint64) {
if id := m.matches; id != nil {
ids = append(ids, *id)
}
@@ -3448,7 +3286,7 @@ func (m *StatsMutation) ResetMatches() {
}
// SetPlayersID sets the "players" edge to the Player entity by id.
func (m *StatsMutation) SetPlayersID(id int) {
func (m *StatsMutation) SetPlayersID(id uint64) {
m.players = &id
}
@@ -3463,7 +3301,7 @@ func (m *StatsMutation) PlayersCleared() bool {
}
// PlayersID returns the "players" edge ID in the mutation.
func (m *StatsMutation) PlayersID() (id int, exists bool) {
func (m *StatsMutation) PlayersID() (id uint64, exists bool) {
if m.players != nil {
return *m.players, true
}
@@ -3473,7 +3311,7 @@ func (m *StatsMutation) PlayersID() (id int, exists bool) {
// PlayersIDs returns the "players" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// PlayersID instead. It exists only for internal usage by the builders.
func (m *StatsMutation) PlayersIDs() (ids []int) {
func (m *StatsMutation) PlayersIDs() (ids []uint64) {
if id := m.players; id != nil {
ids = append(ids, *id)
}