from fastapi import APIRouter, Depends, Query from sqlalchemy.ext.asyncio import AsyncSession from app.api.deps import get_db from app.services.holiday_service import now_in_china, sync_holidays router = APIRouter() @router.post("/holidays/sync") async def sync_holidays_endpoint( year: int | None = Query(None, description="同步年份,默认当前年份"), db: AsyncSession = Depends(get_db), ): if year is None: year = now_in_china().year count = await sync_holidays(db, year) return {"status": "ok", "year": year, "synced": count} @router.get("/holidays/today") async def get_today_status(db: AsyncSession = Depends(get_db)): from app.services.holiday_service import is_workday today = now_in_china() workday = await is_workday(db, today) return { "date": today.isoformat(), "is_workday": workday, "message": "工作日,正常爬取" if workday else "非工作日,跳过爬取", }