Rotation check: tried dinners and keep/drop decisions (#116)
CI / ci (push) Failing after 5s
CI / ci (push) Failing after 5s
Co-authored-by: orchestrator-agent <20+orchestrator-agent@code.cubecraftcreations.com>
This commit was merged in pull request #116.
This commit is contained in:
@@ -52,20 +52,26 @@ func (q *Queries) ListPlannedDinners(ctx context.Context, arg ListPlannedDinners
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listRecentDeclinedNames = `-- name: ListRecentDeclinedNames :many
|
||||
const listRecentPassedNames = `-- name: ListRecentPassedNames :many
|
||||
|
||||
SELECT name
|
||||
FROM suggestions
|
||||
WHERE status = 'declined'
|
||||
SELECT name FROM (
|
||||
SELECT name, decided_at, id
|
||||
FROM suggestions
|
||||
WHERE status = 'declined'
|
||||
UNION ALL
|
||||
SELECT name, decided_at, id
|
||||
FROM rotation_reviews
|
||||
WHERE decision = 'drop'
|
||||
)
|
||||
ORDER BY decided_at DESC, id DESC
|
||||
LIMIT ?
|
||||
`
|
||||
|
||||
// Reads for the AI household context block (internal/ai/harness).
|
||||
// The names the most recently declined suggestions were suggested under,
|
||||
// newest first; renaming their dinners does not change them.
|
||||
func (q *Queries) ListRecentDeclinedNames(ctx context.Context, limit int64) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listRecentDeclinedNames, limit)
|
||||
// The most recent names the household turned down, newest first, as
|
||||
// ListPassedNames has them.
|
||||
func (q *Queries) ListRecentPassedNames(ctx context.Context, limit int64) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listRecentPassedNames, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -228,6 +228,7 @@ type RotationReview struct {
|
||||
PlanDate string
|
||||
Status string
|
||||
Decision sql.NullString
|
||||
Name sql.NullString
|
||||
DecidedAt sql.NullString
|
||||
UpdatedBy sql.NullString
|
||||
CreatedAt string
|
||||
|
||||
+32
-6
@@ -25,6 +25,8 @@ type Querier interface {
|
||||
CountDeck(ctx context.Context) (int64, error)
|
||||
// How many Regulars the household has; archived dinners are not counted.
|
||||
CountRegularDinners(ctx context.Context) (int64, error)
|
||||
// How many Rotation checks dinner_id has had, pending or decided.
|
||||
CountRotationReviews(ctx context.Context, dinnerID string) (int64, error)
|
||||
CreateAIRun(ctx context.Context, arg CreateAIRunParams) error
|
||||
CreateDinner(ctx context.Context, arg CreateDinnerParams) (Dinner, error)
|
||||
CreateJob(ctx context.Context, arg CreateJobParams) error
|
||||
@@ -34,11 +36,16 @@ type Querier interface {
|
||||
CreatePhoto(ctx context.Context, arg CreatePhotoParams) (Photo, error)
|
||||
CreateRecipeIngredient(ctx context.Context, arg CreateRecipeIngredientParams) error
|
||||
CreateRecipeStep(ctx context.Context, arg CreateRecipeStepParams) error
|
||||
CreateRotationReview(ctx context.Context, arg CreateRotationReviewParams) error
|
||||
// name is the name the dish is suggested under, kept whatever its dinner is
|
||||
// later renamed.
|
||||
CreateSuggestion(ctx context.Context, arg CreateSuggestionParams) error
|
||||
CreateSuggestionBatch(ctx context.Context, arg CreateSuggestionBatchParams) (SuggestionBatch, error)
|
||||
CreateWeekPlan(ctx context.Context, arg CreateWeekPlanParams) error
|
||||
// Records the household's decision on a pending Rotation check, with the
|
||||
// dinner's name for a drop and NULL otherwise; one already decided is left
|
||||
// as it is (0 rows).
|
||||
DecideRotationReview(ctx context.Context, arg DecideRotationReviewParams) (int64, error)
|
||||
// Records the household's decision on a pending suggestion; one already
|
||||
// decided is left as it is (0 rows).
|
||||
DecideSuggestion(ctx context.Context, arg DecideSuggestionParams) (int64, error)
|
||||
@@ -87,6 +94,10 @@ type Querier interface {
|
||||
// The newest batch, whatever its status. Returns sql.ErrNoRows when there
|
||||
// is none.
|
||||
GetLatestSuggestionBatch(ctx context.Context) (SuggestionBatch, error)
|
||||
// The pending Rotation check of dinner_id. MarkTried makes one only for a
|
||||
// dinner in the Quest log, which it moves to tried, so a dinner has at
|
||||
// most one. Returns sql.ErrNoRows when there is none.
|
||||
GetPendingRotationReview(ctx context.Context, dinnerID string) (RotationReview, error)
|
||||
GetPhoto(ctx context.Context, id string) (Photo, error)
|
||||
// Finds stored image bytes by content hash. The schema does not make sha256
|
||||
// unique, so the earliest-created (lowest id) match is returned.
|
||||
@@ -121,14 +132,19 @@ type Querier interface {
|
||||
// The pending suggestions whose dinner is still suggested, oldest first,
|
||||
// with their dinners.
|
||||
ListDeck(ctx context.Context) ([]ListDeckRow, error)
|
||||
// The name every declined suggestion was suggested under, oldest decision
|
||||
// first; renaming its dinner does not change it.
|
||||
ListDeclinedSuggestionNames(ctx context.Context) ([]string, error)
|
||||
ListDinnersByStatus(ctx context.Context, status string) ([]Dinner, error)
|
||||
// The dinners a draft of the week starting week_start may plan: every
|
||||
// Regular, and every Quest log dinner no other plan for the week starting
|
||||
// from_week_start or later has on any day.
|
||||
ListDraftPool(ctx context.Context, arg ListDraftPoolParams) ([]Dinner, error)
|
||||
// Every name the household turned down, oldest decision first: the name
|
||||
// each declined suggestion was suggested under, which renaming its dinner
|
||||
// does not change, and the name each dinner a Rotation check dropped
|
||||
// ("Not for us") had when dropped, which renaming it does not change.
|
||||
ListPassedNames(ctx context.Context) ([]string, error)
|
||||
// The pending Rotation checks whose dinner is still tried, oldest plan
|
||||
// date first, with their dinners.
|
||||
ListPendingRotationReviews(ctx context.Context) ([]ListPendingRotationReviewsRow, error)
|
||||
// The days of plan plan_id with their dinners, Monday first. A day with
|
||||
// no dinner is left out.
|
||||
ListPlanDays(ctx context.Context, planID string) ([]ListPlanDaysRow, error)
|
||||
@@ -136,11 +152,14 @@ type Querier interface {
|
||||
// to_date, oldest first. Days with no dinner are left out.
|
||||
ListPlannedDinners(ctx context.Context, arg ListPlannedDinnersParams) ([]ListPlannedDinnersRow, error)
|
||||
// Reads for the AI household context block (internal/ai/harness).
|
||||
// The names the most recently declined suggestions were suggested under,
|
||||
// newest first; renaming their dinners does not change them.
|
||||
ListRecentDeclinedNames(ctx context.Context, limit int64) ([]string, error)
|
||||
// The most recent names the household turned down, newest first, as
|
||||
// ListPassedNames has them.
|
||||
ListRecentPassedNames(ctx context.Context, limit int64) ([]string, error)
|
||||
ListRecipeIngredients(ctx context.Context, recipeID string) ([]RecipeIngredient, error)
|
||||
ListRecipeSteps(ctx context.Context, recipeID string) ([]RecipeStep, error)
|
||||
// The ids of the dinners with status quest_log planned on date, on a plan
|
||||
// of any status, that have no Rotation check for date yet.
|
||||
ListTriedCandidates(ctx context.Context, date string) ([]string, error)
|
||||
// Every dinner a new or renamed dinner must not repeat, with the
|
||||
// source_url of the recipe it is grounded in (NULL while it has none).
|
||||
ListUnarchivedDinners(ctx context.Context) ([]ListUnarchivedDinnersRow, error)
|
||||
@@ -150,6 +169,9 @@ type Querier interface {
|
||||
// The ids of the dinners planned in the week starting week_start, Monday
|
||||
// first.
|
||||
ListWeekPlanDinnerIDs(ctx context.Context, weekStart string) ([]sql.NullString, error)
|
||||
// Moves a dinner still in the Quest log to tried; a dinner with any other
|
||||
// status is left as it is (0 rows).
|
||||
MarkDinnerTried(ctx context.Context, arg MarkDinnerTriedParams) (int64, error)
|
||||
// Records an edit of plan id, raising its revision: a synced plan becomes
|
||||
// changed, any other keeps its status.
|
||||
MarkWeekPlanEdited(ctx context.Context, arg MarkWeekPlanEditedParams) error
|
||||
@@ -157,6 +179,10 @@ type Querier interface {
|
||||
// recording updated_by; a dinner no longer suggested is left as it is
|
||||
// (0 rows).
|
||||
MoveSuggestedDinner(ctx context.Context, arg MoveSuggestedDinnerParams) (int64, error)
|
||||
// Moves a dinner still tried to status (regular, archived or quest_log)
|
||||
// by a Rotation check decision, recording updated_by; its origin is kept.
|
||||
// A dinner no longer tried is left as it is (0 rows).
|
||||
MoveTriedDinner(ctx context.Context, arg MoveTriedDinnerParams) (int64, error)
|
||||
// Stores a partial result of a running job.
|
||||
PublishJobResult(ctx context.Context, arg PublishJobResultParams) (int64, error)
|
||||
// Plans dinner_id on date of plan_id, keeping the day's calendar event id
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: rotation_reviews.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const countRotationReviews = `-- name: CountRotationReviews :one
|
||||
SELECT COUNT(*) FROM rotation_reviews WHERE dinner_id = ?
|
||||
`
|
||||
|
||||
// How many Rotation checks dinner_id has had, pending or decided.
|
||||
func (q *Queries) CountRotationReviews(ctx context.Context, dinnerID string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, countRotationReviews, dinnerID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const createRotationReview = `-- name: CreateRotationReview :exec
|
||||
INSERT INTO rotation_reviews (id, dinner_id, plan_date, status, created_at, updated_at)
|
||||
VALUES (?, ?, ?, 'pending', ?, ?)
|
||||
`
|
||||
|
||||
type CreateRotationReviewParams struct {
|
||||
ID string
|
||||
DinnerID string
|
||||
PlanDate string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
}
|
||||
|
||||
func (q *Queries) CreateRotationReview(ctx context.Context, arg CreateRotationReviewParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createRotationReview,
|
||||
arg.ID,
|
||||
arg.DinnerID,
|
||||
arg.PlanDate,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const decideRotationReview = `-- name: DecideRotationReview :execrows
|
||||
UPDATE rotation_reviews
|
||||
SET status = 'decided',
|
||||
decision = ?1,
|
||||
name = ?2,
|
||||
decided_at = ?3,
|
||||
updated_by = ?4,
|
||||
updated_at = ?3
|
||||
WHERE id = ?5 AND status = 'pending'
|
||||
`
|
||||
|
||||
type DecideRotationReviewParams struct {
|
||||
Decision sql.NullString
|
||||
Name sql.NullString
|
||||
Now sql.NullString
|
||||
UpdatedBy sql.NullString
|
||||
ID string
|
||||
}
|
||||
|
||||
// Records the household's decision on a pending Rotation check, with the
|
||||
// dinner's name for a drop and NULL otherwise; one already decided is left
|
||||
// as it is (0 rows).
|
||||
func (q *Queries) DecideRotationReview(ctx context.Context, arg DecideRotationReviewParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, decideRotationReview,
|
||||
arg.Decision,
|
||||
arg.Name,
|
||||
arg.Now,
|
||||
arg.UpdatedBy,
|
||||
arg.ID,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const getPendingRotationReview = `-- name: GetPendingRotationReview :one
|
||||
SELECT id, dinner_id, plan_date, status, decision, name, decided_at, updated_by, created_at, updated_at FROM rotation_reviews
|
||||
WHERE dinner_id = ? AND status = 'pending'
|
||||
`
|
||||
|
||||
// The pending Rotation check of dinner_id. MarkTried makes one only for a
|
||||
// dinner in the Quest log, which it moves to tried, so a dinner has at
|
||||
// most one. Returns sql.ErrNoRows when there is none.
|
||||
func (q *Queries) GetPendingRotationReview(ctx context.Context, dinnerID string) (RotationReview, error) {
|
||||
row := q.db.QueryRowContext(ctx, getPendingRotationReview, dinnerID)
|
||||
var i RotationReview
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.DinnerID,
|
||||
&i.PlanDate,
|
||||
&i.Status,
|
||||
&i.Decision,
|
||||
&i.Name,
|
||||
&i.DecidedAt,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listPendingRotationReviews = `-- name: ListPendingRotationReviews :many
|
||||
SELECT rotation_reviews.plan_date, dinners.id, dinners.name, dinners.normalized_name, dinners.status, dinners.origin, dinners.method, dinners.minutes_total, dinners.difficulty, dinners.cuisine, dinners.is_favorite, dinners.recipe_id, dinners.photo_id, dinners.grounding_status, dinners.updated_by, dinners.created_at, dinners.updated_at, dinners.recipe_url, dinners.grounding_error, dinners.grounding_revision
|
||||
FROM rotation_reviews
|
||||
JOIN dinners ON dinners.id = rotation_reviews.dinner_id
|
||||
WHERE rotation_reviews.status = 'pending' AND dinners.status = 'tried'
|
||||
ORDER BY rotation_reviews.plan_date, rotation_reviews.id
|
||||
`
|
||||
|
||||
type ListPendingRotationReviewsRow struct {
|
||||
PlanDate string
|
||||
Dinner Dinner
|
||||
}
|
||||
|
||||
// The pending Rotation checks whose dinner is still tried, oldest plan
|
||||
// date first, with their dinners.
|
||||
func (q *Queries) ListPendingRotationReviews(ctx context.Context) ([]ListPendingRotationReviewsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listPendingRotationReviews)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListPendingRotationReviewsRow
|
||||
for rows.Next() {
|
||||
var i ListPendingRotationReviewsRow
|
||||
if err := rows.Scan(
|
||||
&i.PlanDate,
|
||||
&i.Dinner.ID,
|
||||
&i.Dinner.Name,
|
||||
&i.Dinner.NormalizedName,
|
||||
&i.Dinner.Status,
|
||||
&i.Dinner.Origin,
|
||||
&i.Dinner.Method,
|
||||
&i.Dinner.MinutesTotal,
|
||||
&i.Dinner.Difficulty,
|
||||
&i.Dinner.Cuisine,
|
||||
&i.Dinner.IsFavorite,
|
||||
&i.Dinner.RecipeID,
|
||||
&i.Dinner.PhotoID,
|
||||
&i.Dinner.GroundingStatus,
|
||||
&i.Dinner.UpdatedBy,
|
||||
&i.Dinner.CreatedAt,
|
||||
&i.Dinner.UpdatedAt,
|
||||
&i.Dinner.RecipeUrl,
|
||||
&i.Dinner.GroundingError,
|
||||
&i.Dinner.GroundingRevision,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTriedCandidates = `-- name: ListTriedCandidates :many
|
||||
SELECT DISTINCT dinners.id
|
||||
FROM plan_days
|
||||
JOIN dinners ON dinners.id = plan_days.dinner_id
|
||||
WHERE plan_days.date = ?1
|
||||
AND dinners.status = 'quest_log'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM rotation_reviews
|
||||
WHERE rotation_reviews.dinner_id = dinners.id
|
||||
AND rotation_reviews.plan_date = plan_days.date
|
||||
)
|
||||
ORDER BY dinners.id
|
||||
`
|
||||
|
||||
// The ids of the dinners with status quest_log planned on date, on a plan
|
||||
// of any status, that have no Rotation check for date yet.
|
||||
func (q *Queries) ListTriedCandidates(ctx context.Context, date string) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listTriedCandidates, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, id)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const markDinnerTried = `-- name: MarkDinnerTried :execrows
|
||||
UPDATE dinners
|
||||
SET status = 'tried', updated_at = ?
|
||||
WHERE id = ? AND status = 'quest_log'
|
||||
`
|
||||
|
||||
type MarkDinnerTriedParams struct {
|
||||
UpdatedAt string
|
||||
ID string
|
||||
}
|
||||
|
||||
// Moves a dinner still in the Quest log to tried; a dinner with any other
|
||||
// status is left as it is (0 rows).
|
||||
func (q *Queries) MarkDinnerTried(ctx context.Context, arg MarkDinnerTriedParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, markDinnerTried, arg.UpdatedAt, arg.ID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
|
||||
const moveTriedDinner = `-- name: MoveTriedDinner :execrows
|
||||
UPDATE dinners
|
||||
SET status = ?1, updated_by = ?2, updated_at = ?3
|
||||
WHERE id = ?4 AND status = 'tried'
|
||||
`
|
||||
|
||||
type MoveTriedDinnerParams struct {
|
||||
Status string
|
||||
UpdatedBy sql.NullString
|
||||
UpdatedAt string
|
||||
ID string
|
||||
}
|
||||
|
||||
// Moves a dinner still tried to status (regular, archived or quest_log)
|
||||
// by a Rotation check decision, recording updated_by; its origin is kept.
|
||||
// A dinner no longer tried is left as it is (0 rows).
|
||||
func (q *Queries) MoveTriedDinner(ctx context.Context, arg MoveTriedDinnerParams) (int64, error) {
|
||||
result, err := q.db.ExecContext(ctx, moveTriedDinner,
|
||||
arg.Status,
|
||||
arg.UpdatedBy,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected()
|
||||
}
|
||||
@@ -348,17 +348,25 @@ func (q *Queries) ListDeck(ctx context.Context) ([]ListDeckRow, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listDeclinedSuggestionNames = `-- name: ListDeclinedSuggestionNames :many
|
||||
SELECT name
|
||||
FROM suggestions
|
||||
WHERE status = 'declined'
|
||||
const listPassedNames = `-- name: ListPassedNames :many
|
||||
SELECT name FROM (
|
||||
SELECT name, decided_at, id
|
||||
FROM suggestions
|
||||
WHERE status = 'declined'
|
||||
UNION ALL
|
||||
SELECT name, decided_at, id
|
||||
FROM rotation_reviews
|
||||
WHERE decision = 'drop'
|
||||
)
|
||||
ORDER BY decided_at, id
|
||||
`
|
||||
|
||||
// The name every declined suggestion was suggested under, oldest decision
|
||||
// first; renaming its dinner does not change it.
|
||||
func (q *Queries) ListDeclinedSuggestionNames(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listDeclinedSuggestionNames)
|
||||
// Every name the household turned down, oldest decision first: the name
|
||||
// each declined suggestion was suggested under, which renaming its dinner
|
||||
// does not change, and the name each dinner a Rotation check dropped
|
||||
// ("Not for us") had when dropped, which renaming it does not change.
|
||||
func (q *Queries) ListPassedNames(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listPassedNames)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user