Fixed user reference problem in event creation

This commit is contained in:
2026-01-19 20:39:18 +01:00
parent e937cecc81
commit dd1cfc15e5
6 changed files with 15 additions and 13 deletions

View File

@@ -32,7 +32,7 @@ public partial class EnqueuePage(AuthorizationHandler authHandler, NavigationMan
}
_event = await context.Events
.Include(e => e.Host)
.Include(@event => @event.Host)
.FirstOrDefaultAsync(e => e.Id == guid);
if (_event is null) {

View File

@@ -46,7 +46,7 @@ namespace SpotiParty.Web.Migrations
b.HasIndex("host");
b.ToTable("Events");
b.ToTable("Events", (string)null);
});
modelBuilder.Entity("SpotiParty.Web.Models.User", b =>
@@ -75,7 +75,7 @@ namespace SpotiParty.Web.Migrations
b.HasKey("UserId");
b.ToTable("Users");
b.ToTable("Users", (string)null);
});
modelBuilder.Entity("SpotiParty.Web.Models.Event", b =>

View File

@@ -48,8 +48,7 @@ builder.Services.AddHopFrame(config => {
});
context.Table<Event>()
.SetDisplayName(Guid.NewGuid().ToString())
.Ignore(true);
.Ignore();
});
config.AddCustomRepository<EventsDashboardRepo, Event, Guid>(e => e.Id, table => {
@@ -63,8 +62,7 @@ builder.Services.AddHopFrame(config => {
table.Property(e => e.Host)
.List(false)
.SetEditable(false)
.SetCreatable(false)
.SetDisplayedProperty(u => u.DisplayName);
.SetCreatable(false);
table.ShowSearchSuggestions(false);
});

View File

@@ -38,6 +38,7 @@ public class DashboardAuthHandler(ClientSideStorage storage, IDbContextFactory<D
return null;
await using var context = await contextFactory.CreateDbContextAsync();
return await context.Users.AsNoTracking().FirstOrDefaultAsync(u => u.RefreshToken == token);
}

View File

@@ -4,14 +4,15 @@ using SpotiParty.Web.Models;
namespace SpotiParty.Web.Services;
public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler handler) : IHopFrameRepository<Event, Guid> {
public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler handler, IDbContextFactory<DatabaseContext> factory) : IHopFrameRepository<Event, Guid> {
public async Task<IEnumerable<Event>> LoadPage(int page, int perPage) {
var user = await handler.GetCurrentUser();
if (user is null) return [];
return await context.Events
.AsNoTracking()
.Include(e => e.Host)
.OrderBy(e => e.Id)
.Where(e => e.Host.UserId == user.UserId)
.Skip(page * perPage)
.Take(perPage)
@@ -29,12 +30,14 @@ public class EventsDashboardRepo(DatabaseContext context, DashboardAuthHandler h
}
public async Task CreateItem(Event item) {
await using var tempContext = await factory.CreateDbContextAsync();
var creator = await handler.GetCurrentUser();
context.Attach(creator!);
tempContext.Attach(creator!);
item.Host = creator!;
await context.Events.AddAsync(item);
await context.SaveChangesAsync();
await tempContext.Events.AddAsync(item);
await tempContext.SaveChangesAsync();
}
public async Task EditItem(Event item) {

View File

@@ -20,7 +20,7 @@
<ItemGroup>
<PackageReference Include="Aspire.Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.5.2" />
<PackageReference Include="HopFrame.Web" Version="3.3.0" />
<PackageReference Include="HopFrame.Web" Version="3.3.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.12">
<PrivateAssets>all</PrivateAssets>