fix: remove remaining list truncation gaps
This commit is contained in:
1 parent
1ddfecbecc
commit
64b86d2a68
8 files changed
+153
-40
No files matched your search
@@ -86,20 +86,35 @@ public sealed class CourseDiscussionsController(
|
||||
}
|
||||
|
||||
[HttpGet("comments/{commentId:guid}/replies")]
|
||||
public async Task<ActionResult> GetReplies(Guid sheetId, Guid commentId, CancellationToken cancellationToken)
|
||||
public async Task<ActionResult> GetReplies(
|
||||
Guid sheetId, Guid commentId, DateTime? afterCreatedAt, Guid? afterId,
|
||||
int pageSize = 30, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var courseId = await GetAccessibleCourseIdAsync(sheetId, cancellationToken);
|
||||
if (!courseId.HasValue) return NotFound();
|
||||
if (afterCreatedAt.HasValue != afterId.HasValue) return BadRequest("回复游标不完整。");
|
||||
pageSize = Math.Clamp(pageSize, 1, 50);
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var items = await db.GradeAnalyticsComments.AsNoTracking()
|
||||
.Where(x => x.CourseId == courseId && x.ParentCommentId == commentId)
|
||||
.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(100)
|
||||
var source = db.GradeAnalyticsComments.AsNoTracking()
|
||||
.Where(x => x.CourseId == courseId && x.ParentCommentId == commentId);
|
||||
if (afterCreatedAt.HasValue)
|
||||
{
|
||||
var cursorAt = afterCreatedAt.Value;
|
||||
var cursorId = afterId!.Value;
|
||||
source = source.Where(x => x.CreatedAt > cursorAt ||
|
||||
x.CreatedAt == cursorAt && x.Id.CompareTo(cursorId) > 0);
|
||||
}
|
||||
var rows = await source.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(pageSize + 1)
|
||||
.Join(db.Users.AsNoTracking(), comment => comment.AuthorUserId, user => user.Id,
|
||||
(comment, user) => new { comment.Id, comment.Content, comment.IsAnonymous, comment.CreatedAt,
|
||||
AuthorName = comment.IsAnonymous ? "匿名用户" : user.DisplayName,
|
||||
CanDelete = comment.AuthorUserId == userId || CanModerate() })
|
||||
.ToListAsync(cancellationToken);
|
||||
return Ok(new { Items = items });
|
||||
var hasMore = rows.Count > pageSize;
|
||||
var items = rows.Take(pageSize).ToArray();
|
||||
var last = items.LastOrDefault();
|
||||
return Ok(new { Items = items, HasMore = hasMore,
|
||||
NextCursor = hasMore && last is not null ? new { last.CreatedAt, last.Id } : null });
|
||||
}
|
||||
|
||||
[HttpPost("comments/{commentId:guid}/replies")]
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Text.Json;
|
||||
using Jiaowu.Api.Contracts;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Domain.System;
|
||||
@@ -49,6 +50,19 @@ public sealed class ExperimentsController(
|
||||
x.Course!.Code.Contains(normalizedCourseKeyword) ||
|
||||
x.Course.Name.Contains(normalizedCourseKeyword));
|
||||
|
||||
var scheduleEntries = db.ScheduleEntries.AsNoTracking()
|
||||
.Where(x => x.SchedulePlan!.Status == SchedulePlanStatus.Published &&
|
||||
x.Kind == ScheduleEntryKind.Experiment &&
|
||||
x.ClassroomId.HasValue &&
|
||||
AccessibleTeachingTasks().Select(task => task.Id).Contains(x.TeachingTaskId))
|
||||
.Where(x => !academicTermId.HasValue || x.SchedulePlan!.AcademicTermId == academicTermId.Value)
|
||||
.Where(x => !offeringCollegeId.HasValue || x.TeachingTask!.Course!.CollegeId == offeringCollegeId.Value)
|
||||
.Where(x => normalizedCourseKeyword == null ||
|
||||
x.TeachingTask!.Course!.Code.Contains(normalizedCourseKeyword) ||
|
||||
x.TeachingTask.Course.Name.Contains(normalizedCourseKeyword));
|
||||
var taskTotal = await tasks.CountAsync(cancellationToken);
|
||||
var scheduleEntryTotal = await scheduleEntries.CountAsync(cancellationToken);
|
||||
|
||||
var periods = db.ScheduleTimeSlots.AsNoTracking()
|
||||
.Where(x => x.IsEnabled);
|
||||
if (academicTermId.HasValue)
|
||||
@@ -76,6 +90,8 @@ public sealed class ExperimentsController(
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
TaskTotal = taskTotal,
|
||||
TasksTruncated = taskTotal > 200,
|
||||
Tasks = await tasks
|
||||
.OrderByDescending(x => x.AcademicTerm!.StartDate)
|
||||
.ThenBy(x => x.Course!.Code)
|
||||
@@ -110,19 +126,9 @@ public sealed class ExperimentsController(
|
||||
.Distinct()
|
||||
.OrderBy(x => x.CollegeName)
|
||||
.ToListAsync(cancellationToken),
|
||||
ScheduleEntries = await db.ScheduleEntries.AsNoTracking()
|
||||
.Where(x => x.SchedulePlan!.Status == SchedulePlanStatus.Published &&
|
||||
x.Kind == ScheduleEntryKind.Experiment &&
|
||||
x.ClassroomId.HasValue &&
|
||||
AccessibleTeachingTasks().Select(task => task.Id)
|
||||
.Contains(x.TeachingTaskId))
|
||||
.Where(x => !academicTermId.HasValue ||
|
||||
x.SchedulePlan!.AcademicTermId == academicTermId.Value)
|
||||
.Where(x => !offeringCollegeId.HasValue ||
|
||||
x.TeachingTask!.Course!.CollegeId == offeringCollegeId.Value)
|
||||
.Where(x => normalizedCourseKeyword == null ||
|
||||
x.TeachingTask!.Course!.Code.Contains(normalizedCourseKeyword) ||
|
||||
x.TeachingTask.Course.Name.Contains(normalizedCourseKeyword))
|
||||
ScheduleEntryTotal = scheduleEntryTotal,
|
||||
ScheduleEntriesTruncated = scheduleEntryTotal > 500,
|
||||
ScheduleEntries = await scheduleEntries
|
||||
.OrderBy(x => x.TeachingTask!.Course!.Code)
|
||||
.ThenBy(x => x.TeachingTask!.TaskNumber)
|
||||
.ThenBy(x => x.DayOfWeek)
|
||||
@@ -1244,7 +1250,9 @@ public sealed class ExperimentsController(
|
||||
public async Task<ActionResult> GetProxyBookingStudents(
|
||||
Guid id,
|
||||
string? keyword,
|
||||
CancellationToken cancellationToken)
|
||||
CancellationToken cancellationToken,
|
||||
int page = 1,
|
||||
int pageSize = 20)
|
||||
{
|
||||
var session = await LoadManagedSessionAsync(id, cancellationToken);
|
||||
if (session is null) return NotFound();
|
||||
@@ -1260,15 +1268,21 @@ public sealed class ExperimentsController(
|
||||
var normalizedKeyword = string.IsNullOrWhiteSpace(keyword) ? null : keyword.Trim();
|
||||
var roster = await TeachingTaskRosterQuery.LoadForTasksAsync(
|
||||
db, [session.ExperimentProject.TeachingTaskId], cancellationToken);
|
||||
return Ok(roster
|
||||
var filtered = roster
|
||||
.Where(x => !bookedStudentIds.Contains(x.StudentId))
|
||||
.Where(x => normalizedKeyword is null ||
|
||||
x.StudentNumber.Contains(normalizedKeyword) ||
|
||||
x.Name.Contains(normalizedKeyword) ||
|
||||
x.ClassName.Contains(normalizedKeyword))
|
||||
.OrderBy(x => x.StudentNumber)
|
||||
.Take(100)
|
||||
.Select(x => new { x.StudentId, x.StudentNumber, x.Name, x.ClassName }));
|
||||
.ThenBy(x => x.StudentId)
|
||||
.ToArray();
|
||||
page = Math.Max(1, page);
|
||||
pageSize = Math.Clamp(pageSize, 1, 100);
|
||||
var items = filtered.Skip((page - 1) * pageSize).Take(pageSize)
|
||||
.Select(x => new { x.StudentId, x.StudentNumber, x.Name, x.ClassName })
|
||||
.Cast<object>().ToArray();
|
||||
return Ok(new PagedResult<object>(items, filtered.Length, page, pageSize));
|
||||
}
|
||||
|
||||
[HttpPost("sessions/{id:guid}/proxy-bookings")]
|
||||
|
||||
@@ -137,20 +137,35 @@ public sealed class GradeAnalyticsController(
|
||||
}
|
||||
|
||||
[HttpGet("courses/{courseId:guid}/comments/{commentId:guid}/replies")]
|
||||
public async Task<ActionResult> GetReplies(Guid courseId, Guid commentId, CancellationToken cancellationToken)
|
||||
public async Task<ActionResult> GetReplies(
|
||||
Guid courseId, Guid commentId, DateTime? afterCreatedAt, Guid? afterId,
|
||||
int pageSize = 30, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (!await CanAccessCommentCourseAsync(courseId, cancellationToken)) return NotFound();
|
||||
if (afterCreatedAt.HasValue != afterId.HasValue) return BadRequest("回复游标不完整。");
|
||||
pageSize = Math.Clamp(pageSize, 1, 50);
|
||||
var currentUserId = currentUserDataScope.Current.UserId;
|
||||
var canModerate = CanModerateComments();
|
||||
var items = await db.GradeAnalyticsComments.AsNoTracking()
|
||||
.Where(x => x.CourseId == courseId && x.ParentCommentId == commentId)
|
||||
.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(100)
|
||||
var source = db.GradeAnalyticsComments.AsNoTracking()
|
||||
.Where(x => x.CourseId == courseId && x.ParentCommentId == commentId);
|
||||
if (afterCreatedAt.HasValue)
|
||||
{
|
||||
var cursorAt = afterCreatedAt.Value;
|
||||
var cursorId = afterId!.Value;
|
||||
source = source.Where(x => x.CreatedAt > cursorAt ||
|
||||
x.CreatedAt == cursorAt && x.Id.CompareTo(cursorId) > 0);
|
||||
}
|
||||
var rows = await source.OrderBy(x => x.CreatedAt).ThenBy(x => x.Id).Take(pageSize + 1)
|
||||
.Join(db.Users.AsNoTracking(), comment => comment.AuthorUserId, user => user.Id,
|
||||
(comment, user) => new { comment.Id, comment.Content, comment.IsAnonymous, comment.CreatedAt,
|
||||
AuthorName = comment.IsAnonymous ? "匿名用户" : user.DisplayName,
|
||||
CanDelete = comment.AuthorUserId == currentUserId || canModerate })
|
||||
.ToListAsync(cancellationToken);
|
||||
return Ok(new { Items = items });
|
||||
var hasMore = rows.Count > pageSize;
|
||||
var items = rows.Take(pageSize).ToArray();
|
||||
var last = items.LastOrDefault();
|
||||
return Ok(new { Items = items, HasMore = hasMore,
|
||||
NextCursor = hasMore && last is not null ? new { last.CreatedAt, last.Id } : null });
|
||||
}
|
||||
|
||||
[HttpPost("courses/{courseId:guid}/comments/{commentId:guid}/replies")]
|
||||
|
||||
Loaded 3 of 8 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user