Backend: - Rename recognition_jobs → dish_recognition_jobs; add target_date and target_meal_type columns to capture scan context at submission time - Add job_id FK on meal_diary so entries are linked to their origin job - New GET /ai/jobs endpoint returns today's unlinked jobs for the current user - diary.Entry and CreateRequest gain job_id field; repository reads/writes it - CORS middleware: allow Accept-Language and Cache-Control headers - Logging middleware: implement http.Flusher on responseWriter (needed for SSE) - Consolidate migrations into a single 001_initial_schema.sql Flutter: - POST /ai/recognize-dish now sends target_date and target_meal_type - DishResultSheet accepts jobId; _addToDiary includes it in the diary payload, saves last-used meal type to SharedPreferences, invalidates todayJobsProvider - TodayJobsNotifier + todayJobsProvider: loads unlinked jobs via GET /ai/jobs - Home screen shows _TodayJobsWidget (up to 3 tiles) between macros and meals; tapping a done tile reopens DishResultSheet with the stored result - Quick Actions row: third button "История" → /scan/history - New RecognitionHistoryScreen: full-screen list of today's unlinked jobs - LocalPreferences wrapper over SharedPreferences (last_used_meal_type) - app_theme: apply Google Fonts Roboto as default font family Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package recognition
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/food-ai/backend/internal/adapters/ai"
|
|
)
|
|
|
|
// Job status constants.
|
|
const (
|
|
JobStatusPending = "pending"
|
|
JobStatusProcessing = "processing"
|
|
JobStatusDone = "done"
|
|
JobStatusFailed = "failed"
|
|
)
|
|
|
|
// Kafka topic names.
|
|
const (
|
|
TopicPaid = "ai.recognize.paid"
|
|
TopicFree = "ai.recognize.free"
|
|
)
|
|
|
|
// Job represents an async dish recognition task stored in dish_recognition_jobs.
|
|
type Job struct {
|
|
ID string
|
|
UserID string
|
|
UserPlan string
|
|
ImageBase64 string
|
|
MimeType string
|
|
Lang string
|
|
TargetDate *string // nullable YYYY-MM-DD
|
|
TargetMealType *string // nullable e.g. "lunch"
|
|
Status string
|
|
Result *ai.DishResult
|
|
Error *string
|
|
CreatedAt time.Time
|
|
StartedAt *time.Time
|
|
CompletedAt *time.Time
|
|
}
|
|
|
|
// JobSummary is a lightweight job record for list endpoints (omits ImageBase64).
|
|
type JobSummary struct {
|
|
ID string `json:"id"`
|
|
Status string `json:"status"`
|
|
TargetDate *string `json:"target_date,omitempty"`
|
|
TargetMealType *string `json:"target_meal_type,omitempty"`
|
|
Result *ai.DishResult `json:"result,omitempty"`
|
|
Error *string `json:"error,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|