2023-12-24 10:44:20 +00:00
|
|
|
package adapter_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/adapter"
|
|
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/adapter/adaptertest"
|
|
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
|
|
|
|
"github.com/uptrace/bun"
|
|
|
|
)
|
|
|
|
|
|
|
|
type versionRepository interface {
|
|
|
|
List(ctx context.Context, params domain.ListVersionsParams) (domain.Versions, error)
|
|
|
|
ListCount(
|
|
|
|
ctx context.Context,
|
|
|
|
params domain.ListVersionsParams,
|
|
|
|
) (domain.Versions, int, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type serverRepository interface {
|
|
|
|
CreateOrUpdate(ctx context.Context, params ...domain.CreateServerParams) error
|
|
|
|
List(ctx context.Context, params domain.ListServersParams) (domain.Servers, error)
|
2023-12-25 11:04:12 +00:00
|
|
|
Update(ctx context.Context, key string, params domain.UpdateServerParams) error
|
2023-12-24 10:44:20 +00:00
|
|
|
}
|
|
|
|
|
2023-12-28 10:56:59 +00:00
|
|
|
type tribeRepository interface {
|
|
|
|
CreateOrUpdate(ctx context.Context, params ...domain.CreateTribeParams) error
|
2024-01-03 08:09:13 +00:00
|
|
|
UpdateDominance(ctx context.Context, serverKey string, numPlayerVillages int) error
|
2023-12-28 10:56:59 +00:00
|
|
|
List(ctx context.Context, params domain.ListTribesParams) (domain.Tribes, error)
|
|
|
|
Delete(ctx context.Context, serverKey string, ids ...int) error
|
|
|
|
}
|
|
|
|
|
2024-01-01 10:20:30 +00:00
|
|
|
type playerRepository interface {
|
|
|
|
CreateOrUpdate(ctx context.Context, params ...domain.CreatePlayerParams) error
|
|
|
|
List(ctx context.Context, params domain.ListPlayersParams) (domain.Players, error)
|
|
|
|
Delete(ctx context.Context, serverKey string, ids ...int) error
|
|
|
|
}
|
|
|
|
|
2024-01-02 09:54:11 +00:00
|
|
|
type villageRepository interface {
|
|
|
|
CreateOrUpdate(ctx context.Context, params ...domain.CreateVillageParams) error
|
|
|
|
List(ctx context.Context, params domain.ListVillagesParams) (domain.Villages, error)
|
|
|
|
Delete(ctx context.Context, serverKey string, ids ...int) error
|
|
|
|
}
|
|
|
|
|
2024-01-04 10:44:36 +00:00
|
|
|
type ennoblementRepository interface {
|
|
|
|
Create(ctx context.Context, params ...domain.CreateEnnoblementParams) error
|
|
|
|
List(ctx context.Context, params domain.ListEnnoblementsParams) (domain.Ennoblements, error)
|
|
|
|
}
|
|
|
|
|
2024-01-06 09:26:56 +00:00
|
|
|
type tribeChangeRepository interface {
|
|
|
|
Create(ctx context.Context, params ...domain.CreateTribeChangeParams) error
|
|
|
|
List(ctx context.Context, params domain.ListTribeChangesParams) (domain.TribeChanges, error)
|
|
|
|
}
|
|
|
|
|
2023-12-24 10:44:20 +00:00
|
|
|
type repositories struct {
|
2024-01-04 10:44:36 +00:00
|
|
|
version versionRepository
|
|
|
|
server serverRepository
|
|
|
|
tribe tribeRepository
|
|
|
|
player playerRepository
|
|
|
|
village villageRepository
|
|
|
|
ennoblement ennoblementRepository
|
2024-01-06 09:26:56 +00:00
|
|
|
tribeChange tribeChangeRepository
|
2023-12-24 10:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newBunDBRepositories(tb testing.TB, bunDB *bun.DB) repositories {
|
|
|
|
tb.Helper()
|
|
|
|
|
|
|
|
adaptertest.NewFixture(bunDB).Load(tb, context.Background(), os.DirFS("testdata"), "fixture.yml")
|
|
|
|
|
|
|
|
return repositories{
|
2024-01-04 10:44:36 +00:00
|
|
|
version: adapter.NewVersionBunRepository(bunDB),
|
|
|
|
server: adapter.NewServerBunRepository(bunDB),
|
|
|
|
tribe: adapter.NewTribeBunRepository(bunDB),
|
|
|
|
player: adapter.NewPlayerBunRepository(bunDB),
|
|
|
|
village: adapter.NewVillageBunRepository(bunDB),
|
|
|
|
ennoblement: adapter.NewEnnoblementBunRepository(bunDB),
|
2024-01-06 09:26:56 +00:00
|
|
|
tribeChange: adapter.NewTribeChangeBunRepository(bunDB),
|
2023-12-24 10:44:20 +00:00
|
|
|
}
|
|
|
|
}
|