This commit is contained in:
1 parent
cdb4637c65
commit
f0c0479bcb
22 files changed
+1099
-76
No files matched your search
@@ -21,6 +21,12 @@ public sealed record UntisTimetablePeriodDto(int Id, int Date, int StartTime, in
|
||||
string? ActivityType, string? Info, string? LessonText, string? SubstitutionText, string? StudentGroup,
|
||||
IReadOnlyList<UntisEntityDto> Classes, IReadOnlyList<UntisEntityDto> Teachers,
|
||||
IReadOnlyList<UntisEntityDto> Subjects, IReadOnlyList<UntisEntityDto> Rooms);
|
||||
public sealed record UntisGridResourceDto(string Type, string? Status, string? ShortName, string? LongName,
|
||||
string? DisplayName);
|
||||
public sealed record UntisGridResourceChangeDto(UntisGridResourceDto? Current, UntisGridResourceDto? Removed);
|
||||
public sealed record UntisTimetableGridEntryDto(IReadOnlyList<int> Ids, DateTime Start, DateTime End, string Type,
|
||||
string? Status, string? StatusDetail, string? Name, string? LessonText, string? LessonInfo,
|
||||
string? SubstitutionText, IReadOnlyList<UntisGridResourceChangeDto> Resources);
|
||||
public sealed record UntisStudentAddressDto(string? Email, string? Mobile, string? Phone, string? City,
|
||||
string? PostCode, string? Street);
|
||||
public sealed record UntisStudentDto(int UntisId, int? ExternKey, string ClassName, string? Name, string? LongName,
|
||||
@@ -108,6 +114,31 @@ public sealed class WebUntisIntegrationService(HttpClient http, WebUntisSettings
|
||||
x.ActivityType, x.Info, x.LessonText, x.SubstitutionText, x.StudentGroup,
|
||||
Entities(x.Classes), Entities(x.Teachers), Entities(x.Subjects), Entities(x.Rooms))).ToList(), token);
|
||||
|
||||
public Task<IReadOnlyList<UntisTimetableGridEntryDto>> GetOwnTimetableGridAsync(DateOnly start, DateOnly end,
|
||||
CancellationToken token = default) => ExecuteAsync(async client =>
|
||||
{
|
||||
var years = await client.GetSchoolYearsAsync(token);
|
||||
var numericStart = Date(start);
|
||||
var year = years.FirstOrDefault(item => item.StartDate <= numericStart && item.EndDate >= numericStart)
|
||||
?? throw new WebUntisException("WebUntis hat für den REST-Stundenplan kein passendes Schuljahr geliefert.");
|
||||
return await GridEntries(client, year.UntisId, start, end, token);
|
||||
}, token);
|
||||
|
||||
public Task<IReadOnlyList<UntisTimetableGridEntryDto>> GetOwnTimetableGridAsync(int schoolYearId,
|
||||
DateOnly start, DateOnly end, CancellationToken token = default) => ExecuteAsync(
|
||||
client => GridEntries(client, schoolYearId, start, end, token), token);
|
||||
|
||||
private static async Task<IReadOnlyList<UntisTimetableGridEntryDto>> GridEntries(WebUntisClient client,
|
||||
int schoolYearId, DateOnly start, DateOnly end, CancellationToken token)
|
||||
{
|
||||
var entries = await client.GetOwnTimetableGridAsync(schoolYearId, start, end, token);
|
||||
return (IReadOnlyList<UntisTimetableGridEntryDto>)entries.Select(entry => new UntisTimetableGridEntryDto(
|
||||
entry.Ids, entry.Start, entry.End, entry.Type, entry.Status, entry.StatusDetail, entry.Name,
|
||||
entry.LessonText, entry.LessonInfo, entry.SubstitutionText,
|
||||
entry.Resources.Select(change => new UntisGridResourceChangeDto(
|
||||
GridResource(change.Current), GridResource(change.Removed))).ToList())).ToList();
|
||||
}
|
||||
|
||||
public Task<UntisStudentReportDto> GetStudentsAsync(string className, CancellationToken token = default) => ExecuteAsync(
|
||||
async client =>
|
||||
{
|
||||
@@ -241,6 +272,8 @@ public sealed class WebUntisIntegrationService(HttpClient http, WebUntisSettings
|
||||
private static int Date(DateOnly date) => date.Year * 10000 + date.Month * 100 + date.Day;
|
||||
private static IReadOnlyList<UntisEntityDto> Entities(IReadOnlyList<UntisEntity> values) => values
|
||||
.Select(x => new UntisEntityDto(x.Id, x.Name, x.OriginalId, x.OriginalName, x.ExternalKey)).ToList();
|
||||
private static UntisGridResourceDto? GridResource(UntisGridResource? value) => value is null ? null
|
||||
: new UntisGridResourceDto(value.Type, value.Status, value.ShortName, value.LongName, value.DisplayName);
|
||||
private static bool IsUntisError(Exception exception) => exception is WebUntisException
|
||||
or WebUntisConfigurationException or InvalidDataException;
|
||||
private static WebUntisIntegrationException Translate(Exception exception) =>
|
||||
|
||||
Reference in new issue
Block a user