refactor: remove personal_rating, DRY get_or_404, fix ty errors

- Drop Product.personal_rating from model, API schemas, and all frontend
  views (list table, detail view, quick-edit form, new-product form)
- Extract get_or_404 into backend/innercontext/api/utils.py; remove five
  duplicate copies from individual API modules
- Fix all ty type errors: generic get_or_404 with TypeVar, cast() in
  coerce_effect_profile validator, col() for ilike on SQLModel column,
  dict[str, Any] annotation in test helper, ty: ignore for CORSMiddleware

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Piotr Oleszczyk 2026-02-27 11:20:13 +01:00
parent 5e3c0c97e5
commit 6333c6678a
15 changed files with 30 additions and 81 deletions

View file

@ -6,6 +6,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query
from sqlmodel import Session, SQLModel, select
from db import get_session
from innercontext.api.utils import get_or_404
from innercontext.models import (
Product,
ProductCategory,
@ -83,7 +84,6 @@ class ProductCreate(SQLModel):
is_tool: bool = False
needle_length_mm: Optional[float] = None
personal_rating: Optional[int] = None
personal_tolerance_notes: Optional[str] = None
personal_repurchase_intent: Optional[bool] = None
@ -137,7 +137,6 @@ class ProductUpdate(SQLModel):
is_tool: Optional[bool] = None
needle_length_mm: Optional[float] = None
personal_rating: Optional[int] = None
personal_tolerance_notes: Optional[str] = None
personal_repurchase_intent: Optional[bool] = None
@ -165,13 +164,6 @@ class InventoryUpdate(SQLModel):
# ---------------------------------------------------------------------------
def get_or_404(session: Session, model, record_id) -> object:
obj = session.get(model, record_id)
if obj is None:
raise HTTPException(status_code=404, detail=f"{model.__name__} not found")
return obj
# ---------------------------------------------------------------------------
# Product routes
# ---------------------------------------------------------------------------