mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 11:53:12 +00:00
GET /board/search accepts ids=1,2,3 (positive ints, deduplicated, at most 200). When present the result is exactly those work orders inside the caller's tenant and base scope; date, status, dispatcher, facet and text filters are ignored so none of them can hide a listed work order. Malformed or oversized lists are a 400.
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using System.Globalization;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
/// <summary>
|
|
/// The board's exact work-order id filter: comma-separated positive integers, deduplicated,
|
|
/// at most <see cref="MaxCount"/> distinct ids.
|
|
/// </summary>
|
|
public static class WorkOrderIdSet
|
|
{
|
|
public const int MaxCount = 200;
|
|
|
|
/// <summary>
|
|
/// Null when <paramref name="raw"/> is absent or blank. Throws <see cref="ArgumentException"/>
|
|
/// (a 400 on the board) for any token that is not a positive integer, or too many ids.
|
|
/// </summary>
|
|
public static IReadOnlyList<int>? ParseOrThrow(string? raw)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(raw))
|
|
return null;
|
|
|
|
var ids = new List<int>();
|
|
var seen = new HashSet<int>();
|
|
foreach (var token in raw.Split(','))
|
|
{
|
|
if (!int.TryParse(token.Trim(), NumberStyles.None, CultureInfo.InvariantCulture, out var id) || id <= 0)
|
|
throw new ArgumentException("ids must be a comma-separated list of positive work order ids.");
|
|
if (seen.Add(id))
|
|
ids.Add(id);
|
|
}
|
|
|
|
if (ids.Count > MaxCount)
|
|
throw new ArgumentException($"ids accepts at most {MaxCount} work orders.");
|
|
|
|
return ids;
|
|
}
|
|
}
|
|
}
|