feat(sleeve): /sleeve/favorite accept-only (persistence deferred)
This commit is contained in:
@@ -169,6 +169,16 @@ public class SleeveController : SVSimController
|
|||||||
.ToList();
|
.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>
|
/// <summary>
|
||||||
/// A product is "purchased" once the viewer owns at least one of its sleeve-typed reward
|
/// 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
|
/// grants. Emblem/other grants aren't load-bearing for this check — a viewer who somehow
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
44
SVSim.UnitTests/Controllers/SleeveControllerFavoriteTests.cs
Normal file
44
SVSim.UnitTests/Controllers/SleeveControllerFavoriteTests.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user