Skip to content

Commit da5c170

Browse files
authored
Merge pull request #2 from AngryKiller/feat/exam-accomodations
Implemented exam accommodations handling
2 parents d6c30f9 + 13d2d1e commit da5c170

12 files changed

Lines changed: 315 additions & 30 deletions

‎AurionCal.Api.csproj‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,25 @@
3131
</ItemGroup>
3232

3333
<ItemGroup>
34-
<Content Update="Templates\\**\\*">
34+
<Compile Remove="AurionCal.Tests/**" />
35+
<Content Remove="AurionCal.Tests/**" />
36+
<None Remove="AurionCal.Tests/**" />
37+
<EmbeddedResource Remove="AurionCal.Tests/**" />
38+
</ItemGroup>
39+
40+
<ItemGroup>
41+
<!--
42+
RazorLight templates are compiled at runtime, not at build time.
43+
Removing .cshtml files from Content prevents the SDK Razor source generator
44+
from picking them up, which would conflict with RazorLight's own Razor engine
45+
and produce duplicate assembly attributes (CS0579) and CS8785 warnings.
46+
-->
47+
<Content Remove="Templates\**\*.cshtml" />
48+
<None Include="Templates\**\*.cshtml">
3549
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3650
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
37-
</Content>
38-
39-
<None Update="Templates\\**\\*">
51+
</None>
52+
<None Update="Templates\**\*.cs">
4053
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4154
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
4255
</None>

‎Endpoints/GetCalendarFeedEndpoint.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public override async Task HandleAsync(GetCalendarFeedRequest r, CancellationTok
3030
.Include(u => u.RefreshStatus)
3131
.FirstOrDefaultAsync(u => u.Id == r.UserId, c);
3232

33+
3334
if (user == null || user.CalendarToken != r.Token)
3435
{
3536
await Send.NotFoundAsync(c);
@@ -58,7 +59,7 @@ public override async Task HandleAsync(GetCalendarFeedRequest r, CancellationTok
5859
}).ToList() ?? [];
5960
});
6061

61-
var feed = calendarService.GenerateCalendarFeed(planningEvents);
62+
var feed = calendarService.GenerateCalendarFeed(planningEvents, user.ExamAccommodations);
6263

6364
HttpContext.Response.Headers.Append("Content-Disposition", "attachment; filename=\"Planning Junia.ics\"");
6465
HttpContext.Response.ContentType = "text/calendar";

‎Endpoints/GetUserProfileEndpoint.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class UserProfileResponse
1111
public string Email { get; set; } = string.Empty;
1212
public string CalendarFeedUrl { get; set; } = string.Empty;
1313
public DateTime? LastUpdated { get; set; }
14+
public bool ExamAccommodations { get; set; }
1415
}
1516

1617
public class GetUserProfileEndpoint(ApplicationDbContext db, IConfiguration config) : EndpointWithoutRequest<UserProfileResponse>
@@ -49,7 +50,8 @@ public override async Task HandleAsync(CancellationToken ct)
4950
UserId = user.Id,
5051
Email = user.JuniaEmail,
5152
CalendarFeedUrl = calendarUrl,
52-
LastUpdated = user.LastUpdate ?? null
53+
LastUpdated = user.LastUpdate ?? null,
54+
ExamAccommodations = user.ExamAccommodations
5355
};
5456

5557
await Send.OkAsync(response, ct);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Security.Claims;
2+
using AurionCal.Api.Contexts;
3+
using FastEndpoints;
4+
using Microsoft.EntityFrameworkCore;
5+
6+
namespace AurionCal.Api.Endpoints;
7+
8+
public class SetExamAccommodationsRequest
9+
{
10+
public bool Enabled { get; set; }
11+
}
12+
13+
public class SetExamAccommodationsEndpoint(ApplicationDbContext db) : Endpoint<SetExamAccommodationsRequest>
14+
{
15+
public override void Configure()
16+
{
17+
Patch("/api/user/exam-accommodations");
18+
Claims("UserId");
19+
}
20+
21+
public override async Task HandleAsync(SetExamAccommodationsRequest r, CancellationToken ct)
22+
{
23+
var userIdValue = User.FindFirstValue("UserId");
24+
if (string.IsNullOrWhiteSpace(userIdValue) || !Guid.TryParse(userIdValue, out var userId))
25+
{
26+
await Send.UnauthorizedAsync(ct);
27+
return;
28+
}
29+
30+
var user = await db.Users.FirstOrDefaultAsync(u => u.Id == userId, ct);
31+
if (user is null)
32+
{
33+
await Send.NotFoundAsync(ct);
34+
return;
35+
}
36+
37+
user.ExamAccommodations = r.Enabled;
38+
await db.SaveChangesAsync(ct);
39+
await Send.OkAsync(ct);
40+
}
41+
}

‎Entities/User.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public class User
88
public DateTime? LastUpdate { get; set; }
99
public virtual List<CalendarEvent> Planning { get; set; }
1010
public Guid CalendarToken { get; set; }
11+
public bool ExamAccommodations { get; set; }
1112
public virtual UserRefreshStatus? RefreshStatus { get; set; }
1213
}

‎Enums/CourseTypes.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static class RawCourseTypes
77
public const string CoursTp = "TP";
88
public const string Projet = "PROJET";
99
public const string Epreuve = "est-epreuve";
10+
public const string EpreuveAlt = "EXAM_SURV";
1011
public const string AutoAppr = "AUTO_APPR";
1112
public const string Reunion = "REUNION";
1213
public const string Conference = "CONF";

‎Migrations/20260622000000_AddExamAccommodations.Designer.cs‎

Lines changed: 150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace AurionCal.Api.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class AddExamAccommodations : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.AddColumn<bool>(
14+
name: "ExamAccommodations",
15+
table: "Users",
16+
type: "boolean",
17+
nullable: false,
18+
defaultValue: false);
19+
}
20+
21+
/// <inheritdoc />
22+
protected override void Down(MigrationBuilder migrationBuilder)
23+
{
24+
migrationBuilder.DropColumn(
25+
name: "ExamAccommodations",
26+
table: "Users");
27+
}
28+
}
29+
}

‎Migrations/ApplicationDbContextModelSnapshot.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
6060
b.Property<Guid>("CalendarToken")
6161
.HasColumnType("uuid");
6262

63+
b.Property<bool>("ExamAccommodations")
64+
.HasColumnType("boolean");
65+
6366
b.Property<string>("JuniaEmail")
6467
.IsRequired()
6568
.HasColumnType("text");

‎Services/CalendarService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ private static TimeSpan ComputeBackoff(int consecutiveFailures)
175175
private static string Truncate(string value, int max)
176176
=> value.Length <= max ? value : value[..max];
177177

178-
public string GenerateCalendarFeed(IEnumerable<CalendarEvent> planningEvents)
178+
public string GenerateCalendarFeed(IEnumerable<CalendarEvent> planningEvents, bool examAccommodations = false)
179179
{
180180
var calendar = new Calendar();
181181
calendar.AddTimeZone(new VTimeZone("Europe/Paris"));
182182

183183
foreach (var evt in planningEvents)
184184
{
185-
calendar.Events.Add(CalendarEventFormatter.ToIcalEvent(evt));
185+
calendar.Events.Add(CalendarEventFormatter.ToIcalEvent(evt, examAccommodations));
186186
}
187187

188188
return new CalendarSerializer().SerializeToString(calendar);

0 commit comments

Comments
 (0)