Add player profiles and community settings
Some checks failed
CI / backend (push) Has been cancelled
CI / frontend (push) Has been cancelled
CI / compose (push) Has been cancelled

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-19 21:43:48 +03:00
parent 5e0825f43f
commit fa4edc0df5
23 changed files with 1280 additions and 57 deletions

View File

@@ -4,9 +4,11 @@ import (
"errors"
"fmt"
"math/rand"
"regexp"
"slices"
"strings"
"time"
"unicode/utf8"
)
var (
@@ -63,6 +65,7 @@ type Player struct {
ID string `json:"id"`
AccountID string `json:"accountId"`
DisplayName string `json:"displayName"`
BattleTag string `json:"battleTag"`
Ratings Ratings `json:"ratings"`
PreferredRoles []Role `json:"preferredRoles"`
PreferredPlayerIDs []string `json:"preferredPlayerIds"`
@@ -71,6 +74,21 @@ type Player struct {
UpdatedAt time.Time `json:"updatedAt"`
}
var battleTagPattern = regexp.MustCompile(`^[^#\s]{2,20}#[0-9]{3,12}$`)
func (p *Player) ValidateIdentity() error {
p.DisplayName = strings.TrimSpace(p.DisplayName)
length := utf8.RuneCountInString(p.DisplayName)
if length < 2 || length > 32 {
return fmt.Errorf("%w: display name must contain 2 to 32 characters", ErrInvalid)
}
p.BattleTag = strings.TrimSpace(p.BattleTag)
if p.BattleTag != "" && !battleTagPattern.MatchString(p.BattleTag) {
return fmt.Errorf("%w: BattleTag must have the form Name#digits", ErrInvalid)
}
return nil
}
func (p Player) ValidatePreferences() error {
if len(p.PreferredPlayerIDs) > 3 {
return fmt.Errorf("%w: at most three preferred teammates are allowed", ErrInvalid)