dcbot/internal/domain/group.go
Dawid Wysokiński 0436c56813
All checks were successful
continuous-integration/drone/push Build is passing
feat: add a new command - group set-server (#12)
Reviewed-on: #12
2022-10-10 05:16:40 +00:00

124 lines
2.6 KiB
Go

package domain
import (
"fmt"
"time"
)
type Group struct {
ID string
ServerID string // Discord server ID
ChannelGainedVillages string
ChannelLostVillages string
ServerKey string // Tribal Wars server key
VersionCode string
CreatedAt time.Time
}
type CreateGroupParams struct {
serverID string
serverKey string
versionCode string
channelGainedVillages string
channelLostVillages string
}
func NewCreateGroupParams(serverID, versionCode, serverKey, channelGainedVillages, channelLostVillages string) (CreateGroupParams, error) {
if serverID == "" {
return CreateGroupParams{}, RequiredError{
Field: "ServerID",
}
}
if versionCode == "" {
return CreateGroupParams{}, RequiredError{
Field: "VersionCode",
}
}
if serverKey == "" {
return CreateGroupParams{}, RequiredError{
Field: "ServerKey",
}
}
return CreateGroupParams{
serverID: serverID,
serverKey: serverKey,
versionCode: versionCode,
channelGainedVillages: channelGainedVillages,
channelLostVillages: channelLostVillages,
}, 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) ChannelGainedVillages() string {
return c.channelGainedVillages
}
func (c CreateGroupParams) ChannelLostVillages() string {
return c.channelLostVillages
}
type UpdateGroupParams struct {
ChannelGainedVillages NullString
ChannelLostVillages NullString
ServerKey NullString
VersionCode NullString
}
func (u UpdateGroupParams) IsZero() bool {
return !u.ChannelGainedVillages.Valid &&
!u.ChannelLostVillages.Valid &&
!u.VersionCode.Valid &&
!u.ServerKey.Valid
}
type ListGroupsParams struct {
ServerIDs []string
}
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
}