feat(P2余量+P3): chat/history+usage聚合API;教师端:is_admin+班级模型+admin API(班级/加学生/发题公告插对话流/学情聚合/看对话/用量)+teacher.html教师工作台+index历史对话加载+教师入口
这个提交包含在:
@@ -0,0 +1,23 @@
|
||||
"""用量统计 API:/api/usage/summary(个人)+ /api/usage/monthly(月度配额概览)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.db import get_session
|
||||
from app.services.auth_service import AuthService
|
||||
from app.services.usage_service import UsageService
|
||||
|
||||
router = APIRouter(prefix="/usage", tags=["usage"])
|
||||
|
||||
|
||||
def _bearer(authorization: str | None) -> str:
|
||||
if not authorization or not authorization.lower().startswith("bearer "):
|
||||
raise HTTPException(401, "未登录")
|
||||
return authorization[7:].strip()
|
||||
|
||||
|
||||
@router.get("/summary")
|
||||
async def summary(days: int = 7, authorization: str | None = Header(None), session: Session = Depends(get_session)):
|
||||
user = AuthService(session).me(_bearer(authorization))
|
||||
return UsageService(session).summary(user["id"], days=min(days, 30))
|
||||
在新工单中引用
屏蔽一个用户