Add collector fields, including market value
Rating, notes, condition, region, purchase price and date, plus a market
value carrying the timestamp and source that make it interpretable.
Condition is load-bearing rather than cosmetic: price feeds quote per
condition, so it selects which quoted price applies to a copy. Market value
records when it was captured and where it came from — a collection total is
only as good as its staleness — and an edit to an unrelated field leaves
that timestamp alone, so a stale price cannot start looking freshly checked.
Two storage decisions worth naming:
* Money is stored as integer minor units. SQLite has no decimal type and
EF Core maps decimal to TEXT, which compares lexically: "9.00" sorts
above "10.00" and SUM is unavailable. A value converter keeps decimals
in C# while ordering and totalling work. A test pins the ordering.
* Enums serialise as names. The default is ordinals, which meant the API
rejected the browser's {"condition":"Cib"} with a 400 while the C# tests
passed, because they round-tripped ints and never spoke the client's
dialect. The tests now share the API's serializer options.
Also fixes a data-loss bug in the Python tools. Both built their PUT body
from a hardcoded list of field names, so any column added to the model was
omitted and therefore nulled. Adding collector fields meant the next art or
enrichment run would have erased every rating, note, condition, price and
valuation in the library. Payloads are now built by excluding the handful of
server-owned fields, so new columns carry through by default.
The migration was rehearsed against a copy of the live database before being
applied: 105 rows, descriptions and developers intact.
67 backend tests, 8 frontend.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,11 +16,11 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
|
||||
private static async Task SeedLibraryAsync(HttpClient client)
|
||||
{
|
||||
await client.PostAsJsonAsync("/api/games", Game("Chrono Trigger", "SNES", "rpg", "1995", developer: "Square"));
|
||||
await client.PostAsJsonAsync("/api/games", Game("Super Metroid", "SNES", "platformer", "1994"));
|
||||
await client.PostAsJsonAsync("/api/games", Game("GoldenEye 007", "N64", "fps", "1997", publisher: "Nintendo"));
|
||||
await client.PostAsJsonAsync("/api/games", Game("Banjo-Kazooie", "N64", "adventure", "1998", played: true, finished: true));
|
||||
await client.PostAsJsonAsync("/api/games", Game("Ico", "PS2", "adventure", "2001", played: true));
|
||||
await client.PostJsonAsync("/api/games", Game("Chrono Trigger", "SNES", "rpg", "1995", developer: "Square"));
|
||||
await client.PostJsonAsync("/api/games", Game("Super Metroid", "SNES", "platformer", "1994"));
|
||||
await client.PostJsonAsync("/api/games", Game("GoldenEye 007", "N64", "fps", "1997", publisher: "Nintendo"));
|
||||
await client.PostJsonAsync("/api/games", Game("Banjo-Kazooie", "N64", "adventure", "1998", played: true, finished: true));
|
||||
await client.PostJsonAsync("/api/games", Game("Ico", "PS2", "adventure", "2001", played: true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -29,7 +29,7 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
var client = await factory.CreateUserClientAsync("page-user");
|
||||
await SeedLibraryAsync(client);
|
||||
|
||||
var page = await client.GetFromJsonAsync<PagePayload>("/api/games?page=1&pageSize=2");
|
||||
var page = await client.GetJsonAsync<PagePayload>("/api/games?page=1&pageSize=2");
|
||||
|
||||
Assert.Equal(2, page!.Items.Count);
|
||||
Assert.Equal(5, page.Total);
|
||||
@@ -42,9 +42,9 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
var client = await factory.CreateUserClientAsync("search-user");
|
||||
await SeedLibraryAsync(client);
|
||||
|
||||
var byTitle = await client.GetFromJsonAsync<PagePayload>("/api/games?search=metroid");
|
||||
var byDeveloper = await client.GetFromJsonAsync<PagePayload>("/api/games?search=Square");
|
||||
var byPublisher = await client.GetFromJsonAsync<PagePayload>("/api/games?search=Nintendo");
|
||||
var byTitle = await client.GetJsonAsync<PagePayload>("/api/games?search=metroid");
|
||||
var byDeveloper = await client.GetJsonAsync<PagePayload>("/api/games?search=Square");
|
||||
var byPublisher = await client.GetJsonAsync<PagePayload>("/api/games?search=Nintendo");
|
||||
|
||||
Assert.Equal("Super Metroid", Assert.Single(byTitle!.Items).Title);
|
||||
Assert.Equal("Chrono Trigger", Assert.Single(byDeveloper!.Items).Title);
|
||||
@@ -57,10 +57,10 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
var client = await factory.CreateUserClientAsync("filter-user");
|
||||
await SeedLibraryAsync(client);
|
||||
|
||||
var n64 = await client.GetFromJsonAsync<PagePayload>("/api/games?system=N64");
|
||||
var adventure = await client.GetFromJsonAsync<PagePayload>("/api/games?genre=adventure");
|
||||
var finished = await client.GetFromJsonAsync<PagePayload>("/api/games?finished=true");
|
||||
var unplayed = await client.GetFromJsonAsync<PagePayload>("/api/games?played=false");
|
||||
var n64 = await client.GetJsonAsync<PagePayload>("/api/games?system=N64");
|
||||
var adventure = await client.GetJsonAsync<PagePayload>("/api/games?genre=adventure");
|
||||
var finished = await client.GetJsonAsync<PagePayload>("/api/games?finished=true");
|
||||
var unplayed = await client.GetJsonAsync<PagePayload>("/api/games?played=false");
|
||||
|
||||
Assert.Equal(2, n64!.Total);
|
||||
Assert.Equal(2, adventure!.Total);
|
||||
@@ -74,8 +74,8 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
var client = await factory.CreateUserClientAsync("sort-user");
|
||||
await SeedLibraryAsync(client);
|
||||
|
||||
var ascending = await client.GetFromJsonAsync<PagePayload>("/api/games?sort=title&dir=asc");
|
||||
var descending = await client.GetFromJsonAsync<PagePayload>("/api/games?sort=title&dir=desc");
|
||||
var ascending = await client.GetJsonAsync<PagePayload>("/api/games?sort=title&dir=asc");
|
||||
var descending = await client.GetJsonAsync<PagePayload>("/api/games?sort=title&dir=desc");
|
||||
|
||||
Assert.Equal("Banjo-Kazooie", ascending!.Items.First().Title);
|
||||
Assert.Equal("Super Metroid", descending!.Items.First().Title);
|
||||
@@ -92,11 +92,11 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
var response = await client.GetAsync("/api/games?sort=id);DROP%20TABLE%20Games;--");
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
var page = await response.Content.ReadFromJsonAsync<PagePayload>();
|
||||
var page = await response.Content.ReadJsonAsync<PagePayload>();
|
||||
Assert.Equal("Banjo-Kazooie", page!.Items.First().Title);
|
||||
|
||||
// And the table is still there.
|
||||
var after = await client.GetFromJsonAsync<PagePayload>("/api/games");
|
||||
var after = await client.GetJsonAsync<PagePayload>("/api/games");
|
||||
Assert.Equal(5, after!.Total);
|
||||
}
|
||||
|
||||
@@ -118,8 +118,8 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
{
|
||||
var client = await factory.CreateUserClientAsync("title-required");
|
||||
|
||||
var empty = await client.PostAsJsonAsync("/api/games", new { title = "", system = "SNES" });
|
||||
var whitespace = await client.PostAsJsonAsync("/api/games", new { title = " ", system = "SNES" });
|
||||
var empty = await client.PostJsonAsync("/api/games", new { title = "", system = "SNES" });
|
||||
var whitespace = await client.PostJsonAsync("/api/games", new { title = " ", system = "SNES" });
|
||||
|
||||
Assert.Equal(HttpStatusCode.BadRequest, empty.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.BadRequest, whitespace.StatusCode);
|
||||
@@ -129,13 +129,13 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
public async Task Update_changes_fields_and_moves_the_updated_timestamp()
|
||||
{
|
||||
var client = await factory.CreateUserClientAsync("update-user");
|
||||
var created = await (await client.PostAsJsonAsync("/api/games", Game("Before")))
|
||||
.Content.ReadFromJsonAsync<GamePayload>();
|
||||
var created = await (await client.PostJsonAsync("/api/games", Game("Before")))
|
||||
.Content.ReadJsonAsync<GamePayload>();
|
||||
|
||||
await Task.Delay(15); // the stamp has sub-second resolution, but not zero
|
||||
var updated = await (await client.PutAsJsonAsync(
|
||||
var updated = await (await client.PutJsonAsync(
|
||||
$"/api/games/{created!.Id}", Game("After", finished: true)))
|
||||
.Content.ReadFromJsonAsync<GamePayload>();
|
||||
.Content.ReadJsonAsync<GamePayload>();
|
||||
|
||||
Assert.Equal("After", updated!.Title);
|
||||
Assert.True(updated.Finished);
|
||||
@@ -147,8 +147,8 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
public async Task Delete_removes_the_game()
|
||||
{
|
||||
var client = await factory.CreateUserClientAsync("delete-user");
|
||||
var created = await (await client.PostAsJsonAsync("/api/games", Game("Doomed")))
|
||||
.Content.ReadFromJsonAsync<GamePayload>();
|
||||
var created = await (await client.PostJsonAsync("/api/games", Game("Doomed")))
|
||||
.Content.ReadJsonAsync<GamePayload>();
|
||||
|
||||
var response = await client.DeleteAsync($"/api/games/{created!.Id}");
|
||||
|
||||
@@ -161,13 +161,13 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
{
|
||||
var client = await factory.CreateUserClientAsync("null-user");
|
||||
|
||||
var created = await (await client.PostAsJsonAsync("/api/games", new
|
||||
var created = await (await client.PostJsonAsync("/api/games", new
|
||||
{
|
||||
title = " Trimmed ",
|
||||
system = (string?)null,
|
||||
genre = (string?)null,
|
||||
own = true,
|
||||
})).Content.ReadFromJsonAsync<GamePayload>();
|
||||
})).Content.ReadJsonAsync<GamePayload>();
|
||||
|
||||
Assert.Equal("Trimmed", created!.Title);
|
||||
Assert.Null(created.System);
|
||||
@@ -188,7 +188,7 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
|
||||
var response = await client.PostAsync("/api/images", content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var upload = await response.Content.ReadFromJsonAsync<UploadPayload>();
|
||||
var upload = await response.Content.ReadJsonAsync<UploadPayload>();
|
||||
|
||||
Assert.EndsWith(".webp", upload!.FileName);
|
||||
// The stored name is generated server-side, never taken from the upload.
|
||||
@@ -240,9 +240,9 @@ public class GamesTests(LudosApiFactory factory) : IClassFixture<LudosApiFactory
|
||||
image.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
|
||||
content.Add(image, "file", "a.png");
|
||||
var upload = await (await alice.PostAsync("/api/images", content))
|
||||
.Content.ReadFromJsonAsync<UploadPayload>();
|
||||
.Content.ReadJsonAsync<UploadPayload>();
|
||||
|
||||
var bobUser = await bob.GetFromJsonAsync<LudosApiFactory.UserPayload>("/api/auth/me");
|
||||
var bobUser = await bob.GetJsonAsync<LudosApiFactory.UserPayload>("/api/auth/me");
|
||||
var file = upload!.Url.Split('/').Last();
|
||||
|
||||
var probe = await bob.GetAsync($"/uploads/{bobUser!.Id}/{file}");
|
||||
|
||||
Reference in New Issue
Block a user