Build image / build-and-push (push) Successful in 7s
Fixes from the PR #28 adversarial review (considered; not graded). Correctness / API - PATCH /objects/:id can now clear nullable color/props back to NULL: the request takes them as json.RawMessage, and ObjectPatch carries an explicit Set flag so an explicit `null` (clear) is distinguished from an absent field (unchanged) — the strongest cross-model finding (6 hits). New test. Maintainability - store/plantings.go + plants.go use explicit qualified column lists (qualifyColumns helper) instead of SELECT *, matching gardens/objects and surviving a future column add. - Consolidated objectKinds + plantableByDefault into one kind→traits map. - objectForRole factors the fetch-then-authorize shared by UpdateObject and DeleteObject; dropped the redundant kind check in CreateObject (finalizeObject is the single validation point). - Request→service mapping via toInput()/toPatch() methods (matches gardens). - Renamed handler gardenFull → getGardenFull (verbNoun); test helper decodeGarden → decodeMap; generic bind-error messages. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JdQpdYYsTgtkJBxbcpAszi
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.stevedudenhoeffer.com/steve/pansy/internal/domain"
|
|
)
|
|
|
|
// plantingColumns lists plantings columns in the order scanPlanting expects.
|
|
// Used unqualified for direct selects; the /full read below qualifies with pl.
|
|
const plantingColumns = `id, object_id, plant_id, x_cm, y_cm, radius_cm, count, label,
|
|
planted_at, removed_at, version, created_at, updated_at`
|
|
|
|
func scanPlanting(s scanner) (*domain.Planting, error) {
|
|
var p domain.Planting
|
|
if err := s.Scan(
|
|
&p.ID, &p.ObjectID, &p.PlantID, &p.XCM, &p.YCM, &p.RadiusCM,
|
|
&p.Count, &p.Label, &p.PlantedAt, &p.RemovedAt,
|
|
&p.Version, &p.CreatedAt, &p.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
return &p, nil
|
|
}
|
|
|
|
// ListActivePlantingsForGarden returns every currently-planted plop (removed_at
|
|
// IS NULL) across all objects in a garden — the editor's one-shot load. Always a
|
|
// non-nil slice (empty until plantings CRUD lands in #14). Plop CRUD itself is
|
|
// #14; this is only the /full read side.
|
|
func (d *DB) ListActivePlantingsForGarden(ctx context.Context, gardenID int64) ([]domain.Planting, error) {
|
|
rows, err := d.sql.QueryContext(ctx,
|
|
`SELECT `+qualifyColumns("pl", plantingColumns)+` FROM plantings pl
|
|
JOIN garden_objects o ON o.id = pl.object_id
|
|
WHERE o.garden_id = ? AND pl.removed_at IS NULL
|
|
ORDER BY pl.id`,
|
|
gardenID,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("store: list plantings: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
plantings := []domain.Planting{}
|
|
for rows.Next() {
|
|
p, err := scanPlanting(rows)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("store: scan planting: %w", err)
|
|
}
|
|
plantings = append(plantings, *p)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, fmt.Errorf("store: iterate plantings: %w", err)
|
|
}
|
|
return plantings, nil
|
|
}
|