mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package work
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// WorkAnalytics contains analytics data for a work
|
|
type WorkAnalytics struct {
|
|
WorkID uint
|
|
ViewCount int64
|
|
LikeCount int64
|
|
CommentCount int64
|
|
BookmarkCount int64
|
|
TranslationCount int64
|
|
ReadabilityScore float64
|
|
SentimentScore float64
|
|
TopKeywords []string
|
|
PopularTranslations []TranslationAnalytics
|
|
}
|
|
|
|
// TranslationAnalytics contains analytics data for a translation
|
|
type TranslationAnalytics struct {
|
|
TranslationID uint
|
|
Language string
|
|
ViewCount int64
|
|
LikeCount int64
|
|
}
|
|
|
|
// WorkQueries contains the query handlers for the work aggregate.
|
|
type WorkQueries struct {
|
|
repo domain.WorkRepository
|
|
}
|
|
|
|
// NewWorkQueries creates a new WorkQueries handler.
|
|
func NewWorkQueries(repo domain.WorkRepository) *WorkQueries {
|
|
return &WorkQueries{
|
|
repo: repo,
|
|
}
|
|
}
|
|
|
|
// GetWorkByID retrieves a work by ID.
|
|
func (q *WorkQueries) GetWorkByID(ctx context.Context, id uint) (*domain.Work, error) {
|
|
if id == 0 {
|
|
return nil, errors.New("invalid work ID")
|
|
}
|
|
return q.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// ListWorks returns a paginated list of works.
|
|
func (q *WorkQueries) ListWorks(ctx context.Context, page, pageSize int) (*domain.PaginatedResult[domain.Work], error) {
|
|
return q.repo.List(ctx, page, pageSize)
|
|
}
|
|
|
|
// GetWorkWithTranslations retrieves a work with its translations.
|
|
func (q *WorkQueries) GetWorkWithTranslations(ctx context.Context, id uint) (*domain.Work, error) {
|
|
if id == 0 {
|
|
return nil, errors.New("invalid work ID")
|
|
}
|
|
return q.repo.GetWithTranslations(ctx, id)
|
|
}
|
|
|
|
// FindWorksByTitle finds works by title.
|
|
func (q *WorkQueries) FindWorksByTitle(ctx context.Context, title string) ([]domain.Work, error) {
|
|
if title == "" {
|
|
return nil, errors.New("title cannot be empty")
|
|
}
|
|
return q.repo.FindByTitle(ctx, title)
|
|
}
|
|
|
|
// FindWorksByAuthor finds works by author ID.
|
|
func (q *WorkQueries) FindWorksByAuthor(ctx context.Context, authorID uint) ([]domain.Work, error) {
|
|
if authorID == 0 {
|
|
return nil, errors.New("invalid author ID")
|
|
}
|
|
return q.repo.FindByAuthor(ctx, authorID)
|
|
}
|
|
|
|
// FindWorksByCategory finds works by category ID.
|
|
func (q *WorkQueries) FindWorksByCategory(ctx context.Context, categoryID uint) ([]domain.Work, error) {
|
|
if categoryID == 0 {
|
|
return nil, errors.New("invalid category ID")
|
|
}
|
|
return q.repo.FindByCategory(ctx, categoryID)
|
|
}
|
|
|
|
// FindWorksByLanguage finds works by language.
|
|
func (q *WorkQueries) FindWorksByLanguage(ctx context.Context, language string, page, pageSize int) (*domain.PaginatedResult[domain.Work], error) {
|
|
if language == "" {
|
|
return nil, errors.New("language cannot be empty")
|
|
}
|
|
return q.repo.FindByLanguage(ctx, language, page, pageSize)
|
|
}
|