feat(P2余量+P3): chat/history+usage聚合API;教师端:is_admin+班级模型+admin API(班级/加学生/发题公告插对话流/学情聚合/看对话/用量)+teacher.html教师工作台+index历史对话加载+教师入口
这个提交包含在:
@@ -1,8 +1,9 @@
|
||||
"""ORM 模型:题目、提交记录、学习进度、用户、对话消息。"""
|
||||
"""ORM 模型:题目、提交记录、学习进度、用户、对话消息、班级。"""
|
||||
from app.models.klass import Class, ClassMember
|
||||
from app.models.message import Message
|
||||
from app.models.problem import Problem
|
||||
from app.models.progress import Progress
|
||||
from app.models.submission import Submission
|
||||
from app.models.user import User
|
||||
|
||||
__all__ = ["Message", "Problem", "Progress", "Submission", "User"]
|
||||
__all__ = ["Class", "ClassMember", "Message", "Problem", "Progress", "Submission", "User"]
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
"""班级与成员:教师建班、按用户名加学生,教师端发题/看学情的作用域。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, UniqueConstraint, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.db import Base
|
||||
|
||||
|
||||
class Class(Base):
|
||||
__tablename__ = "classes"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(String(64))
|
||||
course: Mapped[str] = mapped_column(String(32), default="usaco")
|
||||
teacher_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.name,
|
||||
"course": self.course,
|
||||
"teacher_id": self.teacher_id,
|
||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||
}
|
||||
|
||||
|
||||
class ClassMember(Base):
|
||||
__tablename__ = "class_members"
|
||||
__table_args__ = (UniqueConstraint("class_id", "user_id", name="uq_class_user"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
class_id: Mapped[int] = mapped_column(ForeignKey("classes.id"), index=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True)
|
||||
joined_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
@@ -22,6 +22,7 @@ class User(Base):
|
||||
mail: Mapped[str] = mapped_column(String(128), default="")
|
||||
# 学科偏好(usaco / ap-csa / ap-calc / ap-phys / ap-chem / ap-bio)
|
||||
course: Mapped[str] = mapped_column(String(32), default="usaco")
|
||||
is_admin: Mapped[bool] = mapped_column(Integer, default=0) # 教师/管理员
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
|
||||
last_login_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
|
||||
@@ -31,6 +32,7 @@ class User(Base):
|
||||
"uname": self.uname,
|
||||
"hydro_uname": self.hydro_uname,
|
||||
"course": self.course,
|
||||
"is_admin": bool(self.is_admin),
|
||||
"created_at": self.created_at.isoformat() if self.created_at else None,
|
||||
"last_login_at": self.last_login_at.isoformat() if self.last_login_at else None,
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户