mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 07:11:06 -04:00
The server becomes the system of record for shared drawings (cut type, thickness, material and grade, customer, notes). Schema v4 adds `drawings` (current row) and `drawing_revisions` (immutable) to the same SQLite file under the existing monitor; the nest tables are untouched and a v3 upgrade keeps every nest row byte-identical. `/api/drawings` follows the nest revision contract: client-allocated ids, If-Match on every existing-drawing write (428/400/409 with no state change), archive instead of delete, and one transaction for promotion plus snapshot. Geometry is an opaque package (a zero-plate .nest) the server never parses. Enum fields accept single names only, because the JSON enum converter would otherwise accept numbers and comma combinations. Material, grade and customer filters match SharedListNames keys so spacing and case cannot split a drawing family; thickness is stored and compared at four decimals. Shared bounds live in OpenNest.Data so the client can refuse the same requests before sending. If-Match parsing moves to one helper used by nests and drawings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
1.0 KiB
C#
23 lines
1.0 KiB
C#
namespace OpenNest.Server;
|
|
|
|
/// <summary>The revision precondition every existing-record mutation requires.</summary>
|
|
internal static class IfMatch
|
|
{
|
|
/// <summary>
|
|
/// Reads one quoted positive revision. Returns 428 when the header is missing and
|
|
/// 400 when it is malformed; null means <paramref name="revision"/> holds the value.
|
|
/// </summary>
|
|
public static IResult? Read(HttpRequest request, out int revision)
|
|
{
|
|
revision = 0;
|
|
var values = request.Headers.IfMatch;
|
|
if (values.Count == 0) return Results.Json("Upgrade/reload required: send If-Match with the current revision.", statusCode: 428);
|
|
var text = values.Count == 1 ? values[0] : null;
|
|
if (text is null || text.Length < 3 || text[0] != '"' || text[^1] != '"' ||
|
|
!text[1..^1].All(c => c is >= '0' and <= '9') ||
|
|
!int.TryParse(text[1..^1], out revision) || revision < 1)
|
|
return Results.BadRequest("If-Match must contain one quoted positive integer revision.");
|
|
return null;
|
|
}
|
|
}
|