process-data-standard-format with Pipes, HeaderId and SubgroupId

This commit is contained in:
2025-04-24 19:52:45 -07:00
parent 61188f434d
commit 13bd899101
25 changed files with 199 additions and 123 deletions

View File

@ -1,27 +1,75 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Adaptation.Shared.Metrology;
public partial class WS
{
// this class represents the response from the Inbound API endpoint
public class Results
{
// true or false if data was written to the database
public bool Success { get; set; }
// if true, contains ID of the Header record in the database
public long HeaderID { get; set; }
#nullable enable
// if false, this collection will contain a list of errors
public List<string> Errors { get; set; }
[JsonConstructor]
public Results(List<string>? errors,
long? headerId,
long? subgroupId,
bool? success,
List<string>? warnings)
{
Errors = errors;
Success = success;
HeaderId = headerId;
Warnings = warnings;
SubgroupId = subgroupId;
}
// this collection will contain a list of warnings, they will not prevent data from being saved
public List<string> Warnings { get; set; }
[JsonPropertyName("errors")] public List<string>? Errors { get; set; }
[JsonPropertyName("headerID")] public long? HeaderId { get; set; }
[JsonPropertyName("subgroupId")] public long? SubgroupId { get; set; }
[JsonPropertyName("success")] public bool? Success { get; set; }
[JsonPropertyName("warnings")] public List<string>? Warnings { get; set; }
public override string ToString()
{
string result = JsonSerializer.Serialize(this, ResultsSourceGenerationContext.Default.Results);
return result;
}
internal static Results Get(Results results, long? subgroupId) =>
new(results.Errors, results.HeaderId, subgroupId, results.Success, results.Warnings);
internal static Results Get(string resultsJson, Exception e)
{
Results results;
Exception? exception = e;
List<string> errors = new();
StringBuilder stringBuilder = new();
while (exception is not null)
{
_ = stringBuilder.AppendLine(exception.Message);
exception = exception.InnerException;
}
errors.Add(resultsJson);
errors.Add(stringBuilder.ToString());
results = new(errors: errors,
headerId: null,
subgroupId: null,
success: false,
warnings: new());
return results;
}
// this is just a helper function to make displaying the results easier
public override string ToString() => JsonSerializer.Serialize(this, GetType());
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(WS.Results))]
internal partial class ResultsSourceGenerationContext : JsonSerializerContext
{
}