refactor: remove dead code, rename some TWHelpHTTP methods
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dawid Wysokiński 2023-07-09 06:28:45 +02:00
parent 9dbfd76c89
commit f9dfe1c998
Signed by: Kichiyaki
GPG Key ID: B5445E357FB8B892
7 changed files with 29 additions and 45 deletions

View File

@ -126,7 +126,7 @@ func (t *TWHelpHTTP) GetExistingTribeByTag(ctx context.Context, versionCode, ser
return t.convertTribeToDomain(tribes[0]), nil
}
func (t *TWHelpHTTP) ListTribesTag(
func (t *TWHelpHTTP) ListTribesByTag(
ctx context.Context,
versionCode, serverKey string,
tribeTags []string,
@ -153,7 +153,7 @@ func (t *TWHelpHTTP) ListTribesTag(
return res, nil
}
func (t *TWHelpHTTP) ListVillagesCoords(
func (t *TWHelpHTTP) ListVillagesByCoords(
ctx context.Context,
versionCode, serverKey string,
coords []string,
@ -247,6 +247,8 @@ func (t *TWHelpHTTP) convertVillageToDomain(v twhelp.Village) domain.Village {
FullName: v.FullName,
ProfileURL: v.ProfileURL,
Points: v.Points,
X: v.X,
Y: v.Y,
Player: t.convertNullPlayerMetaToDomain(v.Player),
}
}

View File

@ -55,6 +55,8 @@ type Village struct {
FullName string
ProfileURL string
Points int64
X int64
Y int64
Player NullPlayerMeta
}

View File

@ -1,22 +0,0 @@
package service
import (
"context"
"gitea.dwysokinski.me/twhelp/dcbot/internal/domain"
)
type Coords struct {
twhelpSvc TWHelpService
}
func NewCoords(twhelpSvc TWHelpService) *Coords {
return &Coords{twhelpSvc: twhelpSvc}
}
func (c *Coords) Translate(ctx context.Context, version, server string, coords ...string) ([]domain.Village, error) {
if len(coords) == 0 {
return nil, nil
}
return c.twhelpSvc.ListVillagesCoords(ctx, version, server, coords, 0, int32(len(coords)))
}

View File

@ -110,7 +110,7 @@ func (g *Group) RemoveTribe(ctx context.Context, id, serverID, tribeTag string)
return domain.GroupWithMonitors{}, err
}
tribes, err := g.twhelpSvc.ListTribesTag(ctx, groupBeforeUpdate.VersionCode, groupBeforeUpdate.ServerKey, []string{tribeTag}, 0, listTribesLimit)
tribes, err := g.twhelpSvc.ListTribesByTag(ctx, groupBeforeUpdate.VersionCode, groupBeforeUpdate.ServerKey, []string{tribeTag}, 0, listTribesLimit)
if err != nil {
return domain.GroupWithMonitors{}, fmt.Errorf("TWHelpClient.ListTribes: %w", err)
}

View File

@ -266,7 +266,7 @@ func TestGroup_RemoveTribe(t *testing.T) {
ID: group.Monitors[0].TribeID,
Tag: "*TAG*",
}
twhelpSvc.ListTribesTagReturns([]domain.Tribe{tribe}, nil)
twhelpSvc.ListTribesByTagReturns([]domain.Tribe{tribe}, nil)
g, err := service.
NewGroup(repo, twhelpSvc, zap.NewNop(), 1, 1).

View File

@ -17,7 +17,7 @@ type TWHelpService interface {
GetOpenServer(ctx context.Context, versionCode, serverKey string) (domain.TWServer, error)
GetTribeByID(ctx context.Context, versionCode, serverKey string, id int64) (domain.Tribe, error)
GetExistingTribeByTag(ctx context.Context, versionCode, serverKey, tribeTag string) (domain.Tribe, error)
ListTribesTag(ctx context.Context, versionCode, serverKey string, tribeTags []string, offset, limit int32) ([]domain.Tribe, error)
ListVillagesCoords(ctx context.Context, versionCode, serverKey string, coords []string, offset, limit int32) ([]domain.Village, error)
ListTribesByTag(ctx context.Context, versionCode, serverKey string, tribeTags []string, offset, limit int32) ([]domain.Tribe, error)
ListVillagesByCoords(ctx context.Context, versionCode, serverKey string, coords []string, offset, limit int32) ([]domain.Village, error)
ListEnnoblementsSince(ctx context.Context, versionCode, serverKey string, since time.Time, offset, limit int32) ([]domain.Ennoblement, error)
}

View File

@ -5,6 +5,11 @@ import (
"time"
)
type NullBool struct {
Bool bool
Valid bool // Valid is true if Bool is not NULL
}
type ErrorCode string
const (
@ -143,6 +148,20 @@ func (p *NullPlayerMeta) UnmarshalJSON(data []byte) error {
return nil
}
type Village struct {
ID int64 `json:"id"`
FullName string `json:"fullName"`
ProfileURL string `json:"profileUrl"`
Points int64 `json:"points"`
X int64 `json:"x"`
Y int64 `json:"y"`
Player NullPlayerMeta `json:"player"`
}
type listVillagesResp struct {
Data []Village `json:"data"`
}
type VillageMeta struct {
ID int64 `json:"id"`
FullName string `json:"fullName"`
@ -160,20 +179,3 @@ type Ennoblement struct {
type listEnnoblementsResp struct {
Data []Ennoblement `json:"data"`
}
type NullBool struct {
Bool bool
Valid bool // Valid is true if Bool is not NULL
}
type Village struct {
ID int64 `json:"id"`
FullName string `json:"fullName"`
ProfileURL string `json:"profileUrl"`
Points int64 `json:"points"`
Player NullPlayerMeta `json:"player"`
}
type listVillagesResp struct {
Data []Village `json:"data"`
}