fixed User Page not loading articles correctly

This commit is contained in:
Mia Rose Winter 2024-04-19 19:06:09 +02:00
parent a204191eaf
commit 2e3bcc577e
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -89,6 +89,7 @@
private ApplicationUser? User { get; set; } private ApplicationUser? User { get; set; }
protected override async Task OnInitializedAsync() { protected override async Task OnInitializedAsync() {
if (User is not null) return;
await using var context = await ContextFactory.CreateDbContextAsync(); await using var context = await ContextFactory.CreateDbContextAsync();
// Find user // Find user
@ -96,13 +97,13 @@
var now = DateTimeOffset.UtcNow; var now = DateTimeOffset.UtcNow;
User = await context.Users User = await context.Users
.IgnoreAutoIncludes().IgnoreQueryFilters() .IgnoreAutoIncludes().IgnoreQueryFilters()
.Include(u => u.Articles.Where(a => !a.IsDeleted && a.PublishDate <= now)) .Include(u => u.Articles
.Where(a => !a.IsDeleted &&
a.Status == ArticleStatus.Published &&
a.PublishDate <= now))
.ThenInclude(a => a.Categories)
.AsSplitQuery()
.FirstOrDefaultAsync(u => u.Id == Id.ToString()); .FirstOrDefaultAsync(u => u.Id == Id.ToString());
await context.Set<Article>()
.Where(a => a.Author.Id == Id.ToString())
.Select(a => new {
a.Id, a.Categories
}).LoadAsync();
} }
// Validate access to user // Validate access to user