mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 18:31:08 -04:00
Nests, drawings and releases store material and grade as free text, so there was no canonical list for clients to suggest from or to fix spelling against. Schema v10 adds materials and material_grades keyed by SharedListNames.Key, with GET/POST /api/materials. Adding is idempotent by key and keeps the first spelling. The tables start empty: the materials already stored did not import cleanly, so the list is filled through the API instead. Existing free-text columns are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
namespace OpenNest.Data;
|
|
|
|
/// <summary>
|
|
/// Wire shape of one material in the nest server's company material list, with its
|
|
/// grades. Names keep the spelling first added; matching uses <see cref="SharedListNames.Key"/>.
|
|
/// </summary>
|
|
public sealed class MaterialListEntry
|
|
{
|
|
public string Name { get; set; } = "";
|
|
public List<string> Grades { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Body of an add to the company material list: a material and, optionally, one of its
|
|
/// grades. Adding a name or grade that is already listed (by key) changes nothing.
|
|
/// </summary>
|
|
public sealed class MaterialListAddition
|
|
{
|
|
public string? Name { get; set; }
|
|
public string? Grade { get; set; }
|
|
}
|
|
|
|
public static class MaterialListRules
|
|
{
|
|
/// <summary>The first rule <paramref name="addition"/> breaks, or null when it may be added.</summary>
|
|
public static string? GetError(MaterialListAddition? addition)
|
|
{
|
|
if (addition is null)
|
|
return "Missing material.";
|
|
if (SharedListNames.Key(addition.Name).Length == 0)
|
|
return "name is required.";
|
|
return DrawingLibraryRules.TextError("name", addition.Name, DrawingLibraryRules.MaxTextLength)
|
|
?? (addition.Grade is null ? null
|
|
: DrawingLibraryRules.TextError("grade", addition.Grade, DrawingLibraryRules.MaxTextLength));
|
|
}
|
|
|
|
/// <summary>The name as listed: trimmed, with internal whitespace runs collapsed to one space.</summary>
|
|
public static string Spelling(string? name) =>
|
|
name == null ? "" : string.Join(' ', name.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries));
|
|
}
|