Sharable rewind point

This commit is contained in:
2025-12-27 14:24:35 +08:00
parent b51a086031
commit bb5d70eddb
3 changed files with 94 additions and 0 deletions

View File

@@ -8,6 +8,14 @@ namespace DysonNetwork.Pass.Rewind;
[Route("/api/rewind")]
public class AccountRewindController(AccountRewindService rewindSrv) : ControllerBase
{
[HttpGet("{code}")]
public async Task<ActionResult<SnRewindPoint>> GetRewindPoint([FromRoute] string code)
{
var point = await rewindSrv.GetPublicRewindPoint(code);
if (point is null) return NotFound();
return Ok(point);
}
[HttpGet("me")]
[Authorize]
public async Task<ActionResult<SnRewindPoint>> GetCurrentRewindPoint()
@@ -16,4 +24,36 @@ public class AccountRewindController(AccountRewindService rewindSrv) : Controlle
var point = await rewindSrv.GetOrCreateRewindPoint(currentUser.Id);
return Ok(point);
}
[HttpPost("me/{year:int}/public")]
[Authorize]
public async Task<ActionResult<SnRewindPoint>> SetRewindPointPublic([FromRoute] int year)
{
if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized();
try
{
var point = await rewindSrv.SetRewindPointPublic(currentUser.Id, year);
return Ok(point);
}
catch (InvalidOperationException error)
{
return BadRequest(error.Message);
}
}
[HttpPost("me/{year:int}/private")]
[Authorize]
public async Task<ActionResult<SnRewindPoint>> SetRewindPointPrivate([FromRoute] int year)
{
if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized();
try
{
var point = await rewindSrv.SetRewindPointPrivate(currentUser.Id, year);
return Ok(point);
}
catch (InvalidOperationException error)
{
return BadRequest(error.Message);
}
}
}