Calendar that show all events that we joined
This commit is contained in:
Witkopawel
2025-06-02 07:11:30 +02:00
parent 9de5c85120
commit a8d706bf97
8 changed files with 185 additions and 65 deletions

View File

@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.EntityFrameworkCore;
using System.Security.Cryptography;
@@ -128,7 +128,26 @@ namespace WebApp.Endpoints
return Results.Json(new { success = true });
});
group.MapGet("/registered",
async (ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
{
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
User? user = await guhf.GetUserFromToken(token);
if (user is null || user.IsOrganisation)
return Results.Json(new { success = false, error_msg = "Unauthorized or organisations cannot register." });
var events = await dbContext.EventRegistrations
.Where(r => r.UserId == user.UserId)
.Select(r => new {
r.Event.EventId,
r.Event.Title,
r.Event.EventDate
})
.ToListAsync();
return Results.Json(events);
});
return group;
}
}