Dawid Wysokiński
75aba22cf8
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#149
127 lines
2.3 KiB
Go
127 lines
2.3 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Tribe struct {
|
|
OpponentsDefeated
|
|
|
|
ID int64
|
|
Name string
|
|
Tag string
|
|
NumMembers int64
|
|
NumVillages int64
|
|
Points int64 // points of top x players
|
|
AllPoints int64
|
|
Rank int64
|
|
Dominance float64
|
|
ProfileURL string
|
|
BestRank int64
|
|
BestRankAt time.Time
|
|
MostPoints int64
|
|
MostPointsAt time.Time
|
|
MostVillages int64
|
|
MostVillagesAt time.Time
|
|
ServerKey string
|
|
CreatedAt time.Time
|
|
DeletedAt time.Time
|
|
}
|
|
|
|
type TribeMeta struct {
|
|
ID int64
|
|
Name string
|
|
Tag string
|
|
ProfileURL string
|
|
}
|
|
|
|
type NullTribeMeta struct {
|
|
Valid bool
|
|
Tribe TribeMeta
|
|
}
|
|
|
|
type CreateTribeParams struct {
|
|
OpponentsDefeated
|
|
|
|
ID int64
|
|
Name string
|
|
Tag string
|
|
NumMembers int64
|
|
NumVillages int64
|
|
Points int64
|
|
AllPoints int64
|
|
Rank int64
|
|
ProfileURL string
|
|
BestRank int64
|
|
BestRankAt time.Time
|
|
MostPoints int64
|
|
MostPointsAt time.Time
|
|
MostVillages int64
|
|
MostVillagesAt time.Time
|
|
ServerKey string
|
|
}
|
|
|
|
type TribeSortBy uint8
|
|
|
|
const (
|
|
TribeSortByID TribeSortBy = iota
|
|
TribeSortByScoreAtt
|
|
TribeSortByScoreDef
|
|
TribeSortByScoreTotal
|
|
TribeSortByPoints
|
|
TribeSortByDominance
|
|
TribeSortByDeletedAt
|
|
)
|
|
|
|
func NewTribeSortBy(s string) (TribeSortBy, error) {
|
|
switch s {
|
|
case "id":
|
|
return TribeSortByID, nil
|
|
case "scoreAtt":
|
|
return TribeSortByScoreAtt, nil
|
|
case "scoreDef":
|
|
return TribeSortByScoreDef, nil
|
|
case "scoreTotal":
|
|
return TribeSortByScoreTotal, nil
|
|
case "points":
|
|
return TribeSortByPoints, nil
|
|
case "dominance":
|
|
return TribeSortByDominance, nil
|
|
case "deletedAt":
|
|
return TribeSortByDeletedAt, nil
|
|
}
|
|
return 0, fmt.Errorf("%w: \"%s\"", ErrUnsupportedSortBy, s)
|
|
}
|
|
|
|
type TribeSort struct {
|
|
By TribeSortBy
|
|
Direction SortDirection
|
|
}
|
|
|
|
type ListTribesParams struct {
|
|
IDs []int64
|
|
IDGT NullInt64
|
|
Tags []string
|
|
ServerKeys []string
|
|
Deleted NullBool
|
|
Pagination Pagination
|
|
Sort []TribeSort
|
|
}
|
|
|
|
type TribeNotFoundError struct {
|
|
ID int64
|
|
}
|
|
|
|
func (e TribeNotFoundError) Error() string {
|
|
return fmt.Sprintf("tribe (id=%d) not found", e.ID)
|
|
}
|
|
|
|
func (e TribeNotFoundError) UserError() string {
|
|
return e.Error()
|
|
}
|
|
|
|
func (e TribeNotFoundError) Code() ErrorCode {
|
|
return ErrorCodeEntityNotFound
|
|
}
|