refactor: split domain/tw.go into multiple files
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dawid Wysokiński 2023-07-09 08:06:53 +02:00
parent 79f19b7a23
commit c7efe7a240
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
7 changed files with 88 additions and 79 deletions

View File

@ -0,0 +1,18 @@
package domain
import "time"
type Ennoblement struct {
ID int64
Village VillageMeta
NewOwner NullPlayerMeta
CreatedAt time.Time
}
func (e Ennoblement) IsBarbarian() bool {
return !e.Village.Player.Valid
}
func (e Ennoblement) IsSelfConquer() bool {
return e.NewOwner.Player.ID == e.Village.Player.Player.ID
}

13
internal/domain/player.go Normal file
View File

@ -0,0 +1,13 @@
package domain
type PlayerMeta struct {
ID int64
Name string
ProfileURL string
Tribe NullTribeMeta
}
type NullPlayerMeta struct {
Player PlayerMeta
Valid bool
}

View File

@ -5,19 +5,6 @@ import (
"time"
)
type TWVersion struct {
Code string
Host string
Name string
Timezone string
}
type TWServer struct {
Key string
URL string
Open bool
}
type Tribe struct {
ID int64
Tag string
@ -38,72 +25,6 @@ type NullTribeMeta struct {
Valid bool
}
type PlayerMeta struct {
ID int64
Name string
ProfileURL string
Tribe NullTribeMeta
}
type NullPlayerMeta struct {
Player PlayerMeta
Valid bool
}
type Village struct {
ID int64
FullName string
ProfileURL string
Points int64
X int64
Y int64
Player NullPlayerMeta
}
type VillageMeta struct {
ID int64
FullName string
ProfileURL string
Player NullPlayerMeta
}
type Ennoblement struct {
ID int64
Village VillageMeta
NewOwner NullPlayerMeta
CreatedAt time.Time
}
func (e Ennoblement) IsBarbarian() bool {
return !e.Village.Player.Valid
}
func (e Ennoblement) IsSelfConquer() bool {
return e.NewOwner.Player.ID == e.Village.Player.Player.ID
}
type TWServerNotFoundError struct {
VersionCode string
Key string
}
var _ TranslatableError = TWServerNotFoundError{}
func (e TWServerNotFoundError) Error() string {
return fmt.Sprintf("server (versionCode=%s,key=%s) not found", e.VersionCode, e.Key)
}
func (e TWServerNotFoundError) Slug() string {
return "tw-server-not-found"
}
func (e TWServerNotFoundError) Params() map[string]any {
return map[string]any{
"VersionCode": e.VersionCode,
"Key": e.Key,
}
}
type TribeTagNotFoundError struct {
VersionCode string
ServerKey string

View File

@ -0,0 +1,31 @@
package domain
import "fmt"
type TWServer struct {
Key string
URL string
Open bool
}
type TWServerNotFoundError struct {
VersionCode string
Key string
}
var _ TranslatableError = TWServerNotFoundError{}
func (e TWServerNotFoundError) Error() string {
return fmt.Sprintf("server (versionCode=%s,key=%s) not found", e.VersionCode, e.Key)
}
func (e TWServerNotFoundError) Slug() string {
return "tw-server-not-found"
}
func (e TWServerNotFoundError) Params() map[string]any {
return map[string]any{
"VersionCode": e.VersionCode,
"Key": e.Key,
}
}

View File

@ -0,0 +1,8 @@
package domain
type TWVersion struct {
Code string
Host string
Name string
Timezone string
}

View File

@ -0,0 +1,18 @@
package domain
type Village struct {
ID int64
FullName string
ProfileURL string
Points int64
X int64
Y int64
Player NullPlayerMeta
}
type VillageMeta struct {
ID int64
FullName string
ProfileURL string
Player NullPlayerMeta
}