feat: 考试和培训可点开明细,考试列表显示是否通过
This commit is contained in:
+32
-4
@@ -12,7 +12,15 @@ from pydantic import BaseModel, Field
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from euniv.db import get_db, init_db
|
||||
from euniv.service import fetch_home, login_and_store, revoke_credential, start_credential_refresh, submit_jigsaw
|
||||
from euniv.service import (
|
||||
fetch_exam_detail,
|
||||
fetch_home,
|
||||
fetch_training_detail,
|
||||
login_and_store,
|
||||
revoke_credential,
|
||||
start_credential_refresh,
|
||||
submit_jigsaw,
|
||||
)
|
||||
from euniv.session import clear_session, read_employee_id, write_session
|
||||
|
||||
|
||||
@@ -95,13 +103,33 @@ def revoke(request: Request, response: Response, db: Session = Depends(get_db))
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@app.get("/api/home")
|
||||
def home(request: Request, db: Session = Depends(get_db)) -> dict:
|
||||
def _signed_in(request: Request) -> str:
|
||||
employee_id = read_employee_id(request.cookies)
|
||||
if not employee_id:
|
||||
raise HTTPException(status_code=401, detail="未登录")
|
||||
return employee_id
|
||||
|
||||
|
||||
@app.get("/api/home")
|
||||
def home(request: Request, db: Session = Depends(get_db)) -> dict:
|
||||
try:
|
||||
return fetch_home(db, employee_id)
|
||||
return fetch_home(db, _signed_in(request))
|
||||
except RuntimeError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.get("/api/exam")
|
||||
def exam_detail(path: str, request: Request, db: Session = Depends(get_db)) -> dict:
|
||||
try:
|
||||
return fetch_exam_detail(db, _signed_in(request), path)
|
||||
except RuntimeError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.get("/api/training")
|
||||
def training_detail(path: str, request: Request, db: Session = Depends(get_db)) -> dict:
|
||||
try:
|
||||
return fetch_training_detail(db, _signed_in(request), path)
|
||||
except RuntimeError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user