feat(degree): /degree/favorite accept-only (persistence deferred)
This commit is contained in:
@@ -38,4 +38,14 @@ public class DegreeController : SVSimController
|
|||||||
.ToList(),
|
.ToList(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("favorite")]
|
||||||
|
public ActionResult<EmptyResponse> Favorite([FromBody] DegreeFavoriteRequest _)
|
||||||
|
{
|
||||||
|
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 /sleeve/favorite + /emblem/favorite
|
||||||
|
// via the shared Wizard/FavoriteTask.cs Kind enum).
|
||||||
|
return new EmptyResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using MessagePack;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Degree;
|
||||||
|
|
||||||
|
[MessagePackObject]
|
||||||
|
public class DegreeFavoriteRequest : BaseRequest
|
||||||
|
{
|
||||||
|
// Spec note: ids are STRINGS on the wire, not ints. Same gotcha as /sleeve/favorite and /emblem/favorite.
|
||||||
|
[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();
|
||||||
|
}
|
||||||
37
SVSim.UnitTests/Controllers/DegreeControllerFavoriteTests.cs
Normal file
37
SVSim.UnitTests/Controllers/DegreeControllerFavoriteTests.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using SVSim.UnitTests.Infrastructure;
|
||||||
|
|
||||||
|
namespace SVSim.UnitTests.Controllers;
|
||||||
|
|
||||||
|
public class DegreeControllerFavoriteTests
|
||||||
|
{
|
||||||
|
[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);
|
||||||
|
|
||||||
|
var requestJson = """{"favorite_add":["100","101"],"favorite_remove":["200"],"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
|
||||||
|
var response = await client.PostAsync("/degree/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("/degree/favorite",
|
||||||
|
new StringContent(requestJson, Encoding.UTF8, "application/json"));
|
||||||
|
|
||||||
|
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user