feat(api): implement FastAPI routes with JWT authentication
- jokes.py: Public joke listing, detail, and random endpoints - categories.py: Type and crowd listing endpoints - auth.py: Login endpoint with JWT token generation - admin.py: Full CRUD for jokes, types, crowds with JWT protection - Fix request body schemas to use Create DTOs instead of Response models Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
d59474f0a6
commit
c3a8e3e311
@@ -0,0 +1,22 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import get_db
|
||||
from app.models.category import JokeCrowd, JokeType
|
||||
from app.schemas.category import JokeCrowdResponse, JokeTypeResponse
|
||||
|
||||
router = APIRouter(prefix="/categories", tags=["分类"])
|
||||
|
||||
|
||||
@router.get("/types", response_model=list[JokeTypeResponse])
|
||||
def list_types(db: Session = Depends(get_db)):
|
||||
"""获取所有笑话类型"""
|
||||
types = db.query(JokeType).order_by(JokeType.sort_order, JokeType.id).all()
|
||||
return [JokeTypeResponse.model_validate(t) for t in types]
|
||||
|
||||
|
||||
@router.get("/crowds", response_model=list[JokeCrowdResponse])
|
||||
def list_crowds(db: Session = Depends(get_db)):
|
||||
"""获取所有笑话人群分类"""
|
||||
crowds = db.query(JokeCrowd).order_by(JokeCrowd.sort_order, JokeCrowd.id).all()
|
||||
return [JokeCrowdResponse.model_validate(c) for c in crowds]
|
||||
Reference in New Issue
Block a user