refactor: refresh servers cmd - send url instead of just host in payload
This commit is contained in:
parent
42f95d6dd1
commit
cde9990810
|
@ -90,7 +90,7 @@ type ListServersParams struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefreshServersCmdPayload struct {
|
type RefreshServersCmdPayload struct {
|
||||||
Host string
|
URL string
|
||||||
VersionCode string
|
VersionCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ type Version struct {
|
||||||
Timezone string
|
Timezone string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Version) URL() string {
|
||||||
|
return "https://" + v.Host
|
||||||
|
}
|
||||||
|
|
||||||
type VersionNotFoundError struct {
|
type VersionNotFoundError struct {
|
||||||
VerCode string
|
VerCode string
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
//counterfeiter:generate -o internal/mock/server_service.gen.go . ServerService
|
//counterfeiter:generate -o internal/mock/server_service.gen.go . ServerService
|
||||||
type ServerService interface {
|
type ServerService interface {
|
||||||
Refresh(ctx context.Context, host, versionCode string) ([]domain.Server, error)
|
Refresh(ctx context.Context, url, versionCode string) ([]domain.Server, error)
|
||||||
UpdateInfoAndConfig(ctx context.Context, key, url string) error
|
UpdateInfoAndConfig(ctx context.Context, key, url string) error
|
||||||
UpdateNumPlayers(ctx context.Context, key string, numPlayers int64) error
|
UpdateNumPlayers(ctx context.Context, key string, numPlayers int64) error
|
||||||
UpdateNumTribes(ctx context.Context, key string, numTribes int64) error
|
UpdateNumTribes(ctx context.Context, key string, numTribes int64) error
|
||||||
|
@ -116,7 +116,7 @@ func (s *ServerConsumer) refresh(msg *message.Message) ([]*message.Message, erro
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
servers, err := s.svc.Refresh(msg.Context(), payload.Host, payload.VersionCode)
|
servers, err := s.svc.Refresh(msg.Context(), payload.URL, payload.VersionCode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("ServerService.Refresh: %w", err)
|
return nil, fmt.Errorf("ServerService.Refresh: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package msg_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ThreeDotsLabs/watermill"
|
"github.com/ThreeDotsLabs/watermill"
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"gitea.dwysokinski.me/twhelp/core/internal/msg/internal/model"
|
"gitea.dwysokinski.me/twhelp/core/internal/msg/internal/model"
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ func TestServerConsumer_refresh(t *testing.T) {
|
||||||
t,
|
t,
|
||||||
msg.NewServerPublisher(pubSub, marshaler).
|
msg.NewServerPublisher(pubSub, marshaler).
|
||||||
CmdRefresh(context.Background(), domain.RefreshServersCmdPayload{
|
CmdRefresh(context.Background(), domain.RefreshServersCmdPayload{
|
||||||
Host: "plemiona.pl",
|
URL: "plemiona.pl",
|
||||||
VersionCode: "pl",
|
VersionCode: "pl",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
@ -78,7 +78,7 @@ func TestServerConsumer_refresh(t *testing.T) {
|
||||||
Open: srv.Open,
|
Open: srv.Open,
|
||||||
VersionCode: srv.VersionCode,
|
VersionCode: srv.VersionCode,
|
||||||
}
|
}
|
||||||
if reflect.DeepEqual(expected, received) {
|
if cmp.Equal(expected, received) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
type RefreshServersCmdPayload struct {
|
type RefreshServersCmdPayload struct {
|
||||||
Host string
|
URL string
|
||||||
VersionCode string
|
VersionCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@ func TestServerPublisher_CmdRefresh(t *testing.T) {
|
||||||
|
|
||||||
payloads := []domain.RefreshServersCmdPayload{
|
payloads := []domain.RefreshServersCmdPayload{
|
||||||
{
|
{
|
||||||
Host: "host1.com",
|
URL: "https://host1.com",
|
||||||
VersionCode: "vc1",
|
VersionCode: "vc1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Host: "host2.com",
|
URL: "https://host2.com",
|
||||||
VersionCode: "vc2",
|
VersionCode: "vc2",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func TestServerPublisher_CmdRefresh(t *testing.T) {
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
for _, payload := range payloads {
|
for _, payload := range payloads {
|
||||||
if payload.VersionCode == received.VersionCode && payload.Host == received.Host {
|
if payload.VersionCode == received.VersionCode && payload.URL == received.URL {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ func (j *Job) UpdateData(ctx context.Context) error {
|
||||||
payloads := make([]domain.RefreshServersCmdPayload, 0, len(versions))
|
payloads := make([]domain.RefreshServersCmdPayload, 0, len(versions))
|
||||||
for _, v := range versions {
|
for _, v := range versions {
|
||||||
payloads = append(payloads, domain.RefreshServersCmdPayload{
|
payloads = append(payloads, domain.RefreshServersCmdPayload{
|
||||||
Host: v.Host,
|
URL: v.URL(),
|
||||||
VersionCode: v.Code,
|
VersionCode: v.Code,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ type ServerRepository interface {
|
||||||
|
|
||||||
//counterfeiter:generate -o internal/mock/open_server_config_info_getter.gen.go . OpenServerConfigInfoGetter
|
//counterfeiter:generate -o internal/mock/open_server_config_info_getter.gen.go . OpenServerConfigInfoGetter
|
||||||
type OpenServerConfigInfoGetter interface {
|
type OpenServerConfigInfoGetter interface {
|
||||||
GetOpenServers(ctx context.Context, host string) ([]tw.Server, error)
|
GetOpenServers(ctx context.Context, baseURL string) ([]tw.Server, error)
|
||||||
GetServerConfig(ctx context.Context, baseURL string) (tw.ServerConfig, error)
|
GetServerConfig(ctx context.Context, baseURL string) (tw.ServerConfig, error)
|
||||||
GetBuildingInfo(ctx context.Context, baseURL string) (tw.BuildingInfo, error)
|
GetBuildingInfo(ctx context.Context, baseURL string) (tw.BuildingInfo, error)
|
||||||
GetUnitInfo(ctx context.Context, baseURL string) (tw.UnitInfo, error)
|
GetUnitInfo(ctx context.Context, baseURL string) (tw.UnitInfo, error)
|
||||||
|
@ -38,8 +38,8 @@ func NewServer(repo ServerRepository, client OpenServerConfigInfoGetter) *Server
|
||||||
return &Server{repo: repo, client: client}
|
return &Server{repo: repo, client: client}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Refresh(ctx context.Context, host, versionCode string) ([]domain.Server, error) {
|
func (s *Server) Refresh(ctx context.Context, url, versionCode string) ([]domain.Server, error) {
|
||||||
openServers, err := s.client.GetOpenServers(ctx, "https://"+host)
|
openServers, err := s.client.GetOpenServers(ctx, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("TWClient.GetOpenServers: %w", err)
|
return nil, fmt.Errorf("TWClient.GetOpenServers: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user