All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#181
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type TribeChange struct {
|
|
ID int64
|
|
PlayerID int64
|
|
NewTribeID int64
|
|
OldTribeID int64
|
|
ServerKey string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type TribeChangeWithRelations struct {
|
|
TribeChange
|
|
|
|
Player PlayerMeta
|
|
NewTribe NullTribeMeta
|
|
OldTribe NullTribeMeta
|
|
}
|
|
|
|
type CreateTribeChangeParams struct {
|
|
PlayerID int64
|
|
NewTribeID int64
|
|
OldTribeID int64
|
|
ServerKey string
|
|
}
|
|
|
|
type TribeChangeSortBy uint8
|
|
|
|
const (
|
|
TribeChangeSortByID TribeChangeSortBy = iota
|
|
TribeChangeSortByCreatedAt
|
|
)
|
|
|
|
func newTribeChangeSortBy(s string) (TribeChangeSortBy, error) {
|
|
switch s {
|
|
case "id":
|
|
return TribeChangeSortByID, nil
|
|
case "createdAt":
|
|
return TribeChangeSortByCreatedAt, nil
|
|
}
|
|
return 0, fmt.Errorf("%w: \"%s\"", ErrUnsupportedSortBy, s)
|
|
}
|
|
|
|
type TribeChangeSort struct {
|
|
By TribeChangeSortBy
|
|
Direction SortDirection
|
|
}
|
|
|
|
func NewTribeChangeSort(by, dir string) (TribeChangeSort, error) {
|
|
convBy, err := newTribeChangeSortBy(by)
|
|
if err != nil {
|
|
return TribeChangeSort{}, err
|
|
}
|
|
|
|
convDir, err := newSortDirection(dir)
|
|
if err != nil {
|
|
return TribeChangeSort{}, err
|
|
}
|
|
|
|
return TribeChangeSort{
|
|
By: convBy,
|
|
Direction: convDir,
|
|
}, nil
|
|
}
|
|
|
|
type ListTribeChangesParams struct {
|
|
ServerKeys []string
|
|
PlayerIDs []int64
|
|
// TribeIDs filters out tribe changes whose NewTribeID OR OldTribeID isn't in the provided slice.
|
|
TribeIDs []int64
|
|
Pagination Pagination
|
|
Sort []TribeChangeSort
|
|
}
|