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:
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -21,13 +22,38 @@ func (h *Handler) ListSummaries(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Handler) GenerateSummary(c *gin.Context) {
|
||||
userID := c.GetString("userID")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Hour)
|
||||
defer cancel()
|
||||
summary, err := h.pipeline.GenerateForUser(ctx, userID)
|
||||
if err != nil {
|
||||
httputil.InternalError(c, err)
|
||||
if h.generationUseCase == nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"error": "generation unavailable"})
|
||||
return
|
||||
}
|
||||
httputil.Created(c, summary)
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 2*time.Hour)
|
||||
defer cancel()
|
||||
result, err := h.generationUseCase.Generate(ctx, c.GetString("userID"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "generation unavailable"})
|
||||
return
|
||||
}
|
||||
switch result.Outcome.Status {
|
||||
case "succeeded", "partial":
|
||||
c.JSON(http.StatusCreated, gin.H{"data": result})
|
||||
case "no_results":
|
||||
httputil.OK(c, result)
|
||||
case "failed":
|
||||
c.JSON(http.StatusBadGateway, gin.H{"data": result})
|
||||
default:
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "invalid generation outcome"})
|
||||
}
|
||||
}
|
||||
func (h *Handler) ListGenerations(c *gin.Context) {
|
||||
limit, err := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
||||
if err != nil || limit < 1 || limit > 50 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "limit must be between 1 and 50"})
|
||||
return
|
||||
}
|
||||
rows, err := h.repo.ListGenerations(c.Request.Context(), c.GetString("userID"), limit)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "history unavailable"})
|
||||
return
|
||||
}
|
||||
httputil.OK(c, rows)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user