164 lines
3.4 KiB
Go
164 lines
3.4 KiB
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Group struct {
|
|
ID string
|
|
ServerID string // Discord server ID
|
|
ChannelGains string
|
|
ChannelLosses string
|
|
Internals bool // Show conquers in the same group
|
|
Barbarians bool // Show barbarian conquers
|
|
ServerKey string // Tribal Wars server key
|
|
VersionCode string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
type CreateGroupParams struct {
|
|
serverID string
|
|
serverKey string
|
|
versionCode string
|
|
channelGains string
|
|
channelLosses string
|
|
barbarians bool
|
|
internals bool
|
|
}
|
|
|
|
func NewCreateGroupParams(
|
|
serverID, versionCode, serverKey, channelGains, channelLosses string,
|
|
barbarians, internals bool,
|
|
) (CreateGroupParams, error) {
|
|
if serverID == "" {
|
|
return CreateGroupParams{}, ValidationError{
|
|
Field: "ServerID",
|
|
Err: ErrRequired,
|
|
}
|
|
}
|
|
|
|
if versionCode == "" {
|
|
return CreateGroupParams{}, ValidationError{
|
|
Field: "VersionCode",
|
|
Err: ErrRequired,
|
|
}
|
|
}
|
|
|
|
if serverKey == "" {
|
|
return CreateGroupParams{}, ValidationError{
|
|
Field: "ServerKey",
|
|
Err: ErrRequired,
|
|
}
|
|
}
|
|
|
|
return CreateGroupParams{
|
|
serverID: serverID,
|
|
serverKey: serverKey,
|
|
versionCode: versionCode,
|
|
channelGains: channelGains,
|
|
channelLosses: channelLosses,
|
|
barbarians: barbarians,
|
|
internals: internals,
|
|
}, nil
|
|
}
|
|
|
|
func (c CreateGroupParams) ServerID() string {
|
|
return c.serverID
|
|
}
|
|
|
|
func (c CreateGroupParams) VersionCode() string {
|
|
return c.versionCode
|
|
}
|
|
|
|
func (c CreateGroupParams) ServerKey() string {
|
|
return c.serverKey
|
|
}
|
|
|
|
func (c CreateGroupParams) ChannelGains() string {
|
|
return c.channelGains
|
|
}
|
|
|
|
func (c CreateGroupParams) ChannelLosses() string {
|
|
return c.channelLosses
|
|
}
|
|
|
|
func (c CreateGroupParams) Barbarians() bool {
|
|
return c.barbarians
|
|
}
|
|
|
|
func (c CreateGroupParams) Internals() bool {
|
|
return c.internals
|
|
}
|
|
|
|
type UpdateGroupParams struct {
|
|
ChannelGains NullString
|
|
ChannelLosses NullString
|
|
Internals NullBool
|
|
Barbarians NullBool
|
|
}
|
|
|
|
func (u UpdateGroupParams) IsZero() bool {
|
|
return !u.ChannelGains.Valid &&
|
|
!u.ChannelLosses.Valid &&
|
|
!u.Internals.Valid &&
|
|
!u.Barbarians.Valid
|
|
}
|
|
|
|
type ListGroupsParams struct {
|
|
ServerIDs []string // DC server IDs
|
|
VersionCode NullString
|
|
ServerKeys []string
|
|
EnabledNotifications NullBool // check if ChannelGains != null && ChannelLosses != null
|
|
CreatedAtLTE time.Time
|
|
}
|
|
|
|
type GroupLimitReachedError struct {
|
|
Current int // current number of groups
|
|
Limit int // maximum number of groups
|
|
}
|
|
|
|
func (e GroupLimitReachedError) Error() string {
|
|
return fmt.Sprintf("group limit has been reached (%d/%d)", e.Current, e.Limit)
|
|
}
|
|
|
|
func (e GroupLimitReachedError) UserError() string {
|
|
return e.Error()
|
|
}
|
|
|
|
func (e GroupLimitReachedError) Code() ErrorCode {
|
|
return ErrorCodeValidationError
|
|
}
|
|
|
|
type GroupNotFoundError struct {
|
|
ID string
|
|
}
|
|
|
|
func (e GroupNotFoundError) Error() string {
|
|
return fmt.Sprintf("group (ID=%s) not found", e.ID)
|
|
}
|
|
|
|
func (e GroupNotFoundError) UserError() string {
|
|
return e.Error()
|
|
}
|
|
|
|
func (e GroupNotFoundError) Code() ErrorCode {
|
|
return ErrorCodeEntityNotFound
|
|
}
|
|
|
|
type GroupDoesNotExistError struct {
|
|
ID string
|
|
}
|
|
|
|
func (e GroupDoesNotExistError) Error() string {
|
|
return fmt.Sprintf("group (ID=%s) doesn't exist", e.ID)
|
|
}
|
|
|
|
func (e GroupDoesNotExistError) UserError() string {
|
|
return e.Error()
|
|
}
|
|
|
|
func (e GroupDoesNotExistError) Code() ErrorCode {
|
|
return ErrorCodeValidationError
|
|
}
|