Skip to content
Merged
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
104 changes: 58 additions & 46 deletions chessfut-be/adapter/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type timeControlStatsModel struct {
Wins int `json:"wins"`
Losses int `json:"losses"`
Draws int `json:"draws"`
RD int `json:"rd"`
}

type attributesModel struct {
Expand All @@ -38,28 +39,32 @@ type workRateModel struct {
}

type cardDataModel struct {
Username string `json:"username"`
Name string `json:"name"`
Title string `json:"title"`
Avatar string `json:"avatar"`
Followers int `json:"followers"`
CountryCode string `json:"country_code"`
JoinedAt time.Time `json:"joined_at"`
FideRating int `json:"fide_rating"`
TacticsRating int `json:"tactics_rating"`
PuzzleRushAccuracy float64 `json:"puzzle_rush_accuracy"`
Bullet timeControlStatsModel `json:"bullet"`
Blitz timeControlStatsModel `json:"blitz"`
Rapid timeControlStatsModel `json:"rapid"`
Daily timeControlStatsModel `json:"daily"`
OVR int `json:"ovr"`
PlayStyle string `json:"play_style"`
Position string `json:"position"`
Attributes attributesModel `json:"attributes"`
WorkRate workRateModel `json:"work_rate"`
Badges []string `json:"badges"`
TopOpenings []openingStatModel `json:"top_openings"`
GamesSnapshot int `json:"games_snapshot"`
Username string `json:"username"`
Name string `json:"name"`
Title string `json:"title"`
Avatar string `json:"avatar"`
Followers int `json:"followers"`
CountryCode string `json:"country_code"`
JoinedAt time.Time `json:"joined_at"`
URL string `json:"url"`
LastOnline time.Time `json:"last_online"`
FideRating int `json:"fide_rating"`
EffectiveFideRating int `json:"effective_fide_rating"`
FideSource string `json:"fide_source"`
TacticsRating int `json:"tactics_rating"`
PuzzleRushAccuracy float64 `json:"puzzle_rush_accuracy"`
Bullet timeControlStatsModel `json:"bullet"`
Blitz timeControlStatsModel `json:"blitz"`
Rapid timeControlStatsModel `json:"rapid"`
Daily timeControlStatsModel `json:"daily"`
OVR int `json:"ovr"`
PlayStyle string `json:"play_style"`
Position string `json:"position"`
Attributes attributesModel `json:"attributes"`
WorkRate workRateModel `json:"work_rate"`
Badges []string `json:"badges"`
TopOpenings []openingStatModel `json:"top_openings"`
GamesSnapshot int `json:"games_snapshot"`
}

func toCardDataModel(c domain.Card) cardDataModel {
Expand All @@ -77,23 +82,27 @@ func toCardDataModel(c domain.Card) cardDataModel {
}

return cardDataModel{
Username: c.Player.Username,
Name: c.Player.Name,
Title: string(c.Player.Title),
Avatar: c.Player.Avatar,
Followers: c.Player.Followers,
CountryCode: c.Player.CountryCode,
JoinedAt: c.Player.JoinedAt,
FideRating: c.Stats.FideRating,
TacticsRating: c.Stats.TacticsRating,
PuzzleRushAccuracy: c.Stats.PuzzleRushAccuracy,
Bullet: toTimeControlModel(c.Stats.Bullet),
Blitz: toTimeControlModel(c.Stats.Blitz),
Rapid: toTimeControlModel(c.Stats.Rapid),
Daily: toTimeControlModel(c.Stats.Daily),
OVR: c.OVR,
PlayStyle: string(c.PlayStyle),
Position: string(c.Position),
Username: c.Player.Username,
Name: c.Player.Name,
Title: string(c.Player.Title),
Avatar: c.Player.Avatar,
Followers: c.Player.Followers,
CountryCode: c.Player.CountryCode,
JoinedAt: c.Player.JoinedAt,
URL: c.Player.URL,
LastOnline: c.Player.LastOnline,
FideRating: c.Stats.FideRating,
EffectiveFideRating: c.EffectiveFideRating,
FideSource: c.FideSource,
TacticsRating: c.Stats.TacticsRating,
PuzzleRushAccuracy: c.Stats.PuzzleRushAccuracy,
Bullet: toTimeControlModel(c.Stats.Bullet),
Blitz: toTimeControlModel(c.Stats.Blitz),
Rapid: toTimeControlModel(c.Stats.Rapid),
Daily: toTimeControlModel(c.Stats.Daily),
OVR: c.OVR,
PlayStyle: string(c.PlayStyle),
Position: string(c.Position),
Attributes: attributesModel{
Pac: c.Attributes.Pac,
Sho: c.Attributes.Sho,
Expand All @@ -113,7 +122,7 @@ func toCardDataModel(c domain.Card) cardDataModel {
}

func toTimeControlModel(s domain.TimeControlStats) timeControlStatsModel {
return timeControlStatsModel{Rating: s.Rating, Highest: s.Highest, Wins: s.Wins, Losses: s.Losses, Draws: s.Draws}
return timeControlStatsModel{Rating: s.Rating, Highest: s.Highest, Wins: s.Wins, Losses: s.Losses, Draws: s.Draws, RD: s.RD}
}

func fromCardDataModel(m cardDataModel, cardType, tier string, computedAt, expiresAt time.Time) domain.Card {
Expand All @@ -134,6 +143,7 @@ func fromCardDataModel(m cardDataModel, cardType, tier string, computedAt, expir
Player: domain.Player{
Username: m.Username, Name: m.Name, Title: domain.Title(m.Title),
Avatar: m.Avatar, Followers: m.Followers, CountryCode: m.CountryCode, JoinedAt: m.JoinedAt,
URL: m.URL, LastOnline: m.LastOnline,
},
Stats: domain.PlayerStats{
FideRating: m.FideRating,
Expand All @@ -144,11 +154,13 @@ func fromCardDataModel(m cardDataModel, cardType, tier string, computedAt, expir
Rapid: fromTimeControlModel(m.Rapid, domain.TimeControlRapid),
Daily: fromTimeControlModel(m.Daily, domain.TimeControlDaily),
},
CardType: domain.CardType(cardType),
Tier: domain.CardTier(tier),
OVR: m.OVR,
PlayStyle: domain.PlayStyle(m.PlayStyle),
Position: domain.Position(m.Position),
CardType: domain.CardType(cardType),
Tier: domain.CardTier(tier),
OVR: m.OVR,
PlayStyle: domain.PlayStyle(m.PlayStyle),
Position: domain.Position(m.Position),
EffectiveFideRating: m.EffectiveFideRating,
FideSource: m.FideSource,
Attributes: domain.Attributes{
Pac: m.Attributes.Pac,
Sho: m.Attributes.Sho,
Expand All @@ -170,5 +182,5 @@ func fromCardDataModel(m cardDataModel, cardType, tier string, computedAt, expir
}

func fromTimeControlModel(m timeControlStatsModel, tc domain.TimeControl) domain.TimeControlStats {
return domain.TimeControlStats{TimeControl: tc, Rating: m.Rating, Highest: m.Highest, Wins: m.Wins, Losses: m.Losses, Draws: m.Draws}
return domain.TimeControlStats{TimeControl: tc, Rating: m.Rating, Highest: m.Highest, Wins: m.Wins, Losses: m.Losses, Draws: m.Draws, RD: m.RD}
}
Loading