feat(generation): persist summary outcomes without articles
Record generation outcomes and summaries for history while keeping article content transient. Refs #7 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
44
backend/internal/generation/repository.go
Normal file
44
backend/internal/generation/repository.go
Normal file
@ -0,0 +1,44 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type RepositoryAdapter struct{ Repo *models.Repository }
|
||||
|
||||
func (r RepositoryAdapter) LoadUserInput(ctx context.Context, id string) (UserInput, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return UserInput{}, err
|
||||
}
|
||||
p, err := r.Repo.GetUserPreferences(id)
|
||||
if err != nil {
|
||||
return UserInput{}, err
|
||||
}
|
||||
assets, err := r.Repo.GetUserAssets(id)
|
||||
if err != nil {
|
||||
return UserInput{}, err
|
||||
}
|
||||
sources, err := r.Repo.ListSources()
|
||||
if err != nil {
|
||||
return UserInput{}, err
|
||||
}
|
||||
value, err := r.Repo.GetSetting("summary_max_articles")
|
||||
if err != nil {
|
||||
return UserInput{}, err
|
||||
}
|
||||
limit, _ := strconv.Atoi(value)
|
||||
if value == "" {
|
||||
limit = 50
|
||||
}
|
||||
return UserInput{Language: p.Language, RankingMode: p.RankingMode, GlobalLimit: limit, Assets: assets, Sources: sources}, nil
|
||||
}
|
||||
func (r RepositoryAdapter) SaveGeneration(ctx context.Context, id string, record GenerationRecord) error {
|
||||
payload, err := json.Marshal(record.Outcome)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return r.Repo.SaveGeneration(ctx, id, record.Outcome.ID, record.Summary, payload, record.Outcome.CreatedAt)
|
||||
}
|
||||
Reference in New Issue
Block a user