Link approval tasks to specific records

This commit is contained in:
biss committed 2026-12-01 10:41:02 +08:00
1 parent 8b9f156dd4
commit c3095545d7
6 files changed
+37 -10

No files matched your search

@@ -1264,11 +1264,12 @@ public sealed class ComprehensiveAssessmentsController(
[Authorize(Roles = Reviewers)]
public async Task<ActionResult> PendingDeclarations(
int page = 1, int pageSize = 30, Guid? batchId = null, string? keyword = null,
CancellationToken token = default)
CancellationToken token = default, Guid? id = null)
{
page = Math.Max(page, 1);
pageSize = Math.Clamp(pageSize, 10, 100);
var query = PendingDeclarationScope(db.ComprehensiveAssessmentDeclarations.AsNoTracking());
if (id.HasValue) query = query.Where(x => x.Id == id.Value);
if (batchId.HasValue) query = query.Where(x => x.ComprehensiveAssessmentBatchId == batchId);
if (!string.IsNullOrWhiteSpace(keyword))
{
@@ -1350,13 +1351,14 @@ public sealed class ComprehensiveAssessmentsController(
public async Task<ActionResult> GetAppeals(
int page = 1, int pageSize = 30, Guid? batchId = null,
ComprehensiveAssessmentAppealStatus? status = null, string? keyword = null,
CancellationToken token = default)
CancellationToken token = default, Guid? id = null)
{
page = Math.Max(page, 1);
pageSize = Math.Clamp(pageSize, 10, 100);
var studentId = AssessmentScope.Scope == DataScope.Self ? await CurrentStudentIdAsync(token) : null;
var query = db.ComprehensiveAssessmentAppeals.AsNoTracking();
query = studentId.HasValue ? query.Where(x => x.StudentId == studentId) : ApplyAppealScope(query);
if (id.HasValue) query = query.Where(x => x.Id == id.Value);
if (batchId.HasValue) query = query.Where(x => x.ComprehensiveAssessmentBatchId == batchId);
if (status.HasValue) query = query.Where(x => x.Status == status);
if (!string.IsNullOrWhiteSpace(keyword))
@@ -786,9 +786,10 @@ public sealed class DormitoryServicesController(
[Authorize(Roles = Viewers)]
public async Task<ActionResult> GetApplications(DormitoryApplicationStatus? status = null,
DormitoryApplicationType? type = null, int? page = null, int? pageSize = null,
CancellationToken ct = default)
CancellationToken ct = default, Guid? id = null)
{
var source = ApplyApplicationScope(db.DormitoryApplications.AsNoTracking());
if (id.HasValue) source = source.Where(x => x.Id == id.Value);
if (status.HasValue) source = source.Where(x => x.Status == status.Value);
if (type.HasValue) source = source.Where(x => x.Type == type.Value);
var ordered = source.OrderByDescending(x => x.SubmittedAt).ThenByDescending(x => x.Id);
@@ -241,9 +241,9 @@ public sealed class ComprehensiveAssessmentsControllerTests
public async Task CounselorPendingDeclarations_IsLimitedToAssignedClasses()
{
await using var fixture = await Fixture.CreateAsync(includeSecondStudent: true, secondClass: true);
fixture.Db.ComprehensiveAssessmentDeclarations.AddRange(
Declaration(fixture.Batch.Id, fixture.Student.Id, fixture.DeclarationDimension.Id, "本班材料"),
Declaration(fixture.Batch.Id, fixture.OtherStudent!.Id, fixture.DeclarationDimension.Id, "其他班材料"));
var own = Declaration(fixture.Batch.Id, fixture.Student.Id, fixture.DeclarationDimension.Id, "本班材料");
var other = Declaration(fixture.Batch.Id, fixture.OtherStudent!.Id, fixture.DeclarationDimension.Id, "其他班材料");
fixture.Db.ComprehensiveAssessmentDeclarations.AddRange(own, other);
await fixture.Db.SaveChangesAsync();
var controller = new ComprehensiveAssessmentsController(fixture.Db, fixture.CounselorScope);
@@ -251,6 +251,10 @@ public sealed class ComprehensiveAssessmentsControllerTests
var page = Assert.IsType<PagedResult<AssessmentDeclarationView>>(response.Value);
Assert.Single(page.Items);
Assert.Equal("本班材料", page.Items.Single().Title);
var targeted = Assert.IsType<OkObjectResult>(await controller.PendingDeclarations(token: CancellationToken.None, id: own.Id));
Assert.Equal(own.Id, Assert.Single(Assert.IsType<PagedResult<AssessmentDeclarationView>>(targeted.Value).Items).Id);
var outside = Assert.IsType<OkObjectResult>(await controller.PendingDeclarations(token: CancellationToken.None, id: other.Id));
Assert.Empty(Assert.IsType<PagedResult<AssessmentDeclarationView>>(outside.Value).Items);
}
[Fact]
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff. Show more