Localize classroom and course adjustment errors
This commit is contained in:
1 parent
0202e23fde
commit
1a6d742437
4 files changed
+181
-53
No files matched your search
@@ -5,10 +5,12 @@ using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Jiaowu.Api.Infrastructure.Localization;
|
||||
using Jiaowu.Api.Infrastructure.Timetables;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Jiaowu.Api.Controllers;
|
||||
|
||||
@@ -18,8 +20,28 @@ namespace Jiaowu.Api.Controllers;
|
||||
public sealed class ClassroomReservationsController(
|
||||
AppDbContext db,
|
||||
ICurrentUserDataScope scope,
|
||||
ClassroomReservationAvailabilityService availabilityService) : ControllerBase
|
||||
ClassroomReservationAvailabilityService availabilityService,
|
||||
IStringLocalizer<SharedResource>? localizer = null) : ControllerBase
|
||||
{
|
||||
private static readonly IReadOnlyDictionary<string, string> ClassroomReservationsErrorKeys = new Dictionary<string, string>
|
||||
{
|
||||
["请填写借用用途。"] = "ClassroomReservations.Application.PurposeRequired",
|
||||
["请填写联系电话。"] = "ClassroomReservations.Application.PhoneRequired",
|
||||
["所选教室在该时段已有课程、考试或已批准预约。"] = "ClassroomReservations.Room.UnavailableAtTime",
|
||||
["您已提交过同一教室、重叠时段的申请。"] = "ClassroomReservations.Application.OverlappingDuplicate",
|
||||
["当前状态不能取消。"] = "ClassroomReservations.Application.CannotCancelCurrentState",
|
||||
["已过期的预约不能取消。"] = "ClassroomReservations.Application.ExpiredCannotCancel",
|
||||
["驳回时必须填写审核意见。"] = "ClassroomReservations.Review.CommentRequired",
|
||||
["该申请已处理,不能重复审核。"] = "ClassroomReservations.Review.AlreadyProcessed",
|
||||
["预约日期已过,不能批准。"] = "ClassroomReservations.Review.DatePassed",
|
||||
["预约范围包含不存在的节次。"] = "ClassroomReservations.Periods.NotFound",
|
||||
["预约范围包含不存在或未启用的节次。"] = "ClassroomReservations.Periods.Unavailable",
|
||||
["学院管理员账号未配置所属学院,无法审核。"] = "ClassroomReservations.Review.CollegeNotConfigured",
|
||||
["申请人数已超过教室当前容量,不能批准。"] = "ClassroomReservations.Review.ApplicantCountExceedsCapacity",
|
||||
["预约日期不能早于今天。"] = "ClassroomReservations.Date.CannotBeInPast",
|
||||
["预约日期不在所选学期范围内。"] = "ClassroomReservations.Date.OutsideTerm",
|
||||
};
|
||||
|
||||
[HttpGet("options")]
|
||||
public async Task<ActionResult> GetOptions(
|
||||
Guid? academicTermId,
|
||||
@@ -623,11 +645,17 @@ public sealed class ClassroomReservationsController(
|
||||
private ActionResult ConflictProblem(string detail) =>
|
||||
Conflict(new ProblemDetails
|
||||
{
|
||||
Title = "无法完成教室预约",
|
||||
Detail = detail,
|
||||
Title = SharedResourceText.Get(localizer, "ClassroomReservations.Errors.Title"),
|
||||
Detail = LocalizeClassroomReservationMessage(detail),
|
||||
Status = StatusCodes.Status409Conflict
|
||||
});
|
||||
|
||||
private ActionResult ValidationProblem(string detail) =>
|
||||
base.ValidationProblem(detail: LocalizeClassroomReservationMessage(detail));
|
||||
|
||||
private string LocalizeClassroomReservationMessage(string detail) =>
|
||||
ClassroomReservationsErrorKeys.TryGetValue(detail, out var key) ? SharedResourceText.Get(localizer, key) : detail;
|
||||
|
||||
private static string? Normalize(string? value) =>
|
||||
string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
|
||||
|
||||
@@ -4,12 +4,14 @@ using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Jiaowu.Api.Infrastructure.Localization;
|
||||
using Jiaowu.Api.Infrastructure.Timetables;
|
||||
using Jiaowu.Api.Infrastructure.Scheduling;
|
||||
using Jiaowu.Api.Infrastructure.Teaching;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Jiaowu.Api.Controllers;
|
||||
|
||||
@@ -18,8 +20,30 @@ namespace Jiaowu.Api.Controllers;
|
||||
[Route("api/course-adjustments")]
|
||||
public sealed class CourseAdjustmentsController(
|
||||
AppDbContext db,
|
||||
ICurrentUserDataScope currentUserDataScope) : ControllerBase
|
||||
ICurrentUserDataScope currentUserDataScope,
|
||||
IStringLocalizer<SharedResource>? localizer = null) : ControllerBase
|
||||
{
|
||||
private static readonly IReadOnlyDictionary<string, string> CourseAdjustmentsErrorKeys = new Dictionary<string, string>
|
||||
{
|
||||
["每批条数应在 1 至 100 之间。"] = "CourseAdjustments.PageSize.Range",
|
||||
["调停课申请游标无效。"] = "CourseAdjustments.Cursor.Invalid",
|
||||
["待审核调停课游标无效。"] = "CourseAdjustments.PendingCursor.Invalid",
|
||||
["只有草稿可以提交。"] = "CourseAdjustments.Application.DraftOnlyForSubmit",
|
||||
["只能审核本学院课程的调停课申请。"] = "CourseAdjustments.Review.CollegeScopeOnly",
|
||||
["只有待审核的申请可以审批。"] = "CourseAdjustments.Review.PendingOnlyApprove",
|
||||
["只有待审核的申请可以退回。"] = "CourseAdjustments.Review.PendingOnlyReturn",
|
||||
["教学班不存在或未发布。"] = "CourseAdjustments.Task.Unavailable",
|
||||
["请选择起始节次。"] = "CourseAdjustments.Schedule.StartPeriodRequired",
|
||||
["请选择代课教师。"] = "CourseAdjustments.SubstituteTeacher.Required",
|
||||
["代课教师不存在或已离职。"] = "CourseAdjustments.SubstituteTeacher.Unavailable",
|
||||
["请选择当前已发布课表中的具体原课次。"] = "CourseAdjustments.Schedule.SourceOccurrenceRequired",
|
||||
["该课次已有待审核或已通过的调停课记录。"] = "CourseAdjustments.Schedule.AdjustmentAlreadyExists",
|
||||
["目标日期必须在本学期起止日期内。"] = "CourseAdjustments.Schedule.DateOutsideTerm",
|
||||
["目标教室不存在、已停用或正在维修。"] = "CourseAdjustments.Room.Unavailable",
|
||||
["原课次已不在当前发布课表中,请退回后重新选择。"] = "CourseAdjustments.Schedule.SourceOccurrenceNoLongerPublished",
|
||||
["目标上课日期或节次不完整。"] = "CourseAdjustments.Schedule.TargetIncomplete",
|
||||
};
|
||||
|
||||
private const string Applicants =
|
||||
SystemRoles.SuperAdmin + "," +
|
||||
SystemRoles.AcademicAdmin + "," +
|
||||
@@ -184,7 +208,7 @@ public sealed class CourseAdjustmentsController(
|
||||
if (pageSize is < 1 or > 100)
|
||||
return ValidationProblem("每批条数应在 1 至 100 之间。");
|
||||
if (!CursorToken.TryDecode<CreatedCursor>(cursor, out var after))
|
||||
return BadRequest("调停课申请游标无效。");
|
||||
return BadRequest(SharedResourceText.Get(localizer, "CourseAdjustments.Cursor.Invalid"));
|
||||
|
||||
var userId = currentUserDataScope.Current.UserId;
|
||||
var source = db.CourseAdjustments.AsNoTracking()
|
||||
@@ -232,7 +256,7 @@ public sealed class CourseAdjustmentsController(
|
||||
if (pageSize is < 1 or > 100)
|
||||
return ValidationProblem("每批条数应在 1 至 100 之间。");
|
||||
if (!CursorToken.TryDecode<SubmittedCursor>(cursor, out var after))
|
||||
return BadRequest("待审核调停课游标无效。");
|
||||
return BadRequest(SharedResourceText.Get(localizer, "CourseAdjustments.PendingCursor.Invalid"));
|
||||
|
||||
var scope = currentUserDataScope.Current;
|
||||
var source = db.CourseAdjustments.AsNoTracking()
|
||||
@@ -790,18 +814,18 @@ public sealed class CourseAdjustmentsController(
|
||||
ScheduleEntry source,
|
||||
int startWeek,
|
||||
int endWeek) => new()
|
||||
{
|
||||
SchedulePlanId = source.SchedulePlanId,
|
||||
TeachingTaskId = source.TeachingTaskId,
|
||||
ClassroomId = source.ClassroomId,
|
||||
DayOfWeek = source.DayOfWeek,
|
||||
StartPeriod = source.StartPeriod,
|
||||
PeriodCount = source.PeriodCount,
|
||||
StartWeek = startWeek,
|
||||
EndWeek = endWeek,
|
||||
WeekPattern = source.WeekPattern,
|
||||
Notes = source.Notes
|
||||
};
|
||||
{
|
||||
SchedulePlanId = source.SchedulePlanId,
|
||||
TeachingTaskId = source.TeachingTaskId,
|
||||
ClassroomId = source.ClassroomId,
|
||||
DayOfWeek = source.DayOfWeek,
|
||||
StartPeriod = source.StartPeriod,
|
||||
PeriodCount = source.PeriodCount,
|
||||
StartWeek = startWeek,
|
||||
EndWeek = endWeek,
|
||||
WeekPattern = source.WeekPattern,
|
||||
Notes = source.Notes
|
||||
};
|
||||
|
||||
private static bool RequiresSourceOccurrence(CourseAdjustmentType type) =>
|
||||
type is CourseAdjustmentType.Reschedule or
|
||||
@@ -852,46 +876,46 @@ public sealed class CourseAdjustmentsController(
|
||||
|
||||
private System.Linq.Expressions.Expression<
|
||||
Func<CourseAdjustment, object>> AdjustmentProjection() => x => new
|
||||
{
|
||||
x.Id,
|
||||
x.TeachingTaskId,
|
||||
x.TeachingTask!.TaskNumber,
|
||||
TaskName = x.TeachingTask.Name,
|
||||
CourseCode = x.TeachingTask.Course!.Code,
|
||||
CourseName = x.TeachingTask.Course.Name,
|
||||
CollegeName = x.TeachingTask.Course.College!.Name,
|
||||
TeacherNames = x.TeachingTask.Teachers
|
||||
{
|
||||
x.Id,
|
||||
x.TeachingTaskId,
|
||||
x.TeachingTask!.TaskNumber,
|
||||
TaskName = x.TeachingTask.Name,
|
||||
CourseCode = x.TeachingTask.Course!.Code,
|
||||
CourseName = x.TeachingTask.Course.Name,
|
||||
CollegeName = x.TeachingTask.Course.College!.Name,
|
||||
TeacherNames = x.TeachingTask.Teachers
|
||||
.OrderByDescending(t => t.IsPrimary)
|
||||
.Select(t => t.Teacher!.Name),
|
||||
x.Type,
|
||||
x.Status,
|
||||
x.Reason,
|
||||
x.ReviewComment,
|
||||
x.SourceScheduleEntryId,
|
||||
x.SourceWeek,
|
||||
x.SourceDate,
|
||||
x.SourceStartPeriod,
|
||||
x.SourcePeriodCount,
|
||||
SourceClassroomName = x.SourceClassroomId == null
|
||||
x.Type,
|
||||
x.Status,
|
||||
x.Reason,
|
||||
x.ReviewComment,
|
||||
x.SourceScheduleEntryId,
|
||||
x.SourceWeek,
|
||||
x.SourceDate,
|
||||
x.SourceStartPeriod,
|
||||
x.SourcePeriodCount,
|
||||
SourceClassroomName = x.SourceClassroomId == null
|
||||
? null
|
||||
: db.Classrooms
|
||||
.Where(room => room.Id == x.SourceClassroomId)
|
||||
.Select(room => room.Building!.Name + " " + room.Name)
|
||||
.FirstOrDefault(),
|
||||
x.TargetDate,
|
||||
x.DayOfWeek,
|
||||
x.StartPeriod,
|
||||
x.PeriodCount,
|
||||
ClassroomName = x.Classroom != null ? x.Classroom.Name : null,
|
||||
BuildingName = x.Classroom != null ? x.Classroom.Building!.Name : null,
|
||||
SubstituteTeacherName = x.SubstituteTeacher != null ? x.SubstituteTeacher.Name : null,
|
||||
x.CancelWeek,
|
||||
x.CancelDate,
|
||||
x.ApplicantUserId,
|
||||
x.SubmittedAt,
|
||||
x.ReviewedAt,
|
||||
x.CreatedAt
|
||||
};
|
||||
x.TargetDate,
|
||||
x.DayOfWeek,
|
||||
x.StartPeriod,
|
||||
x.PeriodCount,
|
||||
ClassroomName = x.Classroom != null ? x.Classroom.Name : null,
|
||||
BuildingName = x.Classroom != null ? x.Classroom.Building!.Name : null,
|
||||
SubstituteTeacherName = x.SubstituteTeacher != null ? x.SubstituteTeacher.Name : null,
|
||||
x.CancelWeek,
|
||||
x.CancelDate,
|
||||
x.ApplicantUserId,
|
||||
x.SubmittedAt,
|
||||
x.ReviewedAt,
|
||||
x.CreatedAt
|
||||
};
|
||||
|
||||
private sealed record SourceOccurrence(
|
||||
ScheduleEntry Entry,
|
||||
@@ -902,10 +926,16 @@ public sealed class CourseAdjustmentsController(
|
||||
private ActionResult ConflictProblem(string detail) =>
|
||||
Conflict(new ProblemDetails
|
||||
{
|
||||
Title = "无法完成操作",
|
||||
Detail = detail,
|
||||
Title = SharedResourceText.Get(localizer, "CourseAdjustments.Errors.Title"),
|
||||
Detail = LocalizeCourseAdjustmentMessage(detail),
|
||||
Status = StatusCodes.Status409Conflict
|
||||
});
|
||||
|
||||
private ActionResult ValidationProblem(string detail) =>
|
||||
base.ValidationProblem(detail: LocalizeCourseAdjustmentMessage(detail));
|
||||
|
||||
private string LocalizeCourseAdjustmentMessage(string detail) =>
|
||||
CourseAdjustmentsErrorKeys.TryGetValue(detail, out var key) ? SharedResourceText.Get(localizer, key) : detail;
|
||||
}
|
||||
|
||||
// ═══════════════ Request records ═══════════════
|
||||
|
||||
@@ -536,4 +536,39 @@
|
||||
<data name="DormitoryServices.Room.NumberLength" xml:space="preserve"><value>The room number is required and must be no longer than 30 characters.</value></data>
|
||||
<data name="DormitoryServices.Room.FloorRange" xml:space="preserve"><value>The floor must be between 1 and 100.</value></data>
|
||||
<data name="DormitoryServices.Room.BedCountRange" xml:space="preserve"><value>The number of beds must be between 1 and 20.</value></data>
|
||||
<data name="请填写借用用途。" xml:space="preserve"><value>Enter the purpose of the reservation.</value></data>
|
||||
<data name="请填写联系电话。" xml:space="preserve"><value>Enter a contact phone number.</value></data>
|
||||
<data name="所选教室在该时段已有课程、考试或已批准预约。" xml:space="preserve"><value>The selected room already has a class, exam or approved reservation at this time.</value></data>
|
||||
<data name="您已提交过同一教室、重叠时段的申请。" xml:space="preserve"><value>You already have a reservation request for this room at an overlapping time.</value></data>
|
||||
<data name="当前状态不能取消。" xml:space="preserve"><value>The reservation cannot be cancelled in its current state.</value></data>
|
||||
<data name="已过期的预约不能取消。" xml:space="preserve"><value>Expired reservations cannot be cancelled.</value></data>
|
||||
<data name="驳回时必须填写审核意见。" xml:space="preserve"><value>Enter a review comment when rejecting the request.</value></data>
|
||||
<data name="该申请已处理,不能重复审核。" xml:space="preserve"><value>This request has already been processed and cannot be reviewed again.</value></data>
|
||||
<data name="预约日期已过,不能批准。" xml:space="preserve"><value>A reservation date in the past cannot be approved.</value></data>
|
||||
<data name="预约范围包含不存在的节次。" xml:space="preserve"><value>The reservation includes a class period that does not exist.</value></data>
|
||||
<data name="预约范围包含不存在或未启用的节次。" xml:space="preserve"><value>The reservation includes a nonexistent or disabled class period.</value></data>
|
||||
<data name="学院管理员账号未配置所属学院,无法审核。" xml:space="preserve"><value>The college administrator account has no college assigned and cannot review requests.</value></data>
|
||||
<data name="无法完成教室预约" xml:space="preserve"><value>Classroom reservation could not be completed</value></data>
|
||||
<data name="每批条数应在 1 至 100 之间。" xml:space="preserve"><value>The page size must be between 1 and 100.</value></data>
|
||||
<data name="调停课申请游标无效。" xml:space="preserve"><value>The course adjustment cursor is invalid.</value></data>
|
||||
<data name="待审核调停课游标无效。" xml:space="preserve"><value>The pending course adjustment cursor is invalid.</value></data>
|
||||
<data name="只有草稿可以提交。" xml:space="preserve"><value>Only draft requests can be submitted.</value></data>
|
||||
<data name="只能审核本学院课程的调停课申请。" xml:space="preserve"><value>You can only review course adjustment requests for your college.</value></data>
|
||||
<data name="只有待审核的申请可以审批。" xml:space="preserve"><value>Only requests awaiting review can be approved.</value></data>
|
||||
<data name="只有待审核的申请可以退回。" xml:space="preserve"><value>Only requests awaiting review can be returned.</value></data>
|
||||
<data name="教学班不存在或未发布。" xml:space="preserve"><value>The teaching class does not exist or is unpublished.</value></data>
|
||||
<data name="请选择起始节次。" xml:space="preserve"><value>Select a starting period.</value></data>
|
||||
<data name="请选择代课教师。" xml:space="preserve"><value>Select a substitute teacher.</value></data>
|
||||
<data name="代课教师不存在或已离职。" xml:space="preserve"><value>The substitute teacher does not exist or is no longer active.</value></data>
|
||||
<data name="请选择当前已发布课表中的具体原课次。" xml:space="preserve"><value>Select the specific original class occurrence from the published timetable.</value></data>
|
||||
<data name="该课次已有待审核或已通过的调停课记录。" xml:space="preserve"><value>This class occurrence already has a pending or approved adjustment.</value></data>
|
||||
<data name="目标日期必须在本学期起止日期内。" xml:space="preserve"><value>The target date must fall within the term.</value></data>
|
||||
<data name="目标教室不存在、已停用或正在维修。" xml:space="preserve"><value>The target room does not exist, is disabled or is under maintenance.</value></data>
|
||||
<data name="原课次已不在当前发布课表中,请退回后重新选择。" xml:space="preserve"><value>The original class is no longer on the published timetable. Return the request and select it again.</value></data>
|
||||
<data name="目标上课日期或节次不完整。" xml:space="preserve"><value>The target class date or period is incomplete.</value></data>
|
||||
<data name="无法完成操作" xml:space="preserve"><value>The operation could not be completed</value></data>
|
||||
<data name="ClassroomReservations.Room.CapacityExceeded" xml:space="preserve"><value>The number of applicants exceeds the room capacity of {0}.</value></data>
|
||||
<data name="ClassroomReservations.Review.ApplicantCountExceedsCapacity" xml:space="preserve"><value>The number of applicants exceeds the current room capacity, so the reservation cannot be approved.</value></data>
|
||||
<data name="ClassroomReservations.Date.CannotBeInPast" xml:space="preserve"><value>The reservation date cannot be in the past.</value></data>
|
||||
<data name="ClassroomReservations.Date.OutsideTerm" xml:space="preserve"><value>The reservation date is outside the selected term.</value></data>
|
||||
</root>
|
||||
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user