feat: recognition job context, diary linkage, worker improvements

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-19 22:22:44 +02:00
parent cf69a4a3d9
commit 9357c194eb
5 changed files with 130 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ type DishRepository interface {
FindOrCreate(ctx context.Context, name string) (string, bool, error)
FindOrCreateRecipe(ctx context.Context, dishID string, calories, proteinG, fatG, carbsG float64) (string, bool, error)
UpsertTranslation(ctx context.Context, dishID, lang, name string) error
GetTranslation(ctx context.Context, dishID, lang string) (string, bool, error)
AddRecipe(ctx context.Context, dishID string, req dish.CreateRequest) (string, error)
}
@@ -249,6 +250,23 @@ func (handler *Handler) ListTodayJobs(responseWriter http.ResponseWriter, reques
writeJSON(responseWriter, http.StatusOK, summaries)
}
// ListAllJobs handles GET /ai/jobs/history — returns all recognition jobs for the current user.
func (handler *Handler) ListAllJobs(responseWriter http.ResponseWriter, request *http.Request) {
userID := middleware.UserIDFromCtx(request.Context())
summaries, listError := handler.jobRepo.ListAll(request.Context(), userID)
if listError != nil {
slog.Error("list all jobs", "err", listError)
writeErrorJSON(responseWriter, http.StatusInternalServerError, "failed to list jobs")
return
}
if summaries == nil {
summaries = []*JobSummary{}
}
writeJSON(responseWriter, http.StatusOK, summaries)
}
// GetJobStream handles GET /ai/jobs/{id}/stream — SSE endpoint for job updates.
func (handler *Handler) GetJobStream(responseWriter http.ResponseWriter, request *http.Request) {
handler.sseBroker.ServeSSE(responseWriter, request)