35 lines
871 B
Go
35 lines
871 B
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dwysokinski.me/twhelp/corev3/internal/domain"
|
|
)
|
|
|
|
type TribeRepository interface {
|
|
CreateOrUpdate(ctx context.Context, params ...domain.CreateTribeParams) error
|
|
List(ctx context.Context, params domain.ListTribesParams) (domain.Tribes, error)
|
|
Delete(ctx context.Context, serverKey string, ids ...int) error
|
|
}
|
|
|
|
type TribeService struct {
|
|
repo TribeRepository
|
|
twSvc TWService
|
|
}
|
|
|
|
func NewTribeService(repo TribeRepository, twSvc TWService) *TribeService {
|
|
return &TribeService{repo: repo, twSvc: twSvc}
|
|
}
|
|
|
|
func (svc *TribeService) Sync(ctx context.Context, payload domain.ServerSyncedEventPayload) error {
|
|
tribes, err := svc.twSvc.GetTribes(ctx, payload.URL())
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't get tribes for server %s: %w", payload.Key(), err)
|
|
}
|
|
|
|
fmt.Println(payload.URL(), len(tribes))
|
|
|
|
return nil
|
|
}
|