🐛 Fix bugs

This commit is contained in:
2025-04-23 00:30:25 +08:00
parent c43ff6be7b
commit 31db3d5388
6 changed files with 39 additions and 11 deletions

View File

@ -20,12 +20,15 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer)
.CountAsync();
var posts = await db.Posts
.Include(e => e.Publisher)
.Include(e => e.Publisher.Picture)
.Include(e => e.Publisher.Background)
.Include(e => e.ThreadedPost)
.Include(e => e.ForwardedPost)
.Include(e => e.Attachments)
.Include(e => e.Categories)
.Include(e => e.Tags)
.FilterWithVisibility(currentUser, isListing: true)
.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt)
.Skip(offset)
.Take(take)
.ToListAsync();
@ -44,6 +47,8 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer)
var post = await db.Posts
.Where(e => e.Id == id)
.Include(e => e.Publisher)
.Include(e => e.Publisher.Picture)
.Include(e => e.Publisher.Background)
.Include(e => e.RepliedPost)
.Include(e => e.ThreadedPost)
.Include(e => e.ForwardedPost)
@ -75,12 +80,15 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer)
var posts = await db.Posts
.Where(e => e.RepliedPostId == id)
.Include(e => e.Publisher)
.Include(e => e.Publisher.Picture)
.Include(e => e.Publisher.Background)
.Include(e => e.ThreadedPost)
.Include(e => e.ForwardedPost)
.Include(e => e.Attachments)
.Include(e => e.Categories)
.Include(e => e.Tags)
.FilterWithVisibility(currentUser, isListing: true)
.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt)
.Skip(offset)
.Take(take)
.ToListAsync();
@ -172,6 +180,8 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer)
var post = await db.Posts
.Where(e => e.Id == id)
.Include(e => e.Publisher)
.Include(e => e.Publisher.Picture)
.Include(e => e.Publisher.Background)
.Include(e => e.Attachments)
.Include(e => e.Categories)
.Include(e => e.Tags)

View File

@ -18,7 +18,11 @@ public class PostService(AppDatabase db, FileService fs)
if (post.PublishedAt.Value.ToDateTimeUtc() < DateTime.UtcNow)
throw new InvalidOperationException("Cannot create the post which published in the past.");
}
else
{
post.PublishedAt = Instant.FromDateTimeUtc(DateTime.UtcNow);
}
if (attachments is not null)
{
post.Attachments = await db.Files.Where(e => attachments.Contains(e.Id)).ToListAsync();