This repository has been archived on 2024-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
core-old/internal/domain/tribe_change.go
Dawid Wysokiński bf29ab4799
All checks were successful
continuous-integration/drone/push Build is passing
feat: new rest endpoint - /versions/{code}/servers/{key}/tribes/{id}/tribe-changes (#181)
Reviewed-on: twhelp/core#181
2023-02-10 05:56:39 +00:00

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
}