Dawid Wysokiński
c6be9a6012
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#180
167 lines
3.0 KiB
Go
167 lines
3.0 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type PlayerSnapshot struct {
|
|
OpponentsDefeated
|
|
|
|
ID int64
|
|
PlayerID int64
|
|
ServerKey string
|
|
NumVillages int64
|
|
Points int64
|
|
Rank int64
|
|
TribeID int64
|
|
Date time.Time
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type PlayerSnapshotWithRelations struct {
|
|
PlayerSnapshot
|
|
|
|
Tribe NullTribeMeta
|
|
}
|
|
|
|
type CreatePlayerSnapshotParams struct {
|
|
OpponentsDefeated
|
|
|
|
PlayerID int64
|
|
NumVillages int64
|
|
Points int64
|
|
Rank int64
|
|
TribeID int64
|
|
ServerKey string
|
|
Date time.Time
|
|
}
|
|
|
|
type PlayerSnapshotSortBy uint8
|
|
|
|
const (
|
|
PlayerSnapshotSortByID PlayerSnapshotSortBy = iota
|
|
PlayerSnapshotSortByDate
|
|
)
|
|
|
|
func newPlayerSnapshotSortBy(s string) (PlayerSnapshotSortBy, error) {
|
|
switch s {
|
|
case "id":
|
|
return PlayerSnapshotSortByID, nil
|
|
case "date":
|
|
return PlayerSnapshotSortByDate, nil
|
|
}
|
|
return 0, fmt.Errorf("%w: \"%s\"", ErrUnsupportedSortBy, s)
|
|
}
|
|
|
|
type PlayerSnapshotSort struct {
|
|
By PlayerSnapshotSortBy
|
|
Direction SortDirection
|
|
}
|
|
|
|
func NewPlayerSnapshotSort(by, dir string) (PlayerSnapshotSort, error) {
|
|
convBy, err := newPlayerSnapshotSortBy(by)
|
|
if err != nil {
|
|
return PlayerSnapshotSort{}, err
|
|
}
|
|
|
|
convDir, err := newSortDirection(dir)
|
|
if err != nil {
|
|
return PlayerSnapshotSort{}, err
|
|
}
|
|
|
|
return PlayerSnapshotSort{
|
|
By: convBy,
|
|
Direction: convDir,
|
|
}, nil
|
|
}
|
|
|
|
type ListPlayerSnapshotsParams struct {
|
|
ServerKeys []string
|
|
PlayerIDs []int64
|
|
Pagination Pagination
|
|
Sort []PlayerSnapshotSort
|
|
}
|
|
|
|
type TribeSnapshot struct {
|
|
OpponentsDefeated
|
|
|
|
ID int64
|
|
TribeID int64
|
|
ServerKey string
|
|
NumMembers int64
|
|
NumVillages int64
|
|
Points int64
|
|
AllPoints int64
|
|
Rank int64
|
|
Dominance float64
|
|
Date time.Time
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type CreateTribeSnapshotParams struct {
|
|
OpponentsDefeated
|
|
|
|
TribeID int64
|
|
ServerKey string
|
|
NumMembers int64
|
|
NumVillages int64
|
|
Points int64
|
|
AllPoints int64
|
|
Rank int64
|
|
Dominance float64
|
|
Date time.Time
|
|
}
|
|
|
|
type TribeSnapshotSortBy uint8
|
|
|
|
const (
|
|
TribeSnapshotSortByID TribeSnapshotSortBy = iota
|
|
TribeSnapshotSortByDate
|
|
)
|
|
|
|
func newTribeSnapshotSortBy(s string) (TribeSnapshotSortBy, error) {
|
|
switch s {
|
|
case "id":
|
|
return TribeSnapshotSortByID, nil
|
|
case "date":
|
|
return TribeSnapshotSortByDate, nil
|
|
}
|
|
return 0, fmt.Errorf("%w: \"%s\"", ErrUnsupportedSortBy, s)
|
|
}
|
|
|
|
type TribeSnapshotSort struct {
|
|
By TribeSnapshotSortBy
|
|
Direction SortDirection
|
|
}
|
|
|
|
func NewTribeSnapshotSort(by, dir string) (TribeSnapshotSort, error) {
|
|
convBy, err := newTribeSnapshotSortBy(by)
|
|
if err != nil {
|
|
return TribeSnapshotSort{}, err
|
|
}
|
|
|
|
convDir, err := newSortDirection(dir)
|
|
if err != nil {
|
|
return TribeSnapshotSort{}, err
|
|
}
|
|
|
|
return TribeSnapshotSort{
|
|
By: convBy,
|
|
Direction: convDir,
|
|
}, nil
|
|
}
|
|
|
|
type ListTribeSnapshotsParams struct {
|
|
ServerKeys []string
|
|
TribeIDs []int64
|
|
Pagination Pagination
|
|
Sort []TribeSnapshotSort
|
|
}
|
|
|
|
type CreateSnapshotsCmdPayload struct {
|
|
Key string
|
|
VersionCode string
|
|
Date time.Time
|
|
}
|