Files
diary-news/backend
xiaji 6b087113e9 fix(me): 把 Pydantic class 移到路由之前,避免 NameError on import
上一次的路由重排把 @router.post(/reads/by-category) 挪到了 mark_read 之前,
但 Pydantic class (CategoryReadRequest/Response/CategoryCountItem) 还在文件底部。

Python 装饰器在 import 阶段立即执行,@router.post(..., response_model=ClassName)
会立刻查找 ClassName — 找不到就 NameError:
  NameError: name 'CategoryReadResponse' is not defined

修法:把 class 和 _build_category_filter helper 一起挪到路由装饰器之前。
Python 函数体内的名字查找是延迟的(运行时),但装饰器参数是立即的。
2026-06-15 20:50:39 +08:00
..