🐛 Fixes for activities API

This commit is contained in:
2025-06-09 01:22:00 +08:00
parent f96de0d325
commit 877dd04b1f
3 changed files with 44 additions and 15 deletions

View File

@ -2,6 +2,7 @@ using DysonNetwork.Sphere.Account;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using NodaTime;
using NodaTime.Text;
namespace DysonNetwork.Sphere.Activity;
@ -23,11 +24,21 @@ public class ActivityController(
/// Besides, when users are logged in, it will also mix the other kinds of data and who're plying to them.
/// </summary>
[HttpGet]
public async Task<ActionResult<List<Activity>>> ListActivities([FromQuery] int? cursor, [FromQuery] int take = 20)
public async Task<ActionResult<List<Activity>>> ListActivities([FromQuery] string? cursor, [FromQuery] int take = 20)
{
var cursorTimestamp = cursor is <= 1000
? SystemClock.Instance.GetCurrentInstant()
: Instant.FromUnixTimeMilliseconds(cursor!.Value);
Instant? cursorTimestamp = null;
if (!string.IsNullOrEmpty(cursor))
{
try
{
cursorTimestamp = InstantPattern.ExtendedIso.Parse(cursor).GetValueOrThrow();
}
catch
{
return BadRequest("Invalid cursor format");
}
}
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
if (currentUserValue is not Account.Account currentUser)