feat(sleeve): /sleeve/favorite accept-only (persistence deferred)

This commit is contained in:
gamer147
2026-06-12 23:22:25 -04:00
parent f879c05dca
commit c870b95be9
3 changed files with 72 additions and 0 deletions

View File

@@ -169,6 +169,16 @@ public class SleeveController : SVSimController
.ToList();
}
[HttpPost("favorite")]
public ActionResult<EmptyResponse> Favorite([FromBody] SleeveFavoriteRequest _)
{
if (!TryGetViewerId(out long __)) return Unauthorized();
// Accept-and-ack. Persisting per-viewer cosmetic favorites is deferred until
// a viewer-favorites schema lands (would also serve /emblem/favorite + /degree/favorite
// via the shared Wizard/FavoriteTask.cs Kind enum). Same pattern as ConfigController.
return new EmptyResponse();
}
/// <summary>
/// A product is "purchased" once the viewer owns at least one of its sleeve-typed reward
/// grants. Emblem/other grants aren't load-bearing for this check — a viewer who somehow

View File

@@ -0,0 +1,18 @@
using MessagePack;
using System.Text.Json.Serialization;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Sleeve;
[MessagePackObject]
public class SleeveFavoriteRequest : BaseRequest
{
// Spec note: ids are STRINGS on the wire, not ints. Don't change to long[].
[JsonPropertyName("favorite_add")]
[Key("favorite_add")]
public List<string> FavoriteAdd { get; set; } = new();
[JsonPropertyName("favorite_remove")]
[Key("favorite_remove")]
public List<string> FavoriteRemove { get; set; } = new();
}

View File

@@ -0,0 +1,44 @@
using System.Net;
using System.Text;
using NUnit.Framework;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Controllers;
public class SleeveControllerFavoriteTests
{
[Test]
public async Task Favorite_accepts_add_and_remove_lists()
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync(tutorialState: 0);
using var client = factory.CreateAuthenticatedClient(viewerId);
// Stringified ids per spec.
var requestJson = """
{
"favorite_add":["100","101"],
"favorite_remove":["200"],
"viewer_id":"0","steam_id":0,"steam_session_ticket":""
}
""";
var response = await client.PostAsync("/sleeve/favorite",
new StringContent(requestJson, Encoding.UTF8, "application/json"));
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
[Test]
public async Task Favorite_accepts_empty_lists()
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync(tutorialState: 0);
using var client = factory.CreateAuthenticatedClient(viewerId);
var requestJson = """{"favorite_add":[],"favorite_remove":[],"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
var response = await client.PostAsync("/sleeve/favorite",
new StringContent(requestJson, Encoding.UTF8, "application/json"));
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
}