waxwing/app/api/endpoints/locations.py
pyr0ball 5f5cb99db6 feat: bootstrap Waxwing Phase 1 scaffold
Plant registry, grow event calendar, and gardening knowledge base
populated via cf-harvest ingest endpoint. All 23 tests passing.

Stack:
- FastAPI + SQLite (cf-core migrations) on port 8522
- Vue 3 + Vite + Pinia SPA on port 8521
- 5 SQL migrations: locations → plants → grow_events, knowledge_sources → knowledge_facts
- Earthy green theme (--color-primary: #4a7c59) matching CF theme system

Knowledge ingest contract:
- POST /api/v1/knowledge/ingest — idempotent on fact_hash (sha256 of type+payload+video_path)
- 8 fact types: companion_planting, soil_amendment, propagation, pest_diagnosis,
  harvest_timing, instruction, medicinal, history_context
- Partial batch failure: malformed facts collected in rejected[], valid facts inserted
- Re-ingesting same video batch: facts_skipped_duplicate > 0, no duplicates

Wired views: RegistryView (plant CRUD), KnowledgeView (facts + type filter chips)
Stub views: CalendarView, SettingsView
2026-06-10 00:03:41 -07:00

51 lines
1.7 KiB
Python

from __future__ import annotations
from fastapi import APIRouter, Depends, HTTPException
from app.core.config import settings
from app.db.store import Store
from app.models.schemas.location import LocationCreate, LocationOut, LocationUpdate
router = APIRouter()
def _get_store() -> Store:
s = Store(settings.DB_PATH)
try:
yield s
finally:
s.close()
@router.post("", response_model=LocationOut, status_code=201)
async def create_location(body: LocationCreate, store: Store = Depends(_get_store)):
cur = store.conn.execute(
"""INSERT INTO locations (name, kind, size_note, sun_note, notes)
VALUES (?, ?, ?, ?, ?) RETURNING *""",
(body.name, body.kind, body.size_note, body.sun_note, body.notes),
)
row = store._row_to_dict(cur.fetchone())
store.conn.commit()
return row
@router.get("", response_model=list[LocationOut])
async def list_locations(store: Store = Depends(_get_store)):
rows = store.conn.execute("SELECT * FROM locations ORDER BY name").fetchall()
return [store._row_to_dict(r) for r in rows]
@router.get("/{location_id}", response_model=LocationOut)
async def get_location(location_id: int, store: Store = Depends(_get_store)):
row = store.conn.execute(
"SELECT * FROM locations WHERE id = ?", (location_id,)
).fetchone()
if not row:
raise HTTPException(status_code=404, detail="Location not found")
return store._row_to_dict(row)
@router.delete("/{location_id}", status_code=204)
async def delete_location(location_id: int, store: Store = Depends(_get_store)):
store.conn.execute("DELETE FROM locations WHERE id = ?", (location_id,))
store.conn.commit()