- Bumped the wire protocol version to 6, reflecting changes in the communication structure.
- Expanded the timetable API with new endpoints for fetching and managing lesson schedules, including `GET /api/schools/{id}/timetable` and `POST /api/schools/{id}/timetable/pin`.
- Updated the protocol documentation to include detailed descriptions of the new timetable features and message structures.
- Enhanced the client-side implementation to support the new timetable functionalities, including lesson pinning and unpinning.
- Revised server-side logic to handle timetable operations and ensure proper integration with existing school management features.
- Added tests to validate the new timetable functionalities and ensure robustness in handling lesson data.
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using HSchool.Content;
|
|
|
|
namespace HSchool.Schedule;
|
|
|
|
/// <summary>
|
|
/// Which lessons are happening at a game instant. Breaks, nights, weekends and holidays are empty
|
|
/// — occupancy is derived, never stored.
|
|
/// </summary>
|
|
public static class TimetableClock
|
|
{
|
|
public static IReadOnlyList<LessonPlacement> OccurringAt(
|
|
Timetable table,
|
|
DefCatalog catalog,
|
|
DateTime time,
|
|
int weekDays)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(table);
|
|
var slot = SchoolDay.At(catalog, time, weekDays);
|
|
if (slot.Kind != DaySlotKind.Lesson)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
var day = SchoolDay.WeekdayIndex(time);
|
|
return table.Lessons
|
|
.Where(lesson => lesson.Day == day && lesson.Period == slot.Index)
|
|
.ToArray();
|
|
}
|
|
|
|
public static OccupancyKey Key(DefCatalog catalog, DateTime time, int weekDays)
|
|
{
|
|
var utc = DateTime.SpecifyKind(time, DateTimeKind.Utc);
|
|
var slot = SchoolDay.At(catalog, utc, weekDays);
|
|
return new OccupancyKey(DateOnly.FromDateTime(utc), slot.Kind, slot.Index);
|
|
}
|
|
}
|
|
|
|
public readonly record struct OccupancyKey(DateOnly Day, DaySlotKind Kind, int Index);
|