v0.1测试
This commit is contained in:
120
backend/routes/student.py
Normal file
120
backend/routes/student.py
Normal file
@@ -0,0 +1,120 @@
|
||||
# ===========================================
|
||||
# 班级操行分管理系统 - 后端服务
|
||||
#
|
||||
# 开发者: Canglan
|
||||
# 联系方式: admin@sea-studio.top
|
||||
# 版权归属: Sea Network Technology Studio
|
||||
# 许可证: MIT License
|
||||
#
|
||||
# 版权所有 © Sea Network Technology Studio
|
||||
# ===========================================
|
||||
|
||||
from fastapi import APIRouter, Request, Query
|
||||
from typing import Optional
|
||||
|
||||
from middleware.permission import get_current_user
|
||||
from services.student_service import StudentService
|
||||
from utils.response import success_response, error_response
|
||||
from utils.logger import get_logger
|
||||
|
||||
router = APIRouter()
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
@router.get("/conduct/{student_id}")
|
||||
async def get_conduct_history(
|
||||
request: Request,
|
||||
student_id: int,
|
||||
limit: int = Query(50, ge=1, le=200),
|
||||
offset: int = Query(0, ge=0)
|
||||
):
|
||||
"""
|
||||
获取学生操行分历史
|
||||
"""
|
||||
user = await get_current_user(request)
|
||||
|
||||
# 权限检查:只能查看自己的信息(学生)或同班(管理员)
|
||||
if user["user_type"] == "student" and user["student_id"] != student_id:
|
||||
return error_response(message="无权查看其他学生信息", code=403)
|
||||
|
||||
result = await StudentService.get_conduct_history(
|
||||
student_id=student_id,
|
||||
limit=limit,
|
||||
offset=offset
|
||||
)
|
||||
|
||||
return success_response(data=result)
|
||||
|
||||
|
||||
@router.get("/homework/{student_id}")
|
||||
async def get_homework_status(request: Request, student_id: int):
|
||||
"""
|
||||
获取学生作业情况
|
||||
"""
|
||||
user = await get_current_user(request)
|
||||
|
||||
# 权限检查
|
||||
if user["user_type"] == "student" and user["student_id"] != student_id:
|
||||
return error_response(message="无权查看其他学生信息", code=403)
|
||||
|
||||
result = await StudentService.get_homework_status(student_id)
|
||||
|
||||
return success_response(data=result)
|
||||
|
||||
|
||||
@router.get("/attendance/{student_id}")
|
||||
async def get_attendance_records(
|
||||
request: Request,
|
||||
student_id: int,
|
||||
month: Optional[str] = None
|
||||
):
|
||||
"""
|
||||
获取学生考勤记录
|
||||
"""
|
||||
user = await get_current_user(request)
|
||||
|
||||
# 权限检查
|
||||
if user["user_type"] == "student" and user["student_id"] != student_id:
|
||||
return error_response(message="无权查看其他学生信息", code=403)
|
||||
|
||||
result = await StudentService.get_attendance_records(
|
||||
student_id=student_id,
|
||||
month=month
|
||||
)
|
||||
|
||||
return success_response(data=result)
|
||||
|
||||
|
||||
@router.get("/ranking")
|
||||
async def get_ranking(
|
||||
request: Request,
|
||||
class_id: Optional[int] = None,
|
||||
limit: int = Query(50, ge=1, le=100)
|
||||
):
|
||||
"""
|
||||
获取操行分排行榜
|
||||
"""
|
||||
user = await get_current_user(request)
|
||||
|
||||
result = await StudentService.get_ranking(
|
||||
user_id=user["user_id"],
|
||||
class_id=class_id,
|
||||
limit=limit
|
||||
)
|
||||
|
||||
return success_response(data=result)
|
||||
|
||||
|
||||
@router.get("/my-info")
|
||||
async def get_my_info(request: Request):
|
||||
"""
|
||||
获取当前学生个人信息
|
||||
"""
|
||||
user = await get_current_user(request)
|
||||
|
||||
if user["user_type"] != "student":
|
||||
return error_response(message="仅限学生访问", code=403)
|
||||
|
||||
result = await StudentService.get_student_info(user["student_id"])
|
||||
|
||||
return success_response(data=result)
|
||||
Reference in New Issue
Block a user