Compare commits
23
Commits
No files matched your search
Submodule Academic-Affairs-System.wiki updated: 36984e720f...4dafcd42a2.
@@ -170,6 +170,25 @@ public sealed class CourseAdjustmentsController(
|
|||||||
return Ok(new { Task = task, Sessions = sessions, Classrooms = classrooms, Periods = periods });
|
return Ok(new { Task = task, Sessions = sessions, Classrooms = classrooms, Periods = periods });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("teacher-options")]
|
||||||
|
[Authorize(Roles = Applicants)]
|
||||||
|
public async Task<ActionResult> GetTeacherOptions(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Ok(await db.Teachers.AsNoTracking()
|
||||||
|
.Where(x => x.Status == TeacherStatus.Active && !x.IsArchived)
|
||||||
|
.OrderBy(x => x.College!.Name)
|
||||||
|
.ThenBy(x => x.TeacherNumber)
|
||||||
|
.Select(x => new
|
||||||
|
{
|
||||||
|
x.Id,
|
||||||
|
x.TeacherNumber,
|
||||||
|
x.Name,
|
||||||
|
x.Title,
|
||||||
|
CollegeName = x.College!.Name
|
||||||
|
})
|
||||||
|
.ToListAsync(cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════════ My adjustments ═══════════════
|
// ═══════════════ My adjustments ═══════════════
|
||||||
|
|
||||||
[HttpGet("mine")]
|
[HttpGet("mine")]
|
||||||
@@ -611,7 +630,8 @@ public sealed class CourseAdjustmentsController(
|
|||||||
return ValidationProblem("请选择代课教师。");
|
return ValidationProblem("请选择代课教师。");
|
||||||
if (!await db.Teachers.AnyAsync(x =>
|
if (!await db.Teachers.AnyAsync(x =>
|
||||||
x.Id == request.SubstituteTeacherId &&
|
x.Id == request.SubstituteTeacherId &&
|
||||||
x.Status == TeacherStatus.Active, cancellationToken))
|
x.Status == TeacherStatus.Active &&
|
||||||
|
!x.IsArchived, cancellationToken))
|
||||||
return ValidationProblem("代课教师不存在或已离职。");
|
return ValidationProblem("代课教师不存在或已离职。");
|
||||||
break;
|
break;
|
||||||
case CourseAdjustmentType.Cancel:
|
case CourseAdjustmentType.Cancel:
|
||||||
|
|||||||
@@ -6,11 +6,46 @@ using Jiaowu.Api.Infrastructure.Persistence;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Jiaowu.Api.Tests;
|
namespace Jiaowu.Api.Tests;
|
||||||
|
|
||||||
public sealed class CourseAdjustmentsControllerTests
|
public sealed class CourseAdjustmentsControllerTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task TeacherOptions_ReturnOnlyActiveNonArchivedTeachers()
|
||||||
|
{
|
||||||
|
await using var fixture = await Fixture.CreateAsync();
|
||||||
|
var collegeId = await fixture.Db.Courses.Select(x => x.CollegeId).SingleAsync();
|
||||||
|
fixture.Db.Teachers.AddRange(
|
||||||
|
new Teacher
|
||||||
|
{
|
||||||
|
TeacherNumber = "T002",
|
||||||
|
Name = "离职教师",
|
||||||
|
CollegeId = collegeId,
|
||||||
|
Status = TeacherStatus.Retired
|
||||||
|
},
|
||||||
|
new Teacher
|
||||||
|
{
|
||||||
|
TeacherNumber = "T003",
|
||||||
|
Name = "归档教师",
|
||||||
|
CollegeId = collegeId,
|
||||||
|
IsArchived = true
|
||||||
|
});
|
||||||
|
await fixture.Db.SaveChangesAsync();
|
||||||
|
|
||||||
|
var controller = new CourseAdjustmentsController(
|
||||||
|
fixture.Db,
|
||||||
|
new TestScope(fixture.TeacherUserId, DataScope.Self, SystemRoles.Teacher));
|
||||||
|
var result = await controller.GetTeacherOptions(CancellationToken.None);
|
||||||
|
|
||||||
|
var ok = Assert.IsType<OkObjectResult>(result);
|
||||||
|
var json = JsonSerializer.Serialize(ok.Value);
|
||||||
|
Assert.Contains("T001", json);
|
||||||
|
Assert.DoesNotContain("T002", json);
|
||||||
|
Assert.DoesNotContain("T003", json);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Reschedule_MovesOnlyTheSelectedOccurrence()
|
public async Task Reschedule_MovesOnlyTheSelectedOccurrence()
|
||||||
{
|
{
|
||||||
|
|||||||
Loaded 3 of 68 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user