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

View File

@@ -4,6 +4,7 @@ import (
"mal/internal/anime/handler" "mal/internal/anime/handler"
"mal/internal/anime/repository" "mal/internal/anime/repository"
"mal/internal/anime/service" "mal/internal/anime/service"
"mal/internal/domain"
"mal/internal/server" "mal/internal/server"
"go.uber.org/fx" "go.uber.org/fx"
@@ -12,7 +13,15 @@ import (
var Module = fx.Options( var Module = fx.Options(
fx.Provide( fx.Provide(
repository.NewAnimeRepository, repository.NewAnimeRepository,
fx.Annotate(
service.NewAnimeService, 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, handler.NewAnimeHandler,
), ),
fx.Provide( fx.Provide(

View File

@@ -29,7 +29,7 @@ func wrapAnimes(in []jikan.Anime) []domain.Anime {
return out 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} return &animeService{jikan: jikan, repo: repo}
} }