45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db import get_db
|
|
from app.models.about import public_about_page, public_expert, public_experts
|
|
from app.models.home import DEFAULT_COLUMN_PAGE_SIZE, public_column_articles
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/about/pages/{page_key}")
|
|
def read_public_about_page(page_key: str, db: Session = Depends(get_db)) -> dict:
|
|
body = public_about_page(db, page_key)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="单篇页键不正确")
|
|
return body
|
|
|
|
|
|
@router.get("/about/articles/{category}")
|
|
def read_public_column_articles(
|
|
category: str,
|
|
current: int = Query(1, ge=1),
|
|
size: int = Query(DEFAULT_COLUMN_PAGE_SIZE, ge=1, le=100),
|
|
kind: str | None = Query(None),
|
|
q: str | None = Query(None),
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
body = public_column_articles(db, category, current=current, size=size, kind=kind, q=q)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="文章类别不正确")
|
|
return body
|
|
|
|
|
|
@router.get("/about/experts")
|
|
def read_public_experts(db: Session = Depends(get_db)) -> dict:
|
|
return public_experts(db)
|
|
|
|
|
|
@router.get("/about/experts/{expert_id}")
|
|
def read_public_expert(expert_id: int, db: Session = Depends(get_db)) -> dict:
|
|
body = public_expert(db, expert_id)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="专家委员会不存在")
|
|
return body
|