604bfe919c
Apply comprehensive fixes from code reviews including: - Extract shared utilities (SqlFormatHelper, CellValueConverter, DbDestinationBase) - Add interface abstractions (IAuthenticationService, IDatabaseMigrator, IMisQueryBuilder) - Implement SecureStore for encrypted secrets storage - Fix error handling with proper HTTP status codes and logging - Optimize double enumeration in DevEtlRegistry - Add DataSync.Dev README for developer onboarding - Extract filter panel base classes to reduce duplication - Update code review docs to mark all issues as fixed
103 lines
2.9 KiB
C#
103 lines
2.9 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using JdeScoping.Core.Models.Enums;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace JdeScoping.Core.Models.Search;
|
|
|
|
/// <summary>
|
|
/// User search request entity
|
|
/// </summary>
|
|
public class Search
|
|
{
|
|
/// <summary>
|
|
/// PK ID of search
|
|
/// </summary>
|
|
public int Id { get; set; }
|
|
|
|
/// <summary>
|
|
/// User name of user that created search
|
|
/// </summary>
|
|
public string UserName { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// User-friendly name for search
|
|
/// </summary>
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Current search status
|
|
/// </summary>
|
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
|
public SearchStatus Status { get; set; }
|
|
|
|
/// <summary>
|
|
/// Timestamp search was submitted
|
|
/// </summary>
|
|
public DateTime? SubmitDt { get; set; }
|
|
|
|
/// <summary>
|
|
/// Timestamp search was started
|
|
/// </summary>
|
|
public DateTime? StartDt { get; set; }
|
|
|
|
/// <summary>
|
|
/// Timestamp search was completed
|
|
/// </summary>
|
|
public DateTime? EndDt { get; set; }
|
|
|
|
/// <summary>
|
|
/// JSON-packed search criteria (stored in database)
|
|
/// </summary>
|
|
public string CriteriaJson { get; set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Search criteria (deserialized from CriteriaJSON)
|
|
/// </summary>
|
|
[JsonIgnore]
|
|
public SearchCriteria? Criteria
|
|
{
|
|
get
|
|
{
|
|
TryGetCriteria(out var criteria);
|
|
return criteria;
|
|
}
|
|
set
|
|
{
|
|
CriteriaJson = value != null
|
|
? JsonSerializer.Serialize(value)
|
|
: string.Empty;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempts to deserialize the search criteria from JSON.
|
|
/// </summary>
|
|
/// <param name="criteria">The deserialized criteria, or null if deserialization fails or JSON is empty.</param>
|
|
/// <param name="logger">Optional logger for warning on deserialization failures.</param>
|
|
/// <returns>True if deserialization succeeded or JSON was empty; false if deserialization failed.</returns>
|
|
public bool TryGetCriteria(out SearchCriteria? criteria, ILogger? logger = null)
|
|
{
|
|
criteria = null;
|
|
|
|
if (string.IsNullOrEmpty(CriteriaJson))
|
|
return true; // Empty is valid, not an error
|
|
|
|
try
|
|
{
|
|
criteria = JsonSerializer.Deserialize<SearchCriteria>(CriteriaJson);
|
|
return true;
|
|
}
|
|
catch (JsonException ex)
|
|
{
|
|
logger?.LogWarning(ex, "Failed to deserialize search criteria for Search ID {SearchId}", Id);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Excel search results file (binary)
|
|
/// </summary>
|
|
public byte[]? Results { get; set; }
|
|
}
|