mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
71 lines
2.4 KiB
Go
71 lines
2.4 KiB
Go
package copyright
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// CopyrightQueries contains the query handlers for copyright.
|
|
type CopyrightQueries struct {
|
|
repo domain.CopyrightRepository
|
|
}
|
|
|
|
// NewCopyrightQueries creates a new CopyrightQueries handler.
|
|
func NewCopyrightQueries(repo domain.CopyrightRepository) *CopyrightQueries {
|
|
return &CopyrightQueries{repo: repo}
|
|
}
|
|
|
|
// GetCopyrightByID retrieves a copyright by ID.
|
|
func (q *CopyrightQueries) GetCopyrightByID(ctx context.Context, id uint) (*domain.Copyright, error) {
|
|
if id == 0 {
|
|
return nil, errors.New("invalid copyright ID")
|
|
}
|
|
return q.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// ListCopyrights retrieves all copyrights.
|
|
func (q *CopyrightQueries) ListCopyrights(ctx context.Context) ([]domain.Copyright, error) {
|
|
// Note: This might need pagination in the future.
|
|
// For now, it mirrors the old service's behavior.
|
|
return q.repo.ListAll(ctx)
|
|
}
|
|
|
|
// GetCopyrightsForEntity gets all copyrights for a specific entity.
|
|
func (q *CopyrightQueries) GetCopyrightsForEntity(ctx context.Context, entityID uint, entityType string) ([]domain.Copyright, error) {
|
|
if entityID == 0 {
|
|
return nil, errors.New("invalid entity ID")
|
|
}
|
|
if entityType == "" {
|
|
return nil, errors.New("entity type cannot be empty")
|
|
}
|
|
return q.repo.GetByEntity(ctx, entityID, entityType)
|
|
}
|
|
|
|
// GetEntitiesByCopyright gets all entities that have a specific copyright.
|
|
func (q *CopyrightQueries) GetEntitiesByCopyright(ctx context.Context, copyrightID uint) ([]domain.Copyrightable, error) {
|
|
if copyrightID == 0 {
|
|
return nil, errors.New("invalid copyright ID")
|
|
}
|
|
return q.repo.GetEntitiesByCopyright(ctx, copyrightID)
|
|
}
|
|
|
|
// GetTranslations gets all translations for a copyright.
|
|
func (q *CopyrightQueries) GetTranslations(ctx context.Context, copyrightID uint) ([]domain.CopyrightTranslation, error) {
|
|
if copyrightID == 0 {
|
|
return nil, errors.New("invalid copyright ID")
|
|
}
|
|
return q.repo.GetTranslations(ctx, copyrightID)
|
|
}
|
|
|
|
// GetTranslationByLanguage gets a specific translation by language code.
|
|
func (q *CopyrightQueries) GetTranslationByLanguage(ctx context.Context, copyrightID uint, languageCode string) (*domain.CopyrightTranslation, error) {
|
|
if copyrightID == 0 {
|
|
return nil, errors.New("invalid copyright ID")
|
|
}
|
|
if languageCode == "" {
|
|
return nil, errors.New("language code cannot be empty")
|
|
}
|
|
return q.repo.GetTranslationByLanguage(ctx, copyrightID, languageCode)
|
|
}
|