refactor: wire anime handler to use new service interfaces via fx

This commit is contained in:
2026-05-28 12:12:00 +02:00
parent 794eb8da27
commit 3e67602e92
3 changed files with 20 additions and 4 deletions

View File

@@ -20,13 +20,20 @@ import (
)
type AnimeHandler struct {
svc domain.AnimeService
svc Service
watchlistSvc domain.WatchlistService
scheduleCacheMu sync.Mutex
scheduleCache map[string]cachedWeekSchedule
}
type Service interface {
domain.AnimeCatalogService
domain.AnimeDiscoverService
domain.AnimeSearchService
domain.AnimeDetailsService
}
type cachedWeekSchedule struct {
fetchedAt time.Time
value animeschedule.WeekSchedule
@@ -40,7 +47,7 @@ func wrapAnimes(in []jikan.Anime) []domain.Anime {
return out
}
func NewAnimeHandler(svc domain.AnimeService, watchlistSvc domain.WatchlistService) *AnimeHandler {
func NewAnimeHandler(svc Service, watchlistSvc domain.WatchlistService) *AnimeHandler {
return &AnimeHandler{
svc: svc,
watchlistSvc: watchlistSvc,

View File

@@ -4,6 +4,7 @@ import (
"mal/internal/anime/handler"
"mal/internal/anime/repository"
"mal/internal/anime/service"
"mal/internal/domain"
"mal/internal/server"
"go.uber.org/fx"
@@ -12,7 +13,15 @@ import (
var Module = fx.Options(
fx.Provide(
repository.NewAnimeRepository,
service.NewAnimeService,
fx.Annotate(
service.NewAnimeService,
fx.As(new(handler.Service)),
fx.As(new(domain.AnimeCatalogService)),
fx.As(new(domain.AnimeDiscoverService)),
fx.As(new(domain.AnimeSearchService)),
fx.As(new(domain.AnimeDetailsService)),
fx.As(new(domain.AnimePlaybackService)),
),
handler.NewAnimeHandler,
),
fx.Provide(

View File

@@ -29,7 +29,7 @@ func wrapAnimes(in []jikan.Anime) []domain.Anime {
return out
}
func NewAnimeService(jikan *jikan.Client, repo domain.AnimeRepository) domain.AnimeService {
func NewAnimeService(jikan *jikan.Client, repo domain.AnimeRepository) *animeService {
return &animeService{jikan: jikan, repo: repo}
}