feat(P2余量+P3): chat/history+usage聚合API;教师端:is_admin+班级模型+admin API(班级/加学生/发题公告插对话流/学情聚合/看对话/用量)+teacher.html教师工作台+index历史对话加载+教师入口
这个提交包含在:
@@ -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())
|
||||
在新工单中引用
屏蔽一个用户