fix: 修复exam_service异常类导入错误
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
将不存在的BusinessException/ErrorCode替换为现有的NotFoundError/ValidationError
This commit is contained in:
@@ -10,7 +10,7 @@ from sqlalchemy import select, func, and_, or_, desc
|
||||
from app.models.exam import Exam, Question, ExamResult
|
||||
from app.models.exam_mistake import ExamMistake
|
||||
from app.models.course import Course, KnowledgePoint
|
||||
from app.core.exceptions import BusinessException, ErrorCode
|
||||
from app.core.exceptions import NotFoundError, ValidationError
|
||||
from app.utils.score_distributor import ScoreDistributor
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class ExamService:
|
||||
# 检查课程是否存在
|
||||
course = await db.get(Course, course_id)
|
||||
if not course:
|
||||
raise BusinessException(error_code=ErrorCode.NOT_FOUND, message="课程不存在")
|
||||
raise NotFoundError("课程不存在")
|
||||
|
||||
# 获取该课程的所有可用题目
|
||||
stmt = select(Question).where(
|
||||
@@ -46,9 +46,7 @@ class ExamService:
|
||||
all_questions = result.scalars().all()
|
||||
|
||||
if not all_questions:
|
||||
raise BusinessException(
|
||||
error_code=ErrorCode.VALIDATION_ERROR, message="该课程暂无题目"
|
||||
)
|
||||
raise ValidationError("该课程暂无题目")
|
||||
|
||||
# 随机选择题目
|
||||
selected_questions = random.sample(
|
||||
@@ -120,12 +118,10 @@ class ExamService:
|
||||
exam = result.scalar_one_or_none()
|
||||
|
||||
if not exam:
|
||||
raise BusinessException(error_code=ErrorCode.NOT_FOUND, message="考试记录不存在")
|
||||
raise NotFoundError("考试记录不存在")
|
||||
|
||||
if exam.status != "started":
|
||||
raise BusinessException(
|
||||
error_code=ErrorCode.VALIDATION_ERROR, message="考试已结束或已提交"
|
||||
)
|
||||
raise ValidationError("考试已结束或已提交")
|
||||
|
||||
# 检查考试是否超时
|
||||
if datetime.now() > exam.start_time + timedelta(
|
||||
@@ -133,9 +129,7 @@ class ExamService:
|
||||
):
|
||||
exam.status = "timeout"
|
||||
await db.commit()
|
||||
raise BusinessException(
|
||||
error_code=ErrorCode.VALIDATION_ERROR, message="考试已超时"
|
||||
)
|
||||
raise ValidationError("考试已超时")
|
||||
|
||||
# 处理答案
|
||||
answers_dict = {ans["question_id"]: ans["answer"] for ans in answers}
|
||||
@@ -223,7 +217,7 @@ class ExamService:
|
||||
exam = result.scalar_one_or_none()
|
||||
|
||||
if not exam:
|
||||
raise BusinessException(error_code=ErrorCode.NOT_FOUND, message="考试记录不存在")
|
||||
raise NotFoundError("考试记录不存在")
|
||||
|
||||
# 构建返回数据
|
||||
exam_data = {
|
||||
|
||||
Reference in New Issue
Block a user