refactor: adapters - rename structs/files
This commit is contained in:
parent
dc8029e76d
commit
9c1b580adb
|
@ -61,7 +61,7 @@ func newServerCommand() *cli.Command {
|
|||
marshaler msg.Marshaler,
|
||||
bunDB *bun.DB,
|
||||
) error {
|
||||
svc := service.NewServer(adapter.NewServerBun(bunDB), internal.NewTWClient(c.App.Version))
|
||||
svc := service.NewServer(adapter.NewServerBunRepository(bunDB), internal.NewTWClient(c.App.Version))
|
||||
msg.NewServerConsumer(marshaler, publisher, subscriber, logger, svc).Register(router)
|
||||
return nil
|
||||
},
|
||||
|
@ -86,8 +86,8 @@ func newTribeCommand() *cli.Command {
|
|||
marshaler msg.Marshaler,
|
||||
bunDB *bun.DB,
|
||||
) error {
|
||||
svc := service.NewTribe(adapter.NewTribeBun(bunDB), internal.NewTWClient(c.App.Version))
|
||||
snapshotSvc := service.NewTribeSnapshot(adapter.NewTribeSnapshotBun(bunDB), svc)
|
||||
svc := service.NewTribe(adapter.NewTribeBunRepository(bunDB), internal.NewTWClient(c.App.Version))
|
||||
snapshotSvc := service.NewTribeSnapshot(adapter.NewTribeSnapshotBunRepository(bunDB), svc)
|
||||
msg.NewTribeConsumer(
|
||||
marshaler,
|
||||
publisher,
|
||||
|
@ -119,9 +119,9 @@ func newPlayerCommand() *cli.Command {
|
|||
marshaler msg.Marshaler,
|
||||
bunDB *bun.DB,
|
||||
) error {
|
||||
tribeChangeSvc := service.NewTribeChange(adapter.NewTribeChangeBun(bunDB))
|
||||
svc := service.NewPlayer(adapter.NewPlayerBun(bunDB), tribeChangeSvc, internal.NewTWClient(c.App.Version))
|
||||
snapshotSvc := service.NewPlayerSnapshot(adapter.NewPlayerSnapshotBun(bunDB), svc)
|
||||
tribeChangeSvc := service.NewTribeChange(adapter.NewTribeChangeBunRepository(bunDB))
|
||||
svc := service.NewPlayer(adapter.NewPlayerBunRepository(bunDB), tribeChangeSvc, internal.NewTWClient(c.App.Version))
|
||||
snapshotSvc := service.NewPlayerSnapshot(adapter.NewPlayerSnapshotBunRepository(bunDB), svc)
|
||||
msg.NewPlayerConsumer(
|
||||
marshaler,
|
||||
publisher,
|
||||
|
@ -153,7 +153,7 @@ func newVillageCommand() *cli.Command {
|
|||
marshaler msg.Marshaler,
|
||||
bunDB *bun.DB,
|
||||
) error {
|
||||
svc := service.NewVillage(adapter.NewVillageBun(bunDB), internal.NewTWClient(c.App.Version))
|
||||
svc := service.NewVillage(adapter.NewVillageBunRepository(bunDB), internal.NewTWClient(c.App.Version))
|
||||
msg.NewVillageConsumer(marshaler, publisher, subscriber, logger, svc).Register(router)
|
||||
return nil
|
||||
},
|
||||
|
@ -178,7 +178,7 @@ func newEnnoblementCommand() *cli.Command {
|
|||
marshaler msg.Marshaler,
|
||||
bunDB *bun.DB,
|
||||
) error {
|
||||
svc := service.NewEnnoblement(adapter.NewEnnoblementBun(bunDB), internal.NewTWClient(c.App.Version))
|
||||
svc := service.NewEnnoblement(adapter.NewEnnoblementBunRepository(bunDB), internal.NewTWClient(c.App.Version))
|
||||
msg.NewEnnoblementConsumer(marshaler, publisher, subscriber, logger, svc).Register(router)
|
||||
return nil
|
||||
},
|
||||
|
|
|
@ -149,14 +149,14 @@ func runJob(c *cli.Context, timeout time.Duration, f runJobFunc) error {
|
|||
|
||||
client := internal.NewTWClient(c.App.Version)
|
||||
|
||||
versionSvc := service.NewVersion(adapter.NewVersionBun(db))
|
||||
serverSvc := service.NewServer(adapter.NewServerBun(db), client)
|
||||
tribeChangeSvc := service.NewTribeChange(adapter.NewTribeChangeBun(db))
|
||||
tribeSvc := service.NewTribe(adapter.NewTribeBun(db), client)
|
||||
tribeSnapshotSvc := service.NewTribeSnapshot(adapter.NewTribeSnapshotBun(db), tribeSvc)
|
||||
playerSvc := service.NewPlayer(adapter.NewPlayerBun(db), tribeChangeSvc, client)
|
||||
playerSnapshotSvc := service.NewPlayerSnapshot(adapter.NewPlayerSnapshotBun(db), playerSvc)
|
||||
ennoblementSvc := service.NewEnnoblement(adapter.NewEnnoblementBun(db), client)
|
||||
versionSvc := service.NewVersion(adapter.NewVersionBunRepository(db))
|
||||
serverSvc := service.NewServer(adapter.NewServerBunRepository(db), client)
|
||||
tribeChangeSvc := service.NewTribeChange(adapter.NewTribeChangeBunRepository(db))
|
||||
tribeSvc := service.NewTribe(adapter.NewTribeBunRepository(db), client)
|
||||
tribeSnapshotSvc := service.NewTribeSnapshot(adapter.NewTribeSnapshotBunRepository(db), tribeSvc)
|
||||
playerSvc := service.NewPlayer(adapter.NewPlayerBunRepository(db), tribeChangeSvc, client)
|
||||
playerSnapshotSvc := service.NewPlayerSnapshot(adapter.NewPlayerSnapshotBunRepository(db), playerSvc)
|
||||
ennoblementSvc := service.NewEnnoblement(adapter.NewEnnoblementBunRepository(db), client)
|
||||
|
||||
return f(ctx, service.NewJob(
|
||||
versionSvc,
|
||||
|
|
|
@ -84,15 +84,15 @@ func newServer(appVersion string, logger *zap.Logger, db *bun.DB) (*http.Server,
|
|||
client := internal.NewTWClient(appVersion)
|
||||
|
||||
// repos
|
||||
versionRepo := adapter.NewVersionBun(db)
|
||||
serverRepo := adapter.NewServerBun(db)
|
||||
tribeRepo := adapter.NewTribeBun(db)
|
||||
playerRepo := adapter.NewPlayerBun(db)
|
||||
villageRepo := adapter.NewVillageBun(db)
|
||||
ennoblementRepo := adapter.NewEnnoblementBun(db)
|
||||
tribeChangeRepo := adapter.NewTribeChangeBun(db)
|
||||
playerSnapshotRepo := adapter.NewPlayerSnapshotBun(db)
|
||||
tribeSnapshotRepo := adapter.NewTribeSnapshotBun(db)
|
||||
versionRepo := adapter.NewVersionBunRepository(db)
|
||||
serverRepo := adapter.NewServerBunRepository(db)
|
||||
tribeRepo := adapter.NewTribeBunRepository(db)
|
||||
playerRepo := adapter.NewPlayerBunRepository(db)
|
||||
villageRepo := adapter.NewVillageBunRepository(db)
|
||||
ennoblementRepo := adapter.NewEnnoblementBunRepository(db)
|
||||
tribeChangeRepo := adapter.NewTribeChangeBunRepository(db)
|
||||
playerSnapshotRepo := adapter.NewPlayerSnapshotBunRepository(db)
|
||||
tribeSnapshotRepo := adapter.NewTribeSnapshotBunRepository(db)
|
||||
|
||||
// services
|
||||
versionSvc := service.NewVersion(versionRepo)
|
||||
|
|
|
@ -11,11 +11,11 @@ import (
|
|||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type bunfixture struct {
|
||||
type bunFixture struct {
|
||||
*bundbtest.Fixture
|
||||
}
|
||||
|
||||
func loadFixtures(tb testing.TB, bunDB *bun.DB) *bunfixture {
|
||||
func loadFixtures(tb testing.TB, bunDB *bun.DB) *bunFixture {
|
||||
tb.Helper()
|
||||
|
||||
fixture := bundbtest.NewFixture(bunDB)
|
||||
|
@ -23,10 +23,10 @@ func loadFixtures(tb testing.TB, bunDB *bun.DB) *bunfixture {
|
|||
err := fixture.Load(context.Background(), os.DirFS("testdata"), "fixture.yml")
|
||||
require.NoError(tb, err, "couldn't load fixtures")
|
||||
|
||||
return &bunfixture{fixture}
|
||||
return &bunFixture{fixture}
|
||||
}
|
||||
|
||||
func (f *bunfixture) Tribes(tb testing.TB) []domain.Tribe {
|
||||
func (f *bunFixture) Tribes(tb testing.TB) []domain.Tribe {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
@ -35,7 +35,7 @@ func (f *bunfixture) Tribes(tb testing.TB) []domain.Tribe {
|
|||
return f.Fixture.Tribes(tb, ids...)
|
||||
}
|
||||
|
||||
func (f *bunfixture) Players(tb testing.TB) []domain.Player {
|
||||
func (f *bunFixture) Players(tb testing.TB) []domain.Player {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
@ -44,7 +44,7 @@ func (f *bunfixture) Players(tb testing.TB) []domain.Player {
|
|||
return f.Fixture.Players(tb, ids...)
|
||||
}
|
||||
|
||||
func (f *bunfixture) Villages(tb testing.TB) []domain.Village {
|
||||
func (f *bunFixture) Villages(tb testing.TB) []domain.Village {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
@ -53,7 +53,7 @@ func (f *bunfixture) Villages(tb testing.TB) []domain.Village {
|
|||
return f.Fixture.Villages(tb, ids...)
|
||||
}
|
||||
|
||||
func (f *bunfixture) Ennoblements(tb testing.TB) []domain.Ennoblement {
|
||||
func (f *bunFixture) Ennoblements(tb testing.TB) []domain.Ennoblement {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
@ -62,7 +62,7 @@ func (f *bunfixture) Ennoblements(tb testing.TB) []domain.Ennoblement {
|
|||
return f.Fixture.Ennoblements(tb, ids...)
|
||||
}
|
||||
|
||||
func (f *bunfixture) PlayerSnapshots(tb testing.TB) []domain.PlayerSnapshot {
|
||||
func (f *bunFixture) PlayerSnapshots(tb testing.TB) []domain.PlayerSnapshot {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
@ -71,7 +71,7 @@ func (f *bunfixture) PlayerSnapshots(tb testing.TB) []domain.PlayerSnapshot {
|
|||
return f.Fixture.PlayerSnapshots(tb, ids...)
|
||||
}
|
||||
|
||||
func (f *bunfixture) TribeSnapshots(tb testing.TB) []domain.TribeSnapshot {
|
||||
func (f *bunFixture) TribeSnapshots(tb testing.TB) []domain.TribeSnapshot {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
@ -80,7 +80,7 @@ func (f *bunfixture) TribeSnapshots(tb testing.TB) []domain.TribeSnapshot {
|
|||
return f.Fixture.TribeSnapshots(tb, ids...)
|
||||
}
|
||||
|
||||
func (f *bunfixture) TribeChanges(tb testing.TB) []domain.TribeChange {
|
||||
func (f *bunFixture) TribeChanges(tb testing.TB) []domain.TribeChange {
|
||||
tb.Helper()
|
||||
|
||||
//nolint:lll
|
||||
|
|
|
@ -16,15 +16,15 @@ var (
|
|||
ennoblementOrders = []string{"ennoblement.server_key ASC"}
|
||||
)
|
||||
|
||||
type EnnoblementBun struct {
|
||||
type EnnoblementBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewEnnoblementBun(db *bun.DB) *EnnoblementBun {
|
||||
return &EnnoblementBun{db: db}
|
||||
func NewEnnoblementBunRepository(db *bun.DB) *EnnoblementBunRepository {
|
||||
return &EnnoblementBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (e *EnnoblementBun) Create(ctx context.Context, params ...domain.CreateEnnoblementParams) error {
|
||||
func (e *EnnoblementBunRepository) Create(ctx context.Context, params ...domain.CreateEnnoblementParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func (e *EnnoblementBun) Create(ctx context.Context, params ...domain.CreateEnno
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *EnnoblementBun) List(ctx context.Context, params domain.ListEnnoblementsParams) ([]domain.Ennoblement, error) {
|
||||
func (e *EnnoblementBunRepository) List(ctx context.Context, params domain.ListEnnoblementsParams) ([]domain.Ennoblement, error) {
|
||||
var ennoblements []bunmodel.Ennoblement
|
||||
|
||||
if err := e.db.NewSelect().
|
||||
|
@ -63,7 +63,7 @@ func (e *EnnoblementBun) List(ctx context.Context, params domain.ListEnnoblement
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (e *EnnoblementBun) ListCountWithRelations(
|
||||
func (e *EnnoblementBunRepository) ListCountWithRelations(
|
||||
ctx context.Context,
|
||||
params domain.ListEnnoblementsParams,
|
||||
) ([]domain.EnnoblementWithRelations, int64, error) {
|
||||
|
@ -113,7 +113,7 @@ func (e *EnnoblementBun) ListCountWithRelations(
|
|||
return result, int64(count), nil
|
||||
}
|
||||
|
||||
func (e *EnnoblementBun) Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error {
|
||||
func (e *EnnoblementBunRepository) Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error {
|
||||
if _, err := e.db.NewDelete().
|
||||
Model(&bunmodel.Ennoblement{}).
|
||||
Where("server_key = ?", serverKey).
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEnnoblementBun_Create(t *testing.T) {
|
||||
func TestEnnoblementBunRepository_Create(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -24,7 +24,7 @@ func TestEnnoblementBun_Create(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewEnnoblementBun(db)
|
||||
repo := adapter.NewEnnoblementBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -146,7 +146,7 @@ func TestEnnoblementBun_Create(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestEnnoblementBun_List(t *testing.T) {
|
||||
func TestEnnoblementBunRepository_List(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -155,7 +155,7 @@ func TestEnnoblementBun_List(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewEnnoblementBun(db)
|
||||
repo := adapter.NewEnnoblementBunRepository(db)
|
||||
ennoblements := fixture.Ennoblements(t)
|
||||
|
||||
type expectedEnnoblement struct {
|
||||
|
@ -477,7 +477,7 @@ func TestEnnoblementBun_List(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestEnnoblementBun_Delete(t *testing.T) {
|
||||
func TestEnnoblementBunRepository_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -486,7 +486,7 @@ func TestEnnoblementBun_Delete(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewEnnoblementBun(db)
|
||||
repo := adapter.NewEnnoblementBunRepository(db)
|
||||
|
||||
ennoblementsBeforeDelete, err := repo.List(context.Background(), domain.ListEnnoblementsParams{})
|
||||
assert.NoError(t, err)
|
|
@ -17,15 +17,15 @@ var (
|
|||
playerOrders = []string{"player.server_key ASC"}
|
||||
)
|
||||
|
||||
type PlayerBun struct {
|
||||
type PlayerBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewPlayerBun(db *bun.DB) *PlayerBun {
|
||||
return &PlayerBun{db: db}
|
||||
func NewPlayerBunRepository(db *bun.DB) *PlayerBunRepository {
|
||||
return &PlayerBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (p *PlayerBun) CreateOrUpdate(ctx context.Context, params ...domain.CreatePlayerParams) error {
|
||||
func (p *PlayerBunRepository) CreateOrUpdate(ctx context.Context, params ...domain.CreatePlayerParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (p *PlayerBun) CreateOrUpdate(ctx context.Context, params ...domain.CreateP
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *PlayerBun) Delete(ctx context.Context, serverKey string, ids ...int64) error {
|
||||
func (p *PlayerBunRepository) Delete(ctx context.Context, serverKey string, ids ...int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (p *PlayerBun) Delete(ctx context.Context, serverKey string, ids ...int64)
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *PlayerBun) List(ctx context.Context, params domain.ListPlayersParams) ([]domain.Player, error) {
|
||||
func (p *PlayerBunRepository) List(ctx context.Context, params domain.ListPlayersParams) ([]domain.Player, error) {
|
||||
var players []bunmodel.Player
|
||||
|
||||
if err := p.db.NewSelect().
|
||||
|
@ -99,7 +99,10 @@ func (p *PlayerBun) List(ctx context.Context, params domain.ListPlayersParams) (
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (p *PlayerBun) ListCountWithRelations(ctx context.Context, params domain.ListPlayersParams) ([]domain.PlayerWithRelations, int64, error) {
|
||||
func (p *PlayerBunRepository) ListCountWithRelations(
|
||||
ctx context.Context,
|
||||
params domain.ListPlayersParams,
|
||||
) ([]domain.PlayerWithRelations, int64, error) {
|
||||
var players []bunmodel.Player
|
||||
|
||||
paramsApplier := listPlayersParamsApplier{params}
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
)
|
||||
|
||||
func TestPlayerBun_CreateOrUpdate(t *testing.T) {
|
||||
func TestPlayerBunRepository_CreateOrUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -23,7 +23,7 @@ func TestPlayerBun_CreateOrUpdate(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewPlayerBun(db)
|
||||
repo := adapter.NewPlayerBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -182,7 +182,7 @@ func TestPlayerBun_CreateOrUpdate(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestPlayerBun_Delete(t *testing.T) {
|
||||
func TestPlayerBunRepository_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -191,7 +191,7 @@ func TestPlayerBun_Delete(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewPlayerBun(db)
|
||||
repo := adapter.NewPlayerBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -221,7 +221,7 @@ func TestPlayerBun_Delete(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestPlayerBun_List_ListCountWithRelations(t *testing.T) {
|
||||
func TestPlayerBunRepository_List_ListCountWithRelations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -230,7 +230,7 @@ func TestPlayerBun_List_ListCountWithRelations(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewPlayerBun(db)
|
||||
repo := adapter.NewPlayerBunRepository(db)
|
||||
players := fixture.Players(t)
|
||||
tribeCSA := fixture.Tribe(t, "pl169-csa")
|
||||
|
|
@ -16,15 +16,15 @@ var (
|
|||
playerSnapshotOrders = []string{"ps.server_key ASC"}
|
||||
)
|
||||
|
||||
type PlayerSnapshotBun struct {
|
||||
type PlayerSnapshotBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewPlayerSnapshotBun(db *bun.DB) *PlayerSnapshotBun {
|
||||
return &PlayerSnapshotBun{db: db}
|
||||
func NewPlayerSnapshotBunRepository(db *bun.DB) *PlayerSnapshotBunRepository {
|
||||
return &PlayerSnapshotBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (p *PlayerSnapshotBun) Create(ctx context.Context, params ...domain.CreatePlayerSnapshotParams) error {
|
||||
func (p *PlayerSnapshotBunRepository) Create(ctx context.Context, params ...domain.CreatePlayerSnapshotParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func (p *PlayerSnapshotBun) Create(ctx context.Context, params ...domain.CreateP
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *PlayerSnapshotBun) List(ctx context.Context, params domain.ListPlayerSnapshotsParams) ([]domain.PlayerSnapshot, error) {
|
||||
func (p *PlayerSnapshotBunRepository) List(ctx context.Context, params domain.ListPlayerSnapshotsParams) ([]domain.PlayerSnapshot, error) {
|
||||
var snapshots []bunmodel.PlayerSnapshot
|
||||
|
||||
if err := p.db.NewSelect().
|
||||
|
@ -63,7 +63,7 @@ func (p *PlayerSnapshotBun) List(ctx context.Context, params domain.ListPlayerSn
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (p *PlayerSnapshotBun) ListCountWithRelations(
|
||||
func (p *PlayerSnapshotBunRepository) ListCountWithRelations(
|
||||
ctx context.Context,
|
||||
params domain.ListPlayerSnapshotsParams,
|
||||
) ([]domain.PlayerSnapshotWithRelations, int64, error) {
|
||||
|
@ -103,7 +103,7 @@ func (p *PlayerSnapshotBun) ListCountWithRelations(
|
|||
return result, int64(count), nil
|
||||
}
|
||||
|
||||
func (p *PlayerSnapshotBun) Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error {
|
||||
func (p *PlayerSnapshotBunRepository) Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error {
|
||||
if _, err := p.db.NewDelete().
|
||||
Model(&bunmodel.PlayerSnapshot{}).
|
||||
Where("server_key = ?", serverKey).
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
)
|
||||
|
||||
func TestPlayerSnapshotBun_Create(t *testing.T) {
|
||||
func TestPlayerSnapshotBunRepository_Create(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -23,7 +23,7 @@ func TestPlayerSnapshotBun_Create(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewPlayerSnapshotBun(db)
|
||||
repo := adapter.NewPlayerSnapshotBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -183,7 +183,7 @@ func TestPlayerSnapshotBun_Create(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestPlayerSnapshotBun_List(t *testing.T) {
|
||||
func TestPlayerSnapshotBunRepository_List(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -192,7 +192,7 @@ func TestPlayerSnapshotBun_List(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewPlayerSnapshotBun(db)
|
||||
repo := adapter.NewPlayerSnapshotBunRepository(db)
|
||||
snapshots := fixture.PlayerSnapshots(t)
|
||||
|
||||
type expectedSnapshots struct {
|
||||
|
@ -442,7 +442,7 @@ func TestPlayerSnapshotBun_List(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPlayerSnapshotBun_Delete(t *testing.T) {
|
||||
func TestPlayerSnapshotBunRepository_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -451,7 +451,7 @@ func TestPlayerSnapshotBun_Delete(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewPlayerSnapshotBun(db)
|
||||
repo := adapter.NewPlayerSnapshotBunRepository(db)
|
||||
|
||||
snapshotsBeforeDelete, err := repo.List(context.Background(), domain.ListPlayerSnapshotsParams{})
|
||||
assert.NoError(t, err)
|
|
@ -16,15 +16,15 @@ var (
|
|||
serverMetaColumns = []string{"key", "open", "url"}
|
||||
)
|
||||
|
||||
type ServerBun struct {
|
||||
type ServerBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewServerBun(db *bun.DB) *ServerBun {
|
||||
return &ServerBun{db: db}
|
||||
func NewServerBunRepository(db *bun.DB) *ServerBunRepository {
|
||||
return &ServerBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (s *ServerBun) CreateOrUpdate(ctx context.Context, params ...domain.CreateServerParams) ([]domain.Server, error) {
|
||||
func (s *ServerBunRepository) CreateOrUpdate(ctx context.Context, params ...domain.CreateServerParams) ([]domain.Server, error) {
|
||||
if len(params) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func (s *ServerBun) CreateOrUpdate(ctx context.Context, params ...domain.CreateS
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (s *ServerBun) List(ctx context.Context, params domain.ListServersParams) ([]domain.Server, error) {
|
||||
func (s *ServerBunRepository) List(ctx context.Context, params domain.ListServersParams) ([]domain.Server, error) {
|
||||
var servers []bunmodel.Server
|
||||
|
||||
if err := s.buildListQuery(&servers, params).Scan(ctx); err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
|
@ -74,7 +74,7 @@ func (s *ServerBun) List(ctx context.Context, params domain.ListServersParams) (
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (s *ServerBun) ListCount(ctx context.Context, params domain.ListServersParams) ([]domain.Server, int64, error) {
|
||||
func (s *ServerBunRepository) ListCount(ctx context.Context, params domain.ListServersParams) ([]domain.Server, int64, error) {
|
||||
var servers []bunmodel.Server
|
||||
|
||||
q := s.buildListQuery(&servers, params)
|
||||
|
@ -91,14 +91,14 @@ func (s *ServerBun) ListCount(ctx context.Context, params domain.ListServersPara
|
|||
return result, int64(count), nil
|
||||
}
|
||||
|
||||
func (s *ServerBun) buildListQuery(servers *[]bunmodel.Server, params domain.ListServersParams) *bun.SelectQuery {
|
||||
func (s *ServerBunRepository) buildListQuery(servers *[]bunmodel.Server, params domain.ListServersParams) *bun.SelectQuery {
|
||||
return s.db.NewSelect().
|
||||
Model(servers).
|
||||
Order("server.version_code ASC", "server.open DESC", "server.key ASC").
|
||||
Apply(listServersParamsApplier{params}.apply)
|
||||
}
|
||||
|
||||
func (s *ServerBun) Update(ctx context.Context, key string, params domain.UpdateServerParams) (domain.Server, error) {
|
||||
func (s *ServerBunRepository) Update(ctx context.Context, key string, params domain.UpdateServerParams) (domain.Server, error) {
|
||||
if params.IsZero() {
|
||||
return domain.Server{}, domain.ErrNothingToUpdate
|
||||
}
|
|
@ -15,14 +15,14 @@ import (
|
|||
"gitea.dwysokinski.me/twhelp/core/internal/domain"
|
||||
)
|
||||
|
||||
func TestServerBun_CreateOrUpdate(t *testing.T) {
|
||||
func TestServerBunRepository_CreateOrUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
t.Skip("skipping long-running test")
|
||||
}
|
||||
|
||||
repo := adapter.NewServerBun(newBunDB(t))
|
||||
repo := adapter.NewServerBunRepository(newBunDB(t))
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -85,7 +85,7 @@ func TestServerBun_CreateOrUpdate(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestServerBun_List_ListCount(t *testing.T) {
|
||||
func TestServerBunRepository_List_ListCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -127,7 +127,7 @@ func TestServerBun_List_ListCount(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
_ = loadFixtures(t, db)
|
||||
repo := adapter.NewServerBun(db)
|
||||
repo := adapter.NewServerBunRepository(db)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -329,7 +329,7 @@ func TestServerBun_List_ListCount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServerBun_Update(t *testing.T) {
|
||||
func TestServerBunRepository_Update(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -337,7 +337,7 @@ func TestServerBun_Update(t *testing.T) {
|
|||
}
|
||||
|
||||
db := newBunDB(t)
|
||||
repo := adapter.NewServerBun(db)
|
||||
repo := adapter.NewServerBunRepository(db)
|
||||
fixture := loadFixtures(t, db)
|
||||
server := fixture.Server(t, "de188")
|
||||
|
|
@ -16,15 +16,15 @@ var (
|
|||
tribeMetaColumns = []string{"id", "name", "tag", "profile_url"}
|
||||
)
|
||||
|
||||
type TribeBun struct {
|
||||
type TribeBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewTribeBun(db *bun.DB) *TribeBun {
|
||||
return &TribeBun{db: db}
|
||||
func NewTribeBunRepository(db *bun.DB) *TribeBunRepository {
|
||||
return &TribeBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (t *TribeBun) CreateOrUpdate(ctx context.Context, params ...domain.CreateTribeParams) error {
|
||||
func (t *TribeBunRepository) CreateOrUpdate(ctx context.Context, params ...domain.CreateTribeParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func (t *TribeBun) CreateOrUpdate(ctx context.Context, params ...domain.CreateTr
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *TribeBun) Delete(ctx context.Context, serverKey string, ids ...int64) error {
|
||||
func (t *TribeBunRepository) Delete(ctx context.Context, serverKey string, ids ...int64) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (t *TribeBun) Delete(ctx context.Context, serverKey string, ids ...int64) e
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *TribeBun) UpdateDominance(ctx context.Context, serverKey string, numPlayerVillages int64) error {
|
||||
func (t *TribeBunRepository) UpdateDominance(ctx context.Context, serverKey string, numPlayerVillages int64) error {
|
||||
q := t.db.NewUpdate().
|
||||
Model(&bunmodel.Tribe{}).
|
||||
Returning("NULL").
|
||||
|
@ -98,7 +98,7 @@ func (t *TribeBun) UpdateDominance(ctx context.Context, serverKey string, numPla
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *TribeBun) List(ctx context.Context, params domain.ListTribesParams) ([]domain.Tribe, error) {
|
||||
func (t *TribeBunRepository) List(ctx context.Context, params domain.ListTribesParams) ([]domain.Tribe, error) {
|
||||
var tribes []bunmodel.Tribe
|
||||
|
||||
if err := t.buildListQuery(&tribes, params).Scan(ctx); err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
|
@ -113,7 +113,7 @@ func (t *TribeBun) List(ctx context.Context, params domain.ListTribesParams) ([]
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (t *TribeBun) ListCount(ctx context.Context, params domain.ListTribesParams) ([]domain.Tribe, int64, error) {
|
||||
func (t *TribeBunRepository) ListCount(ctx context.Context, params domain.ListTribesParams) ([]domain.Tribe, int64, error) {
|
||||
var tribes []bunmodel.Tribe
|
||||
|
||||
q := t.buildListQuery(&tribes, params)
|
||||
|
@ -130,7 +130,7 @@ func (t *TribeBun) ListCount(ctx context.Context, params domain.ListTribesParams
|
|||
return result, int64(count), nil
|
||||
}
|
||||
|
||||
func (t *TribeBun) buildListQuery(tribes *[]bunmodel.Tribe, params domain.ListTribesParams) *bun.SelectQuery {
|
||||
func (t *TribeBunRepository) buildListQuery(tribes *[]bunmodel.Tribe, params domain.ListTribesParams) *bun.SelectQuery {
|
||||
return t.db.NewSelect().
|
||||
Model(tribes).
|
||||
Order("tribe.server_key ASC").
|
|
@ -17,7 +17,7 @@ import (
|
|||
"gitea.dwysokinski.me/twhelp/core/internal/adapter"
|
||||
)
|
||||
|
||||
func TestTribeBun_CreateOrUpdate(t *testing.T) {
|
||||
func TestTribeBunRepository_CreateOrUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -26,7 +26,7 @@ func TestTribeBun_CreateOrUpdate(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
_ = loadFixtures(t, db)
|
||||
repo := adapter.NewTribeBun(db)
|
||||
repo := adapter.NewTribeBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -185,7 +185,7 @@ func TestTribeBun_CreateOrUpdate(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestTribeBun_Delete(t *testing.T) {
|
||||
func TestTribeBunRepository_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -194,7 +194,7 @@ func TestTribeBun_Delete(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeBun(db)
|
||||
repo := adapter.NewTribeBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -223,7 +223,7 @@ func TestTribeBun_Delete(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestTribeBun_List_ListCount(t *testing.T) {
|
||||
func TestTribeBunRepository_List_ListCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -232,7 +232,7 @@ func TestTribeBun_List_ListCount(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeBun(db)
|
||||
repo := adapter.NewTribeBunRepository(db)
|
||||
tribes := fixture.Tribes(t)
|
||||
|
||||
type expectedTribe struct {
|
||||
|
@ -618,7 +618,7 @@ func TestTribeBun_List_ListCount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTribeBun_UpdateDominance(t *testing.T) {
|
||||
func TestTribeBunRepository_UpdateDominance(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -627,7 +627,7 @@ func TestTribeBun_UpdateDominance(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeBun(db)
|
||||
repo := adapter.NewTribeBunRepository(db)
|
||||
serverDE188 := fixture.Server(t, "de188")
|
||||
serverPL169 := fixture.Server(t, "pl169")
|
||||
|
|
@ -15,15 +15,15 @@ var (
|
|||
tribeChangeOrders = []string{"tc.server_key ASC"}
|
||||
)
|
||||
|
||||
type TribeChangeBun struct {
|
||||
type TribeChangeBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewTribeChangeBun(db *bun.DB) *TribeChangeBun {
|
||||
return &TribeChangeBun{db: db}
|
||||
func NewTribeChangeBunRepository(db *bun.DB) *TribeChangeBunRepository {
|
||||
return &TribeChangeBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (t *TribeChangeBun) Create(ctx context.Context, params ...domain.CreateTribeChangeParams) error {
|
||||
func (t *TribeChangeBunRepository) Create(ctx context.Context, params ...domain.CreateTribeChangeParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func (t *TribeChangeBun) Create(ctx context.Context, params ...domain.CreateTrib
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *TribeChangeBun) List(ctx context.Context, params domain.ListTribeChangesParams) ([]domain.TribeChange, error) {
|
||||
func (t *TribeChangeBunRepository) List(ctx context.Context, params domain.ListTribeChangesParams) ([]domain.TribeChange, error) {
|
||||
var tcs []bunmodel.TribeChange
|
||||
|
||||
if err := t.db.NewSelect().
|
||||
|
@ -62,7 +62,7 @@ func (t *TribeChangeBun) List(ctx context.Context, params domain.ListTribeChange
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (t *TribeChangeBun) ListCountWithRelations(
|
||||
func (t *TribeChangeBunRepository) ListCountWithRelations(
|
||||
ctx context.Context,
|
||||
params domain.ListTribeChangesParams,
|
||||
) ([]domain.TribeChangeWithRelations, int64, error) {
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
)
|
||||
|
||||
func TestTribeChangeBun_Create(t *testing.T) {
|
||||
func TestTribeChangeBunRepository_Create(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -21,7 +21,7 @@ func TestTribeChangeBun_Create(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeChangeBun(db)
|
||||
repo := adapter.NewTribeChangeBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -157,7 +157,7 @@ func TestTribeChangeBun_Create(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestTribeChangeBun_List_ListCountWithRelations(t *testing.T) {
|
||||
func TestTribeChangeBunRepository_List_ListCountWithRelations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -166,7 +166,7 @@ func TestTribeChangeBun_List_ListCountWithRelations(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeChangeBun(db)
|
||||
repo := adapter.NewTribeChangeBunRepository(db)
|
||||
tcs := fixture.TribeChanges(t)
|
||||
|
||||
type expectedTribeChange struct {
|
|
@ -12,15 +12,15 @@ import (
|
|||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type TribeSnapshotBun struct {
|
||||
type TribeSnapshotBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewTribeSnapshotBun(db *bun.DB) *TribeSnapshotBun {
|
||||
return &TribeSnapshotBun{db: db}
|
||||
func NewTribeSnapshotBunRepository(db *bun.DB) *TribeSnapshotBunRepository {
|
||||
return &TribeSnapshotBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (t *TribeSnapshotBun) Create(ctx context.Context, params ...domain.CreateTribeSnapshotParams) error {
|
||||
func (t *TribeSnapshotBunRepository) Create(ctx context.Context, params ...domain.CreateTribeSnapshotParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func (t *TribeSnapshotBun) Create(ctx context.Context, params ...domain.CreateTr
|
|||
return nil
|
||||
}
|
||||
|
||||
func (t *TribeSnapshotBun) List(ctx context.Context, params domain.ListTribeSnapshotsParams) ([]domain.TribeSnapshot, error) {
|
||||
func (t *TribeSnapshotBunRepository) List(ctx context.Context, params domain.ListTribeSnapshotsParams) ([]domain.TribeSnapshot, error) {
|
||||
var snapshots []bunmodel.TribeSnapshot
|
||||
|
||||
if err := t.buildListQuery(&snapshots, params).Scan(ctx); err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
|
@ -55,7 +55,7 @@ func (t *TribeSnapshotBun) List(ctx context.Context, params domain.ListTribeSnap
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (t *TribeSnapshotBun) ListCount(ctx context.Context, params domain.ListTribeSnapshotsParams) ([]domain.TribeSnapshot, int64, error) {
|
||||
func (t *TribeSnapshotBunRepository) ListCount(ctx context.Context, params domain.ListTribeSnapshotsParams) ([]domain.TribeSnapshot, int64, error) {
|
||||
var snapshots []bunmodel.TribeSnapshot
|
||||
|
||||
q := t.buildListQuery(&snapshots, params)
|
||||
|
@ -72,14 +72,14 @@ func (t *TribeSnapshotBun) ListCount(ctx context.Context, params domain.ListTrib
|
|||
return result, int64(count), nil
|
||||
}
|
||||
|
||||
func (t *TribeSnapshotBun) buildListQuery(snapshots *[]bunmodel.TribeSnapshot, params domain.ListTribeSnapshotsParams) *bun.SelectQuery {
|
||||
func (t *TribeSnapshotBunRepository) buildListQuery(snapshots *[]bunmodel.TribeSnapshot, params domain.ListTribeSnapshotsParams) *bun.SelectQuery {
|
||||
return t.db.NewSelect().
|
||||
Model(snapshots).
|
||||
Order("ts.server_key ASC").
|
||||
Apply(listTribeSnapshotsParamsApplier{params}.apply)
|
||||
}
|
||||
|
||||
func (t *TribeSnapshotBun) Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error {
|
||||
func (t *TribeSnapshotBunRepository) Delete(ctx context.Context, serverKey string, createdAtLTE time.Time) error {
|
||||
if _, err := t.db.NewDelete().
|
||||
Model(&bunmodel.TribeSnapshot{}).
|
||||
Where("server_key = ?", serverKey).
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
)
|
||||
|
||||
func TestTribeSnapshotBun_Create(t *testing.T) {
|
||||
func TestTribeSnapshotBunRepository_Create(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -23,7 +23,7 @@ func TestTribeSnapshotBun_Create(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeSnapshotBun(db)
|
||||
repo := adapter.NewTribeSnapshotBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -200,7 +200,7 @@ func TestTribeSnapshotBun_Create(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestTribeSnapshotBun_List_ListCount(t *testing.T) {
|
||||
func TestTribeSnapshotBunRepository_List_ListCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -209,7 +209,7 @@ func TestTribeSnapshotBun_List_ListCount(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeSnapshotBun(db)
|
||||
repo := adapter.NewTribeSnapshotBunRepository(db)
|
||||
snapshots := fixture.TribeSnapshots(t)
|
||||
|
||||
type expectedSnapshots struct {
|
||||
|
@ -451,7 +451,7 @@ func TestTribeSnapshotBun_List_ListCount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTribeSnapshotBun_Delete(t *testing.T) {
|
||||
func TestTribeSnapshotBunRepository_Delete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -460,7 +460,7 @@ func TestTribeSnapshotBun_Delete(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewTribeSnapshotBun(db)
|
||||
repo := adapter.NewTribeSnapshotBunRepository(db)
|
||||
|
||||
snapshotsBeforeDelete, err := repo.List(context.Background(), domain.ListTribeSnapshotsParams{})
|
||||
assert.NoError(t, err)
|
|
@ -11,15 +11,15 @@ import (
|
|||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type VersionBun struct {
|
||||
type VersionBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewVersionBun(db *bun.DB) *VersionBun {
|
||||
return &VersionBun{db: db}
|
||||
func NewVersionBunRepository(db *bun.DB) *VersionBunRepository {
|
||||
return &VersionBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (v *VersionBun) List(ctx context.Context) ([]domain.Version, error) {
|
||||
func (v *VersionBunRepository) List(ctx context.Context) ([]domain.Version, error) {
|
||||
var versions []bunmodel.Version
|
||||
|
||||
if err := v.buildListQuery(&versions).Scan(ctx); err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
|
@ -34,7 +34,7 @@ func (v *VersionBun) List(ctx context.Context) ([]domain.Version, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (v *VersionBun) ListCount(ctx context.Context) ([]domain.Version, int64, error) {
|
||||
func (v *VersionBunRepository) ListCount(ctx context.Context) ([]domain.Version, int64, error) {
|
||||
var versions []bunmodel.Version
|
||||
|
||||
count, err := v.buildListQuery(&versions).ScanAndCount(ctx)
|
||||
|
@ -50,13 +50,13 @@ func (v *VersionBun) ListCount(ctx context.Context) ([]domain.Version, int64, er
|
|||
return result, int64(count), nil
|
||||
}
|
||||
|
||||
func (v *VersionBun) buildListQuery(versions *[]bunmodel.Version) *bun.SelectQuery {
|
||||
func (v *VersionBunRepository) buildListQuery(versions *[]bunmodel.Version) *bun.SelectQuery {
|
||||
return v.db.NewSelect().
|
||||
Model(versions).
|
||||
Order("code ASC")
|
||||
}
|
||||
|
||||
func (v *VersionBun) GetByCode(ctx context.Context, code string) (domain.Version, error) {
|
||||
func (v *VersionBunRepository) GetByCode(ctx context.Context, code string) (domain.Version, error) {
|
||||
var version bunmodel.Version
|
||||
|
||||
if err := v.db.NewSelect().
|
|
@ -11,14 +11,14 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestVersionBun_List_ListCount(t *testing.T) {
|
||||
func TestVersionBunRepository_List_ListCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
t.Skip("skipping long-running test")
|
||||
}
|
||||
|
||||
repo := adapter.NewVersionBun(newBunDB(t))
|
||||
repo := adapter.NewVersionBunRepository(newBunDB(t))
|
||||
|
||||
allVersions := []string{
|
||||
"pl",
|
||||
|
@ -62,14 +62,14 @@ func TestVersionBun_List_ListCount(t *testing.T) {
|
|||
assert.Equal(t, resListCount, resList)
|
||||
}
|
||||
|
||||
func TestVersionBun_GetByCode(t *testing.T) {
|
||||
func TestVersionBunRepository_GetByCode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
t.Skip("skipping long-running test")
|
||||
}
|
||||
|
||||
repo := adapter.NewVersionBun(newBunDB(t))
|
||||
repo := adapter.NewVersionBunRepository(newBunDB(t))
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
|
@ -16,15 +16,15 @@ var (
|
|||
villageOrders = []string{"village.server_key ASC", "village.id ASC"}
|
||||
)
|
||||
|
||||
type VillageBun struct {
|
||||
type VillageBunRepository struct {
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
func NewVillageBun(db *bun.DB) *VillageBun {
|
||||
return &VillageBun{db: db}
|
||||
func NewVillageBunRepository(db *bun.DB) *VillageBunRepository {
|
||||
return &VillageBunRepository{db: db}
|
||||
}
|
||||
|
||||
func (v *VillageBun) CreateOrUpdate(ctx context.Context, params ...domain.CreateVillageParams) error {
|
||||
func (v *VillageBunRepository) CreateOrUpdate(ctx context.Context, params ...domain.CreateVillageParams) error {
|
||||
if len(params) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ func (v *VillageBun) CreateOrUpdate(ctx context.Context, params ...domain.Create
|
|||
return nil
|
||||
}
|
||||
|
||||
func (v *VillageBun) List(ctx context.Context, params domain.ListVillagesParams) ([]domain.Village, error) {
|
||||
func (v *VillageBunRepository) List(ctx context.Context, params domain.ListVillagesParams) ([]domain.Village, error) {
|
||||
var villages []bunmodel.Village
|
||||
|
||||
err := v.db.NewSelect().
|
||||
|
@ -72,7 +72,10 @@ func (v *VillageBun) List(ctx context.Context, params domain.ListVillagesParams)
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func (v *VillageBun) ListCountWithRelations(ctx context.Context, params domain.ListVillagesParams) ([]domain.VillageWithRelations, int64, error) {
|
||||
func (v *VillageBunRepository) ListCountWithRelations(
|
||||
ctx context.Context,
|
||||
params domain.ListVillagesParams,
|
||||
) ([]domain.VillageWithRelations, int64, error) {
|
||||
var villages []bunmodel.Village
|
||||
|
||||
paramsApplier := listVillagesParamsApplier{params}
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/uptrace/bun/driver/pgdriver"
|
||||
)
|
||||
|
||||
func TestVillageBun_CreateOrUpdate(t *testing.T) {
|
||||
func TestVillageBunRepository_CreateOrUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -21,7 +21,7 @@ func TestVillageBun_CreateOrUpdate(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewVillageBun(db)
|
||||
repo := adapter.NewVillageBunRepository(db)
|
||||
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
@ -129,7 +129,7 @@ func TestVillageBun_CreateOrUpdate(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestVillageBun_List_ListCountWithRelations(t *testing.T) {
|
||||
func TestVillageBunRepository_List_ListCountWithRelations(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if testing.Short() {
|
||||
|
@ -138,7 +138,7 @@ func TestVillageBun_List_ListCountWithRelations(t *testing.T) {
|
|||
|
||||
db := newBunDB(t)
|
||||
fixture := loadFixtures(t, db)
|
||||
repo := adapter.NewVillageBun(db)
|
||||
repo := adapter.NewVillageBunRepository(db)
|
||||
villages := fixture.Villages(t)
|
||||
|
||||
type expectedVillage struct {
|
|
@ -119,14 +119,14 @@ func TestUpdateData(t *testing.T) {
|
|||
|
||||
// repos
|
||||
db := newBunDB(t)
|
||||
versionRepo := adapter.NewVersionBun(db)
|
||||
serverRepo := adapter.NewServerBun(db)
|
||||
tribeRepo := adapter.NewTribeBun(db)
|
||||
playerRepo := adapter.NewPlayerBun(db)
|
||||
villageRepo := adapter.NewVillageBun(db)
|
||||
tribeChangeRepo := adapter.NewTribeChangeBun(db)
|
||||
playerSnapshotRepo := adapter.NewPlayerSnapshotBun(db)
|
||||
tribeSnapshotRepo := adapter.NewTribeSnapshotBun(db)
|
||||
versionRepo := adapter.NewVersionBunRepository(db)
|
||||
serverRepo := adapter.NewServerBunRepository(db)
|
||||
tribeRepo := adapter.NewTribeBunRepository(db)
|
||||
playerRepo := adapter.NewPlayerBunRepository(db)
|
||||
villageRepo := adapter.NewVillageBunRepository(db)
|
||||
tribeChangeRepo := adapter.NewTribeChangeBunRepository(db)
|
||||
playerSnapshotRepo := adapter.NewPlayerSnapshotBunRepository(db)
|
||||
tribeSnapshotRepo := adapter.NewTribeSnapshotBunRepository(db)
|
||||
|
||||
// services
|
||||
versionSvc := service.NewVersion(versionRepo)
|
||||
|
@ -368,9 +368,9 @@ func TestUpdateEnnoblements(t *testing.T) {
|
|||
require.NoError(t, bundbtest.NewFixture(db).Load(ctx, os.DirFS("./testdata/updateennoblements"), "fixture.yml"))
|
||||
|
||||
// repos
|
||||
versionRepo := adapter.NewVersionBun(db)
|
||||
serverRepo := adapter.NewServerBun(db)
|
||||
ennoblementRepo := adapter.NewEnnoblementBun(db)
|
||||
versionRepo := adapter.NewVersionBunRepository(db)
|
||||
serverRepo := adapter.NewServerBunRepository(db)
|
||||
ennoblementRepo := adapter.NewEnnoblementBunRepository(db)
|
||||
|
||||
// services
|
||||
versionSvc := service.NewVersion(versionRepo)
|
||||
|
@ -484,12 +484,12 @@ func TestCreateSnapshots(t *testing.T) {
|
|||
require.NoError(t, bundbtest.NewFixture(db).Load(ctx, os.DirFS("./testdata/createsnapshots"), "fixture.yml"))
|
||||
|
||||
// repos
|
||||
versionRepo := adapter.NewVersionBun(db)
|
||||
serverRepo := adapter.NewServerBun(db)
|
||||
playerRepo := adapter.NewPlayerBun(db)
|
||||
playerSnapshotRepo := adapter.NewPlayerSnapshotBun(db)
|
||||
tribeRepo := adapter.NewTribeBun(db)
|
||||
tribeSnapshotRepo := adapter.NewTribeSnapshotBun(db)
|
||||
versionRepo := adapter.NewVersionBunRepository(db)
|
||||
serverRepo := adapter.NewServerBunRepository(db)
|
||||
playerRepo := adapter.NewPlayerBunRepository(db)
|
||||
playerSnapshotRepo := adapter.NewPlayerSnapshotBunRepository(db)
|
||||
tribeRepo := adapter.NewTribeBunRepository(db)
|
||||
tribeSnapshotRepo := adapter.NewTribeSnapshotBunRepository(db)
|
||||
|
||||
// services
|
||||
versionSvc := service.NewVersion(versionRepo)
|
||||
|
|
Reference in New Issue