Updaed event logic and event creation system

This commit is contained in:
2025-11-30 20:14:08 +01:00
parent 5d1fc1f347
commit 8d0573eb7e
18 changed files with 122 additions and 528 deletions

View File

@@ -1,13 +1,14 @@
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore;
using SpotifyAPI.Web;
using SpotiParty.Web.Services;
namespace SpotiParty.Web.Components.Pages;
public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationManager navigator) : ComponentBase {
public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationManager navigator, DatabaseContext context) : ComponentBase {
[Parameter]
public string UserId { get; set; } = string.Empty;
public string EventId { get; set; } = string.Empty;
private readonly int _currentYear = DateTime.Now.Year;
private SpotifyClient _client = null!;
@@ -22,12 +23,27 @@ public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationMan
protected override async Task OnInitializedAsync() {
await base.OnInitializedAsync();
if (!Guid.TryParse(UserId, out var guid)) {
if (!Guid.TryParse(EventId, out var guid)) {
navigator.NavigateTo("/", forceLoad: true);
return;
}
var eventEntry = await context.Events
.Include(e => e.Host)
.FirstOrDefaultAsync(e => e.Id == guid);
if (eventEntry is null) {
navigator.NavigateTo("/", forceLoad: true);
return;
}
var now = DateTime.Now;
if (eventEntry.Start > now || eventEntry.End < now) {
navigator.NavigateTo("/", forceLoad: true);
return;
}
var client = await authHandler.ConfigureClient(guid);
var client = await authHandler.ConfigureClient(eventEntry.Host.UserId);
if (client is null) {
navigator.NavigateTo("/", forceLoad: true);