package services import ( "context" "tercul/internal/domain" ) type AnalyticsService interface { GetAnalytics(ctx context.Context) (*Analytics, error) } type analyticsService struct { workRepo domain.WorkRepository translationRepo domain.TranslationRepository authorRepo domain.AuthorRepository userRepo domain.UserRepository likeRepo domain.LikeRepository } func NewAnalyticsService( workRepo domain.WorkRepository, translationRepo domain.TranslationRepository, authorRepo domain.AuthorRepository, userRepo domain.UserRepository, likeRepo domain.LikeRepository, ) AnalyticsService { return &analyticsService{ workRepo: workRepo, translationRepo: translationRepo, authorRepo: authorRepo, userRepo: userRepo, likeRepo: likeRepo, } } type Analytics struct { TotalWorks int64 TotalTranslations int64 TotalAuthors int64 TotalUsers int64 TotalLikes int64 } func (s *analyticsService) GetAnalytics(ctx context.Context) (*Analytics, error) { totalWorks, err := s.workRepo.Count(ctx) if err != nil { return nil, err } totalTranslations, err := s.translationRepo.Count(ctx) if err != nil { return nil, err } totalAuthors, err := s.authorRepo.Count(ctx) if err != nil { return nil, err } totalUsers, err := s.userRepo.Count(ctx) if err != nil { return nil, err } totalLikes, err := s.likeRepo.Count(ctx) if err != nil { return nil, err } return &Analytics{ TotalWorks: totalWorks, TotalTranslations: totalTranslations, TotalAuthors: totalAuthors, TotalUsers: totalUsers, TotalLikes: totalLikes, }, nil }