tercul-backend/internal/domain/analytics.go
google-labs-jules[bot] f8b3ecb9bd feat: Implement trending works feature
This commit introduces a new trending works feature to the application.

The feature includes:
- A new `Trending` domain model to store ranked works.
- An `UpdateTrending` method in the `AnalyticsService` that calculates a trending score for each work based on views, likes, and comments.
- A background job that runs hourly to update the trending works.
- A new `trendingWorks` query in the GraphQL API to expose the trending works.
- New tests for the trending feature, and fixes for existing tests.

This commit also includes a refactoring of the analytics repository to use a more generic `IncrementWorkCounter` method, and enhancements to the `WorkStats` and `TranslationStats` models with new metrics like `readingTime`, `complexity`, and `sentiment`.
2025-09-07 20:40:35 +00:00

19 lines
976 B
Go

package domain
import "context"
import "time"
type AnalyticsRepository interface {
IncrementWorkCounter(ctx context.Context, workID uint, field string, value int) error
IncrementTranslationCounter(ctx context.Context, translationID uint, field string, value int) error
UpdateWorkStats(ctx context.Context, workID uint, stats WorkStats) error
UpdateTranslationStats(ctx context.Context, translationID uint, stats TranslationStats) error
GetOrCreateWorkStats(ctx context.Context, workID uint) (*WorkStats, error)
GetOrCreateTranslationStats(ctx context.Context, translationID uint) (*TranslationStats, error)
GetOrCreateUserEngagement(ctx context.Context, userID uint, date time.Time) (*UserEngagement, error)
UpdateUserEngagement(ctx context.Context, userEngagement *UserEngagement) error
UpdateTrendingWorks(ctx context.Context, timePeriod string, trending []*Trending) error
GetTrendingWorks(ctx context.Context, timePeriod string, limit int) ([]*Work, error)
}