Featured post

This commit is contained in:
2025-07-31 11:27:52 +08:00
parent 8e6e3e6289
commit 49fe70b0aa
2 changed files with 21 additions and 4 deletions

View File

@@ -119,7 +119,8 @@ public class PostController(
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
{ AccountId = currentUser.Id });
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
}
}
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
var queryable = db.Posts
@@ -150,6 +151,22 @@ public class PostController(
return Ok(posts);
}
[HttpGet("{id:guid}/replies/featured")]
public async Task<ActionResult<Post>> GetFeaturedReply(Guid id)
{
var now = SystemClock.Instance.GetCurrentInstant();
var post = await db.Posts
.Where(e => e.RepliedPostId == id)
.OrderByDescending(p =>
p.Upvotes * 2 -
p.Downvotes +
((p.CreatedAt - now).TotalMinutes < 60 ? 5 : 0)
)
.FirstOrDefaultAsync();
if (post is null) return NotFound();
return await ps.LoadPostInfo(post);
}
[HttpGet("{id:guid}/replies")]
public async Task<ActionResult<List<Post>>> ListReplies(Guid id, [FromQuery] int offset = 0,
[FromQuery] int take = 20)