diff --git a/SpotiParty.AppHost/AppHost.cs b/SpotiParty.AppHost/AppHost.cs
index 180f365..af99f1e 100644
--- a/SpotiParty.AppHost/AppHost.cs
+++ b/SpotiParty.AppHost/AppHost.cs
@@ -3,7 +3,7 @@ using Projects;
var builder = DistributedApplication.CreateBuilder(args);
var dbServer = builder.AddPostgres("database")
- .WithDataVolume("database-data");
+ .WithDataVolume();
var database = dbServer.AddDatabase("SpotiParty");
diff --git a/SpotiParty.Web/Components/Pages/EnqueuePage.razor b/SpotiParty.Web/Components/Pages/EnqueuePage.razor
index 01a00d1..313dcc3 100644
--- a/SpotiParty.Web/Components/Pages/EnqueuePage.razor
+++ b/SpotiParty.Web/Components/Pages/EnqueuePage.razor
@@ -1,4 +1,4 @@
-@page "/enqueue/{userid}"
+@page "/enqueue/{eventId}"
@using SpotiParty.Web.Components.Components
@rendermode InteractiveServer
diff --git a/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs b/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs
index 5d7b76d..637bd6d 100644
--- a/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs
+++ b/SpotiParty.Web/Components/Pages/EnqueuePage.razor.cs
@@ -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);
diff --git a/SpotiParty.Web/Migrations/20251130141048_Initial.Designer.cs b/SpotiParty.Web/Migrations/20251130141048_Initial.Designer.cs
deleted file mode 100644
index a6212ea..0000000
--- a/SpotiParty.Web/Migrations/20251130141048_Initial.Designer.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-//
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using SpotiParty.Web;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- [DbContext(typeof(DatabaseContext))]
- [Migration("20251130141048_Initial")]
- partial class Initial
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "10.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
- {
- b.Property("UserId")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("DisplayName")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("RefreshToken")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.HasKey("UserId");
-
- b.ToTable("Users");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130141048_Initial.cs b/SpotiParty.Web/Migrations/20251130141048_Initial.cs
deleted file mode 100644
index e17be45..0000000
--- a/SpotiParty.Web/Migrations/20251130141048_Initial.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- ///
- public partial class Initial : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "Users",
- columns: table => new
- {
- UserId = table.Column(type: "uuid", nullable: false),
- DisplayName = table.Column(type: "character varying(255)", maxLength: 255, nullable: false),
- RefreshToken = table.Column(type: "character varying(255)", maxLength: 255, nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Users", x => x.UserId);
- });
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "Users");
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.Designer.cs b/SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.Designer.cs
deleted file mode 100644
index 88af478..0000000
--- a/SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.Designer.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-//
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using SpotiParty.Web;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- [DbContext(typeof(DatabaseContext))]
- [Migration("20251130142549_Added Spotify Id")]
- partial class AddedSpotifyId
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "10.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
- {
- b.Property("UserId")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("DisplayName")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("RefreshToken")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("SpotifyUserId")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.HasKey("UserId");
-
- b.ToTable("Users");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.cs b/SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.cs
deleted file mode 100644
index 3be1837..0000000
--- a/SpotiParty.Web/Migrations/20251130142549_Added Spotify Id.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- ///
- public partial class AddedSpotifyId : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AddColumn(
- name: "SpotifyUserId",
- table: "Users",
- type: "character varying(255)",
- maxLength: 255,
- nullable: false,
- defaultValue: "");
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropColumn(
- name: "SpotifyUserId",
- table: "Users");
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130170930_Added admin property.Designer.cs b/SpotiParty.Web/Migrations/20251130170930_Added admin property.Designer.cs
deleted file mode 100644
index b2f6d2f..0000000
--- a/SpotiParty.Web/Migrations/20251130170930_Added admin property.Designer.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-//
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using SpotiParty.Web;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- [DbContext(typeof(DatabaseContext))]
- [Migration("20251130170930_Added admin property")]
- partial class Addedadminproperty
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "10.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
- {
- b.Property("UserId")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("DisplayName")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("IsAdmin")
- .HasColumnType("boolean");
-
- b.Property("RefreshToken")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("SpotifyUserId")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.HasKey("UserId");
-
- b.ToTable("Users");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130170930_Added admin property.cs b/SpotiParty.Web/Migrations/20251130170930_Added admin property.cs
deleted file mode 100644
index bb8e788..0000000
--- a/SpotiParty.Web/Migrations/20251130170930_Added admin property.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Microsoft.EntityFrameworkCore.Migrations;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- ///
- public partial class Addedadminproperty : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.AddColumn(
- name: "IsAdmin",
- table: "Users",
- type: "boolean",
- nullable: false,
- defaultValue: false);
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropColumn(
- name: "IsAdmin",
- table: "Users");
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130175629_Added events.Designer.cs b/SpotiParty.Web/Migrations/20251130175629_Added events.Designer.cs
deleted file mode 100644
index 9776baa..0000000
--- a/SpotiParty.Web/Migrations/20251130175629_Added events.Designer.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-//
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using SpotiParty.Web;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- [DbContext(typeof(DatabaseContext))]
- [Migration("20251130175629_Added events")]
- partial class Addedevents
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "10.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
-
- b.Property("End")
- .HasColumnType("timestamp with time zone");
-
- b.Property("HostUserId")
- .HasColumnType("uuid");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("Start")
- .HasColumnType("timestamp with time zone");
-
- b.HasKey("Id");
-
- b.HasIndex("HostUserId");
-
- b.ToTable("Events");
- });
-
- modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
- {
- b.Property("UserId")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("DisplayName")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("IsAdmin")
- .HasColumnType("boolean");
-
- b.Property("RefreshToken")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("SpotifyUserId")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.HasKey("UserId");
-
- b.ToTable("Users");
- });
-
- modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
- {
- b.HasOne("SpotiParty.Web.Models.User", "Host")
- .WithMany()
- .HasForeignKey("HostUserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Host");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/20251130175629_Added events.cs b/SpotiParty.Web/Migrations/20251130175629_Added events.cs
deleted file mode 100644
index d0713f8..0000000
--- a/SpotiParty.Web/Migrations/20251130175629_Added events.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using System;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- ///
- public partial class Addedevents : Migration
- {
- ///
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "Events",
- columns: table => new
- {
- Id = table.Column(type: "integer", nullable: false)
- .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
- HostUserId = table.Column(type: "uuid", nullable: false),
- Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false),
- Start = table.Column(type: "timestamp with time zone", nullable: false),
- End = table.Column(type: "timestamp with time zone", nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_Events", x => x.Id);
- table.ForeignKey(
- name: "FK_Events_Users_HostUserId",
- column: x => x.HostUserId,
- principalTable: "Users",
- principalColumn: "UserId",
- onDelete: ReferentialAction.Cascade);
- });
-
- migrationBuilder.CreateIndex(
- name: "IX_Events_HostUserId",
- table: "Events",
- column: "HostUserId");
- }
-
- ///
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "Events");
- }
- }
-}
diff --git a/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs b/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs
deleted file mode 100644
index dee540f..0000000
--- a/SpotiParty.Web/Migrations/DatabaseContextModelSnapshot.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-//
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
-using SpotiParty.Web;
-
-#nullable disable
-
-namespace SpotiParty.Web.Migrations
-{
- [DbContext(typeof(DatabaseContext))]
- partial class DatabaseContextModelSnapshot : ModelSnapshot
- {
- protected override void BuildModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "10.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 63);
-
- NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
-
- modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
- {
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("integer");
-
- NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
-
- b.Property("End")
- .HasColumnType("timestamp with time zone");
-
- b.Property("HostUserId")
- .HasColumnType("uuid");
-
- b.Property("Name")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("Start")
- .HasColumnType("timestamp with time zone");
-
- b.HasKey("Id");
-
- b.HasIndex("HostUserId");
-
- b.ToTable("Events");
- });
-
- modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
- {
- b.Property("UserId")
- .ValueGeneratedOnAdd()
- .HasColumnType("uuid");
-
- b.Property("DisplayName")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("IsAdmin")
- .HasColumnType("boolean");
-
- b.Property("RefreshToken")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.Property("SpotifyUserId")
- .IsRequired()
- .HasMaxLength(255)
- .HasColumnType("character varying(255)");
-
- b.HasKey("UserId");
-
- b.ToTable("Users");
- });
-
- modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>
- {
- b.HasOne("SpotiParty.Web.Models.User", "Host")
- .WithMany()
- .HasForeignKey("HostUserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.Navigation("Host");
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/SpotiParty.Web/Models/Event.cs b/SpotiParty.Web/Models/Event.cs
index df118d2..a7b9ee3 100644
--- a/SpotiParty.Web/Models/Event.cs
+++ b/SpotiParty.Web/Models/Event.cs
@@ -1,18 +1,17 @@
using System.ComponentModel.DataAnnotations;
-using System.ComponentModel.DataAnnotations.Schema;
namespace SpotiParty.Web.Models;
public class Event {
- [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
- public int Id { get; init; }
+ [Key]
+ public Guid Id { get; init; } = Guid.CreateVersion7();
- public required User Host { get; init; }
+ public required User Host { get; set; }
[MaxLength(255)]
public required string Name { get; set; }
- public DateTime Start { get; set; }
+ public DateTime Start { get; set; } = DateTime.Today;
- public DateTime End { get; set; }
+ public DateTime End { get; set; } = DateTime.Today + TimeSpan.FromDays(1);
}
\ No newline at end of file
diff --git a/SpotiParty.Web/Program.cs b/SpotiParty.Web/Program.cs
index d00a87e..8ac0ee7 100644
--- a/SpotiParty.Web/Program.cs
+++ b/SpotiParty.Web/Program.cs
@@ -1,3 +1,4 @@
+using HopFrame.Core.Callbacks;
using HopFrame.Core.Services;
using HopFrame.Web;
using Microsoft.EntityFrameworkCore;
@@ -14,6 +15,9 @@ builder.Services.AddRazorComponents()
builder.AddServiceDefaults();
+AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
+AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
+
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped();
builder.AddNpgsqlDbContext("SpotiParty");
@@ -23,6 +27,8 @@ builder.Services.AddDbContextFactory(options => {
builder.Services.AddScoped();
builder.Services.AddScoped();
+builder.Services.AddScoped();
+builder.Services.AddScoped();
builder.Services.AddHopFrame(config => {
config.SetLoginPage("/login");
@@ -42,12 +48,29 @@ builder.Services.AddHopFrame(config => {
table.ShowSearchSuggestions(false);
});
- context.Table(table => {
- table.Property(e => e.Id)
- .List(false)
- .SetEditable(false);
+ context.Table()
+ .Ignore(true);
+ });
- table.ShowSearchSuggestions(false);
+ config.AddCustomRepository(e => e.Id, table => {
+ //table.SetDisplayName("Events");
+
+ table.Property(e => e.Id)
+ .List(false)
+ .SetEditable(false)
+ .SetCreatable(false);
+
+ table.Property(e => e.Host)
+ .SetEditable(false)
+ .SetCreatable(false)
+ .SetDisplayedProperty(u => u.DisplayName);
+
+ table.ShowSearchSuggestions(false);
+
+ table.AddCallbackHandler(CallbackType.CreateEntry, async (entry, services) => {
+ var auth = services.GetRequiredService();
+ var user = await auth.GetCurrentUser();
+ entry.Host = user!;
});
});
});
diff --git a/SpotiParty.Web/Services/DashboardAuthHandler.cs b/SpotiParty.Web/Services/DashboardAuthHandler.cs
index 05a7800..ced6f4c 100644
--- a/SpotiParty.Web/Services/DashboardAuthHandler.cs
+++ b/SpotiParty.Web/Services/DashboardAuthHandler.cs
@@ -1,5 +1,6 @@
using HopFrame.Core.Services;
using Microsoft.EntityFrameworkCore;
+using SpotiParty.Web.Models;
namespace SpotiParty.Web.Services;
@@ -8,14 +9,10 @@ public class DashboardAuthHandler(ClientSideStorage storage, IDbContextFactory IsAuthenticatedAsync(string? policy) {
- var token = storage.GetUserToken();
- if (string.IsNullOrWhiteSpace(token))
+ var user = await GetCurrentUser();
+ if (user is null)
return false;
- await using var context = await contextFactory.CreateDbContextAsync();
- var user = await context.Users.AsNoTracking().FirstOrDefaultAsync(u => u.RefreshToken == token);
- if (user is null) return false;
-
if (policy == AdminPolicy) {
return user.IsAdmin;
}
@@ -34,4 +31,14 @@ public class DashboardAuthHandler(ClientSideStorage storage, IDbContextFactory GetCurrentUser() {
+ var token = storage.GetUserToken();
+ if (string.IsNullOrWhiteSpace(token))
+ return null;
+
+ await using var context = await contextFactory.CreateDbContextAsync();
+ return await context.Users.AsNoTracking().FirstOrDefaultAsync(u => u.RefreshToken == token);
+ }
+
}
\ No newline at end of file
diff --git a/SpotiParty.Web/Services/EventsDashboardRepo.cs b/SpotiParty.Web/Services/EventsDashboardRepo.cs
new file mode 100644
index 0000000..52475ce
--- /dev/null
+++ b/SpotiParty.Web/Services/EventsDashboardRepo.cs
@@ -0,0 +1,49 @@
+using HopFrame.Core.Repositories;
+using Microsoft.EntityFrameworkCore;
+using SpotiParty.Web.Models;
+
+namespace SpotiParty.Web.Services;
+
+public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler handler) : IHopFrameRepository {
+ public async Task> LoadPage(int page, int perPage) {
+ var user = await handler.GetCurrentUser();
+ if (user is null) return [];
+
+ return await context.Events
+ .AsNoTracking()
+ .Include(e => e.Host)
+ .Where(e => e.Host.UserId == user.UserId)
+ .Skip(page * perPage)
+ .Take(perPage)
+ .ToListAsync();
+ }
+
+ public async Task> Search(string searchTerm, int page, int perPage) {
+ var entries = await LoadPage(page, perPage);
+ return new(entries, await GetTotalPageCount(perPage));
+ }
+
+ public async Task GetTotalPageCount(int perPage) {
+ double count = await context.Events.CountAsync();
+ return Convert.ToInt32(Math.Ceiling(count / perPage));
+ }
+
+ public async Task CreateItem(Event item) {
+ await context.Events.AddAsync(item);
+ await context.SaveChangesAsync();
+ }
+
+ public async Task EditItem(Event item) {
+ context.Events.Update(item);
+ await context.SaveChangesAsync();
+ }
+
+ public async Task DeleteItem(Event item) {
+ context.Events.Remove(item);
+ await context.SaveChangesAsync();
+ }
+
+ public async Task GetOne(Guid key) {
+ return await context.Events.FindAsync(key);
+ }
+}
\ No newline at end of file
diff --git a/SpotiParty.Web/SpotiParty.Web.csproj b/SpotiParty.Web/SpotiParty.Web.csproj
index 5b81409..fdd4d21 100644
--- a/SpotiParty.Web/SpotiParty.Web.csproj
+++ b/SpotiParty.Web/SpotiParty.Web.csproj
@@ -83,4 +83,8 @@
+
+
+
+
diff --git a/SpotiParty.sln.DotSettings.user b/SpotiParty.sln.DotSettings.user
index 92a7f3d..39a1eca 100644
--- a/SpotiParty.sln.DotSettings.user
+++ b/SpotiParty.sln.DotSettings.user
@@ -2,5 +2,6 @@
ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
ForceIncluded
ForceIncluded
\ No newline at end of file