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:
@@ -1,5 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
using LudosData.Api.Domain;
|
||||
|
||||
namespace LudosData.Api.Contracts;
|
||||
|
||||
/// <summary>A page of results plus the totals the paginator needs.</summary>
|
||||
@@ -28,6 +30,15 @@ public record GameResponse(
|
||||
bool Dumped,
|
||||
bool Played,
|
||||
bool Finished,
|
||||
int? Rating,
|
||||
string? Notes,
|
||||
GameCondition Condition,
|
||||
GameRegion Region,
|
||||
decimal? PurchasePrice,
|
||||
DateOnly? PurchaseDate,
|
||||
decimal? MarketValue,
|
||||
DateTimeOffset? MarketValueUpdatedAt,
|
||||
string? MarketValueSource,
|
||||
DateTimeOffset CreatedAt,
|
||||
DateTimeOffset UpdatedAt);
|
||||
|
||||
@@ -52,6 +63,24 @@ public record GameRequest
|
||||
public bool Dumped { get; init; }
|
||||
public bool Played { get; init; }
|
||||
public bool Finished { get; init; }
|
||||
|
||||
[Range(1, 10)] public int? Rating { get; init; }
|
||||
[MaxLength(10_000)] public string? Notes { get; init; }
|
||||
|
||||
public GameCondition Condition { get; init; } = GameCondition.Unspecified;
|
||||
public GameRegion Region { get; init; } = GameRegion.Unspecified;
|
||||
|
||||
[Range(0, 1_000_000)] public decimal? PurchasePrice { get; init; }
|
||||
public DateOnly? PurchaseDate { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Current estimated resale value. Accepted here so a figure can be entered
|
||||
/// by hand; a price feed will later write the same field, stamping
|
||||
/// MarketValueUpdatedAt and MarketValueSource as it goes.
|
||||
/// </summary>
|
||||
[Range(0, 1_000_000)] public decimal? MarketValue { get; init; }
|
||||
|
||||
[MaxLength(100)] public string? MarketValueSource { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>Query string for the library list, bound from [FromQuery].</summary>
|
||||
@@ -68,12 +97,24 @@ public record GameQuery
|
||||
public bool? Played { get; init; }
|
||||
public bool? Finished { get; init; }
|
||||
|
||||
public GameCondition? Condition { get; init; }
|
||||
public GameRegion? Region { get; init; }
|
||||
|
||||
/// <summary>Lowest personal score to include. Unrated games are excluded when set.</summary>
|
||||
[Range(1, 10)] public int? MinRating { get; init; }
|
||||
|
||||
/// <summary>Restrict to games that do, or do not, have a market value recorded.</summary>
|
||||
public bool? HasValue { get; init; }
|
||||
|
||||
[Range(1, int.MaxValue)] public int Page { get; init; } = 1;
|
||||
|
||||
/// <summary>Capped at 100 to keep a hostile or buggy client from asking for everything.</summary>
|
||||
[Range(1, 100)] public int PageSize { get; init; } = 20;
|
||||
|
||||
/// <summary>One of: title, system, genre, year, developer, publisher, created, updated.</summary>
|
||||
/// <summary>
|
||||
/// One of: title, system, genre, year, developer, publisher, rating,
|
||||
/// value, price, purchased, created, updated.
|
||||
/// </summary>
|
||||
public string Sort { get; init; } = "title";
|
||||
|
||||
/// <summary>"asc" or "desc".</summary>
|
||||
|
||||
Reference in New Issue
Block a user