课程/教学班归档
This commit is contained in:
1 parent
df87aa16d3
commit
e165964a77
6 files changed
+111
-27
No files matched your search
@@ -272,6 +272,7 @@ public sealed class ExperimentsController(
|
||||
x.Status,
|
||||
x.PublishedAt,
|
||||
x.ClosedAt,
|
||||
TeachingTaskStatus = x.TeachingTask!.Status,
|
||||
AcademicTermId = x.TeachingTask!.AcademicTermId,
|
||||
TermName = x.TeachingTask.AcademicTerm!.Name,
|
||||
TaskNumber = x.TeachingTask.TaskNumber,
|
||||
@@ -368,6 +369,7 @@ public sealed class ExperimentsController(
|
||||
x.SelectionStartsAt,
|
||||
x.SelectionEndsAt,
|
||||
x.Status,
|
||||
TeachingTaskStatus = x.TeachingTask!.Status,
|
||||
AcademicTermId = x.TeachingTask!.AcademicTermId,
|
||||
TermName = x.TeachingTask.AcademicTerm!.Name,
|
||||
TaskNumber = x.TeachingTask.TaskNumber,
|
||||
@@ -687,6 +689,8 @@ public sealed class ExperimentsController(
|
||||
.ThenInclude(x => x!.AcademicTerm)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (project is null) return NotFound();
|
||||
if (!IsTaskOperable(project.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (project.Status != ExperimentProjectStatus.Draft)
|
||||
return ConflictProblem("只有草稿实验项目可以修改。");
|
||||
if (project.TeachingTaskId != request.TeachingTaskId)
|
||||
@@ -729,8 +733,11 @@ public sealed class ExperimentsController(
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var project = await ScopedProjects()
|
||||
.Include(x => x.TeachingTask)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (project is null) return NotFound();
|
||||
if (!IsTaskOperable(project.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (project.Status != ExperimentProjectStatus.Draft)
|
||||
return ConflictProblem("只有草稿实验项目可以删除。");
|
||||
|
||||
@@ -754,6 +761,8 @@ public sealed class ExperimentsController(
|
||||
.ThenInclude(x => x!.Course)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (project is null) return NotFound();
|
||||
if (!IsTaskOperable(project.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (project.Status != ExperimentProjectStatus.Published)
|
||||
return ConflictProblem("只有已发布实验项目可以修正教学内容。");
|
||||
if (!CanCorrectPublishedProject(project.TeachingTask!)) return Forbid();
|
||||
@@ -786,11 +795,14 @@ public sealed class ExperimentsController(
|
||||
return ValidationProblem("请为每个已选实验项目填写一个名称,每行一个且数量必须一致。");
|
||||
|
||||
var projects = await ScopedProjects()
|
||||
.Include(x => x.TeachingTask)
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.ToListAsync(cancellationToken);
|
||||
if (projects.Count != ids.Count) return NotFound();
|
||||
if (projects.Any(x => x.Status != ExperimentProjectStatus.Draft))
|
||||
return ConflictProblem("批量修改名称只能包含草稿实验项目。");
|
||||
if (projects.Any(x => !IsTaskOperable(x.TeachingTask!)))
|
||||
return TaskArchivedProblem();
|
||||
|
||||
var projectsById = projects.ToDictionary(x => x.Id);
|
||||
for (var index = 0; index < ids.Count; index++)
|
||||
@@ -809,11 +821,14 @@ public sealed class ExperimentsController(
|
||||
var ids = ValidateBulkProjectIds(request.ProjectIds);
|
||||
if (ids is null) return ValidationProblem("请选择 1 至 100 个实验项目。");
|
||||
var projects = await ScopedProjects()
|
||||
.Include(x => x.TeachingTask)
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.ToListAsync(cancellationToken);
|
||||
if (projects.Count != ids.Count) return NotFound();
|
||||
if (projects.Any(x => x.Status != ExperimentProjectStatus.Draft))
|
||||
return ConflictProblem("批量删除只能包含草稿实验项目。");
|
||||
if (projects.Any(x => !IsTaskOperable(x.TeachingTask!)))
|
||||
return TaskArchivedProblem();
|
||||
|
||||
db.ExperimentProjects.RemoveRange(projects);
|
||||
await db.SaveChangesAsync(cancellationToken);
|
||||
@@ -833,6 +848,8 @@ public sealed class ExperimentsController(
|
||||
.ThenInclude(x => x!.Course)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (project is null) return NotFound();
|
||||
if (!IsTaskOperable(project.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (project.Status != ExperimentProjectStatus.Draft)
|
||||
return ConflictProblem("只有草稿实验项目可以发布。");
|
||||
var hasSchedule = project.ArrangementMode == ExperimentArrangementMode.Centralized
|
||||
@@ -872,8 +889,14 @@ public sealed class ExperimentsController(
|
||||
{
|
||||
var ids = ValidateBulkProjectIds(request.ProjectIds);
|
||||
if (ids is null) return ValidationProblem("请选择 1 至 100 个实验项目。");
|
||||
if (await ScopedProjects().CountAsync(x => ids.Contains(x.Id), cancellationToken) != ids.Count)
|
||||
var projects = await ScopedProjects().AsNoTracking()
|
||||
.Where(x => ids.Contains(x.Id))
|
||||
.Select(x => new { x.Id, x.TeachingTask!.Status })
|
||||
.ToListAsync(cancellationToken);
|
||||
if (projects.Count != ids.Count)
|
||||
return NotFound();
|
||||
if (projects.Any(x => x.Status != TeachingTaskStatus.Published))
|
||||
return TaskArchivedProblem();
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var job = new ExamPublishJob
|
||||
{
|
||||
@@ -908,8 +931,11 @@ public sealed class ExperimentsController(
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var project = await ScopedProjects()
|
||||
.Include(x => x.TeachingTask)
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (project is null) return NotFound();
|
||||
if (!IsTaskOperable(project.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (project.Status != ExperimentProjectStatus.Published)
|
||||
return ConflictProblem("只有已发布实验项目可以关闭。");
|
||||
project.Status = ExperimentProjectStatus.Closed;
|
||||
@@ -930,6 +956,8 @@ public sealed class ExperimentsController(
|
||||
.ThenInclude(x => x!.AcademicTerm)
|
||||
.FirstOrDefaultAsync(x => x.Id == projectId, cancellationToken);
|
||||
if (project is null) return NotFound();
|
||||
if (!IsTaskOperable(project.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (project.Status == ExperimentProjectStatus.Closed)
|
||||
return ConflictProblem("已关闭实验项目不能再增加场次。");
|
||||
if (project.ArrangementMode == ExperimentArrangementMode.Centralized)
|
||||
@@ -1009,6 +1037,8 @@ public sealed class ExperimentsController(
|
||||
if (projects.Count != projectIds.Count)
|
||||
return ValidationProblem(
|
||||
"部分实验项目不存在或不在当前管理范围内。");
|
||||
if (projects.Values.Any(x => !IsTaskOperable(x.TeachingTask!)))
|
||||
return TaskArchivedProblem();
|
||||
|
||||
var createdSessions = new List<(ExperimentProject Project, ExperimentSession Session)>(
|
||||
request.Items.Count);
|
||||
@@ -1100,6 +1130,8 @@ public sealed class ExperimentsController(
|
||||
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||
if (session is null) return NotFound();
|
||||
if (!CanManageSession(session)) return Forbid();
|
||||
if (!IsTaskOperable(session.ExperimentProject!.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (session.Status == ExperimentSessionStatus.Cancelled)
|
||||
return NoContent();
|
||||
|
||||
@@ -1253,6 +1285,8 @@ public sealed class ExperimentsController(
|
||||
var session = await LoadManagedSessionAsync(id, cancellationToken);
|
||||
if (session is null) return NotFound();
|
||||
if (!CanManageSession(session)) return Forbid();
|
||||
if (!IsTaskOperable(session.ExperimentProject!.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (session.Status != ExperimentSessionStatus.Scheduled ||
|
||||
session.ExperimentProject!.Status != ExperimentProjectStatus.Published ||
|
||||
session.ExperimentProject.ArrangementMode != ExperimentArrangementMode.SelfScheduled)
|
||||
@@ -1327,6 +1361,8 @@ public sealed class ExperimentsController(
|
||||
var session = await LoadManagedSessionAsync(id, cancellationToken);
|
||||
if (session is null) return NotFound();
|
||||
if (!CanManageSession(session)) return Forbid();
|
||||
if (!IsTaskOperable(session.ExperimentProject!.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (session.Status != ExperimentSessionStatus.Scheduled ||
|
||||
session.ExperimentProject!.Status != ExperimentProjectStatus.Published ||
|
||||
session.ExperimentProject.ArrangementMode != ExperimentArrangementMode.SelfScheduled)
|
||||
@@ -1429,6 +1465,8 @@ public sealed class ExperimentsController(
|
||||
session.ExperimentProject!.Status !=
|
||||
ExperimentProjectStatus.Published)
|
||||
return NotFound();
|
||||
if (!IsTaskOperable(session.ExperimentProject.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (session.ExperimentProject.ArrangementMode !=
|
||||
ExperimentArrangementMode.SelfScheduled)
|
||||
return ConflictProblem("集中安排实验无需学生预约。");
|
||||
@@ -1517,11 +1555,15 @@ public sealed class ExperimentsController(
|
||||
|
||||
var booking = await db.ExperimentBookings
|
||||
.Include(x => x.ExperimentSession)
|
||||
.ThenInclude(x => x!.ExperimentProject)
|
||||
.ThenInclude(x => x!.TeachingTask)
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.Id == id &&
|
||||
x.StudentId == student.Id,
|
||||
cancellationToken);
|
||||
if (booking is null) return NotFound();
|
||||
if (!IsTaskOperable(booking.ExperimentSession!.ExperimentProject!.TeachingTask!))
|
||||
return TaskArchivedProblem();
|
||||
if (booking.Status == ExperimentBookingStatus.Cancelled)
|
||||
return NoContent();
|
||||
|
||||
@@ -1847,6 +1889,12 @@ public sealed class ExperimentsController(
|
||||
item.Teacher?.UserId == scope.UserId);
|
||||
}
|
||||
|
||||
private static bool IsTaskOperable(TeachingTask task) =>
|
||||
task.Status == TeachingTaskStatus.Published;
|
||||
|
||||
private ActionResult TaskArchivedProblem() =>
|
||||
ConflictProblem("教学任务已归档,实验项目、场次和预约仅可查看,不能再操作。");
|
||||
|
||||
private Task<Student?> CurrentStudentAsync(
|
||||
CancellationToken cancellationToken) =>
|
||||
db.Students.FirstOrDefaultAsync(x =>
|
||||
|
||||
Reference in new issue
Block a user