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
114 lines
3.9 KiB
C#
114 lines
3.9 KiB
C#
using System.Data;
|
|
using Dapper;
|
|
using JdeScoping.Core.Models.Enums;
|
|
using JdeScoping.Core.Models.Search;
|
|
using JdeScoping.DataAccess.Queries;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace JdeScoping.DataAccess.Repositories;
|
|
|
|
/// <summary>
|
|
/// Search management operations for LotFinder repository.
|
|
/// </summary>
|
|
public partial class LotFinderRepository
|
|
{
|
|
/// <inheritdoc/>
|
|
public async Task<List<Search>> GetUserSearchesAsync(string userName, CancellationToken ct = default)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(userName);
|
|
|
|
return await ExecuteQueryAsync(
|
|
nameof(GetUserSearchesAsync),
|
|
"SQL_GET_USER_SEARCHES",
|
|
async connection => (await connection.QueryAsync<Search>(
|
|
LotFinderQueries.SqlGetUserSearches,
|
|
new { userName },
|
|
commandTimeout: _options.Value.DefaultTimeoutSeconds)).ToList(),
|
|
ct);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<List<Search>> GetQueuedSearchesAsync(CancellationToken ct = default)
|
|
{
|
|
return await ExecuteQueryAsync(
|
|
nameof(GetQueuedSearchesAsync),
|
|
"SQL_GET_QUEUED_SEARCHES",
|
|
async connection => (await connection.QueryAsync<Search>(
|
|
LotFinderQueries.SqlGetQueuedSearches,
|
|
commandTimeout: _options.Value.DefaultTimeoutSeconds)).ToList(),
|
|
ct);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<Search?> GetSearchAsync(int id, CancellationToken ct = default)
|
|
{
|
|
return await ExecuteQueryAsync(
|
|
nameof(GetSearchAsync),
|
|
"SQL_GET_SEARCH",
|
|
async connection =>
|
|
{
|
|
var result = await connection.QueryFirstOrDefaultAsync<Search>(
|
|
LotFinderQueries.SqlGetSearch,
|
|
new { id },
|
|
commandTimeout: _options.Value.DefaultTimeoutSeconds);
|
|
|
|
if (result != null)
|
|
{
|
|
result.Id = id;
|
|
}
|
|
|
|
return result;
|
|
},
|
|
ct);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<byte[]?> GetSearchResultsAsync(int id, CancellationToken ct = default)
|
|
{
|
|
return await ExecuteQueryAsync(
|
|
nameof(GetSearchResultsAsync),
|
|
"SQL_GET_SEARCH_RESULTS",
|
|
connection => connection.QueryFirstOrDefaultAsync<byte[]>(
|
|
LotFinderQueries.SqlGetSearchResults,
|
|
new { id },
|
|
commandTimeout: _options.Value.DefaultTimeoutSeconds),
|
|
ct);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public async Task<int> SubmitSearchAsync(Search search, CancellationToken ct = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(search);
|
|
|
|
search.Status = SearchStatus.Queued;
|
|
search.SubmitDt = DateTime.UtcNow;
|
|
|
|
return await ExecuteQueryAsync(
|
|
nameof(SubmitSearchAsync),
|
|
SqlObjects.SubmitSearch,
|
|
async connection =>
|
|
{
|
|
await using var command = new SqlCommand(SqlObjects.SubmitSearch, connection)
|
|
{
|
|
CommandType = CommandType.StoredProcedure,
|
|
CommandTimeout = _options.Value.DefaultTimeoutSeconds
|
|
};
|
|
|
|
command.Parameters.AddWithValue("p_UserName", search.UserName);
|
|
command.Parameters.AddWithValue("p_Name", search.Name);
|
|
command.Parameters.AddWithValue("p_Criteria", search.CriteriaJson);
|
|
|
|
var searchIdParam = new SqlParameter("o_SearchID", SqlDbType.Int)
|
|
{
|
|
Direction = ParameterDirection.Output
|
|
};
|
|
command.Parameters.Add(searchIdParam);
|
|
|
|
await command.ExecuteNonQueryAsync(ct);
|
|
return Convert.ToInt32(searchIdParam.Value);
|
|
},
|
|
ct);
|
|
}
|
|
|
|
}
|