Marking views

This commit is contained in:
2025-06-19 23:54:25 +08:00
parent eb1c283971
commit cfa63c7c93
6 changed files with 130 additions and 1 deletions

View File

@ -58,9 +58,21 @@ public class PostController(
var postsId = posts.Select(e => e.Id).ToList();
var reactionMaps = await ps.GetPostReactionMapBatch(postsId);
foreach (var post in posts)
{
post.ReactionsCount =
reactionMaps.TryGetValue(post.Id, out var count) ? count : new Dictionary<string, int>();
// Track view for each post in the list
if (currentUser != null)
{
await ps.IncreaseViewCount(post.Id, currentUser.Id.ToString());
}
else
{
await ps.IncreaseViewCount(post.Id);
}
}
Response.Headers["X-Total"] = totalCount.ToString();
return Ok(posts);
@ -85,6 +97,9 @@ public class PostController(
post.ReactionsCount = await ps.GetPostReactionMap(post.Id);
// Track view - use the account ID as viewer ID if user is logged in
await ps.IncreaseViewCount(post.Id, currentUser?.Id.ToString());
return Ok(post);
}