29 lines
911 B
Python
29 lines
911 B
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db import get_db
|
|
from app.models.home import public_article, public_home, public_slide
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/home")
|
|
def read_public_home(db: Session = Depends(get_db)) -> dict:
|
|
return public_home(db)
|
|
|
|
|
|
@router.get("/home/articles/{article_id}")
|
|
def read_public_article(article_id: int, db: Session = Depends(get_db)) -> dict:
|
|
body = public_article(db, article_id)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="文章不存在")
|
|
return body
|
|
|
|
|
|
@router.get("/home/slides/{slide_id}")
|
|
def read_public_slide(slide_id: int, db: Session = Depends(get_db)) -> dict:
|
|
body = public_slide(db, slide_id)
|
|
if body is None:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="轮播不存在")
|
|
return body
|