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:
@@ -28,9 +28,9 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
|
||||
private static async Task<int> CreateGameAsync(HttpClient client, string title)
|
||||
{
|
||||
var response = await client.PostAsJsonAsync("/api/games", Game(title));
|
||||
var response = await client.PostJsonAsync("/api/games", Game(title));
|
||||
response.EnsureSuccessStatusCode();
|
||||
var created = await response.Content.ReadFromJsonAsync<GamePayload>();
|
||||
var created = await response.Content.ReadJsonAsync<GamePayload>();
|
||||
return created!.Id;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,8 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
await CreateGameAsync(alice, "Alice's Game");
|
||||
await CreateGameAsync(bob, "Bob's Game");
|
||||
|
||||
var alicePage = await alice.GetFromJsonAsync<PagePayload>("/api/games");
|
||||
var bobPage = await bob.GetFromJsonAsync<PagePayload>("/api/games");
|
||||
var alicePage = await alice.GetJsonAsync<PagePayload>("/api/games");
|
||||
var bobPage = await bob.GetJsonAsync<PagePayload>("/api/games");
|
||||
|
||||
Assert.Single(alicePage!.Items);
|
||||
Assert.Equal("Alice's Game", alicePage.Items[0].Title);
|
||||
@@ -73,11 +73,11 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
var bob = await factory.CreateUserClientAsync("upd-bob");
|
||||
var aliceGame = await CreateGameAsync(alice, "Untouched");
|
||||
|
||||
var response = await bob.PutAsJsonAsync($"/api/games/{aliceGame}", Game("Hijacked"));
|
||||
var response = await bob.PutJsonAsync($"/api/games/{aliceGame}", Game("Hijacked"));
|
||||
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
|
||||
var after = await alice.GetFromJsonAsync<GamePayload>($"/api/games/{aliceGame}");
|
||||
var after = await alice.GetJsonAsync<GamePayload>($"/api/games/{aliceGame}");
|
||||
Assert.Equal("Untouched", after!.Title);
|
||||
}
|
||||
|
||||
@@ -102,11 +102,11 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
var alice = await factory.CreateUserClientAsync("spoof-alice");
|
||||
var bob = await factory.CreateUserClientAsync("spoof-bob");
|
||||
|
||||
var bobUser = await bob.GetFromJsonAsync<LudosApiFactory.UserPayload>("/api/auth/me");
|
||||
var bobUser = await bob.GetJsonAsync<LudosApiFactory.UserPayload>("/api/auth/me");
|
||||
|
||||
// Alice creates a game while claiming it belongs to Bob. The contract has
|
||||
// no ownerId, so this should be ignored rather than honoured.
|
||||
var response = await alice.PostAsJsonAsync("/api/games", new
|
||||
var response = await alice.PostJsonAsync("/api/games", new
|
||||
{
|
||||
title = "Attempted Handover",
|
||||
system = "SNES",
|
||||
@@ -116,8 +116,8 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
});
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var alicePage = await alice.GetFromJsonAsync<PagePayload>("/api/games");
|
||||
var bobPage = await bob.GetFromJsonAsync<PagePayload>("/api/games");
|
||||
var alicePage = await alice.GetJsonAsync<PagePayload>("/api/games");
|
||||
var bobPage = await bob.GetJsonAsync<PagePayload>("/api/games");
|
||||
|
||||
Assert.Single(alicePage!.Items);
|
||||
Assert.Empty(bobPage!.Items);
|
||||
@@ -129,10 +129,10 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
var alice = await factory.CreateUserClientAsync("facet-alice");
|
||||
var bob = await factory.CreateUserClientAsync("facet-bob");
|
||||
|
||||
await alice.PostAsJsonAsync("/api/games", new { title = "A", system = "N64", genre = "fps", own = true });
|
||||
await bob.PostAsJsonAsync("/api/games", new { title = "B", system = "PS2", genre = "rpg", own = true });
|
||||
await alice.PostJsonAsync("/api/games", new { title = "A", system = "N64", genre = "fps", own = true });
|
||||
await bob.PostJsonAsync("/api/games", new { title = "B", system = "PS2", genre = "rpg", own = true });
|
||||
|
||||
var facets = await alice.GetFromJsonAsync<FacetsPayload>("/api/games/facets");
|
||||
var facets = await alice.GetJsonAsync<FacetsPayload>("/api/games/facets");
|
||||
|
||||
Assert.Equal(["N64"], facets!.Systems);
|
||||
Assert.Equal(["fps"], facets.Genres);
|
||||
@@ -147,9 +147,9 @@ public class OwnershipTests(LudosApiFactory factory) : IClassFixture<LudosApiFac
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, (await anonymous.GetAsync("/api/games/1")).StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, (await anonymous.GetAsync("/api/games/facets")).StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized,
|
||||
(await anonymous.PostAsJsonAsync("/api/games", Game("x"))).StatusCode);
|
||||
(await anonymous.PostJsonAsync("/api/games", Game("x"))).StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized,
|
||||
(await anonymous.PutAsJsonAsync("/api/games/1", Game("x"))).StatusCode);
|
||||
(await anonymous.PutJsonAsync("/api/games/1", Game("x"))).StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, (await anonymous.DeleteAsync("/api/games/1")).StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, (await anonymous.PostAsync("/api/images", null)).StatusCode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user