This commit is contained in:
Zeeshaun
2026-04-07 14:21:04 -05:00
parent e37826fe30
commit 75ea216a17
264 changed files with 15920 additions and 0 deletions
@@ -0,0 +1,9 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
public static class IncludeAllQueryable
{
public static IQueryable<LoadTestRunInfo> IncludeAll(this IQueryable<LoadTestRunInfo> queryable)
{
return queryable.Include(loadTestRunInfo => loadTestRunInfo.RateProcessingInfos);
}
}
@@ -0,0 +1,8 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
public static class IncludeFiltersQueryable
{
public static IQueryable<LoadTestRunInfo> IncludeFilters(this IQueryable<LoadTestRunInfo> queryable, LoadTestRunInfoFilter loadTestRunInfoFilter)
=> queryable.FilterRateType(loadTestRunInfoFilter)
.FilterInProgress(loadTestRunInfoFilter)
.FilterByRunTime(loadTestRunInfoFilter);
}
@@ -0,0 +1,13 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
public static class LoadTestRunInfoInProgressQueryable
{
public static IQueryable<LoadTestRunInfo> FilterInProgress(this IQueryable<LoadTestRunInfo> queryable, LoadTestRunInfoFilter loadTestRunInfoFilter)
{
if (!loadTestRunInfoFilter.InProgress)
{
return queryable;
}
return queryable.Where(loadTestRunInfo => !loadTestRunInfo.EndTimeStamp.HasValue);
}
}
@@ -0,0 +1,13 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
public static class LoadTestRunInfoRateTypeQueryable
{
public static IQueryable<LoadTestRunInfo> FilterRateType(this IQueryable<LoadTestRunInfo> queryable, LoadTestRunInfoFilter loadTestRunInfoFilter)
{
if (loadTestRunInfoFilter?.RateTypes == null || !loadTestRunInfoFilter.RateTypes.Any())
{
return queryable;
}
return queryable.Where(loadTestRunInfo => loadTestRunInfoFilter.RateTypes.Contains(loadTestRunInfo.RateType));
}
}
@@ -0,0 +1,21 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
public static class LoadTestRunInfoRunTimeQueryable
{
public static IQueryable<LoadTestRunInfo> FilterByRunTime(this IQueryable<LoadTestRunInfo> queryable, LoadTestRunInfoFilter loadTestRunInfoFilter)
{
if (loadTestRunInfoFilter.StartTimeStamp == null && loadTestRunInfoFilter.EndTimeStamp == null)
{
return queryable;
}
if (loadTestRunInfoFilter.StartTimeStamp == null)
{
loadTestRunInfoFilter.StartTimeStamp = DateTime.MinValue;
}
return queryable.Where(loadTestRunInfo => loadTestRunInfo.StartTimeStamp >= loadTestRunInfoFilter.StartTimeStamp &&
(loadTestRunInfoFilter.InProgress
|| !loadTestRunInfoFilter.EndTimeStamp.HasValue
|| loadTestRunInfo.StartTimeStamp <= loadTestRunInfoFilter.EndTimeStamp));
}
}
@@ -0,0 +1,28 @@
using System.Text;
using System.Linq.Dynamic.Core;
namespace LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
public static class SortableFieldsQueryable
{
public static IQueryable<LoadTestRunInfo> OrderBySortableFields(this IQueryable<LoadTestRunInfo> queryable, LoadTestRunInfoFilter loadTestRunInfoFilter)
{
var sortableFields = loadTestRunInfoFilter.SortableFields
.Where(sortableField => sortableField.Active && sortableField.Position >= 0)
.OrderBy(sortableField => sortableField.Position).ToList();
if (sortableFields == null || !sortableFields.Any())
{
return queryable;
}
var orderBy = new StringBuilder();
foreach (var field in sortableFields)
{
var addedComma = orderBy.ToString() == "" ? "" : " ,";
var desc = field.IsDescending ? " desc" : "";
orderBy.Append($"{addedComma}{field.Field}{desc}");
}
return queryable.OrderBy(orderBy.ToString());
}
}
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.8" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LCU.Library.Internal.LoanRateModels\LCU.Library.Internal.LoanRateModels.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,16 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Persistence;
public class AppDbContext : DbContext
{
public DbSet<LoadTestRunInfo> LoadTestRunInfos { get; set; }
public DbSet<RateProcessingInfo> RateProcessingInfos { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<LoadTestRunInfo>().ToTable("LoadTestRunInfo");
builder.Entity<RateProcessingInfo>().ToTable("RateProcessingInfo");
}
}
@@ -0,0 +1,12 @@
using LCU.API.Internal.LoanRateLoadTestingLib.Persistence;
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public abstract class BaseRepository
{
protected readonly AppDbContext _context;
public BaseRepository(AppDbContext context)
{
_context = context;
}
}
@@ -0,0 +1,16 @@
using LCU.Library.Internal.LCUFilterModels.Pagination;
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public interface ILoadTestRunInfoRepository
{
Task<IEnumerable<LoadTestRunInfo>?> FindAsync();
Task<LoadTestRunInfo?> FindByIdAsync(int id);
Task<IEnumerable<LoadTestRunInfo>?> FindRangeByIdAsync(List<int> ids);
Task<PagedResult<LoadTestRunInfo>> FindFilteredLoadTestRunInfosAsync(LoadTestRunInfoFilter loadTestRunInfoFilter);
Task<LoadTestRunInfo?> AddAsync(LoadTestRunInfo loadTestRunInfo);
Task AddRangeAsync(IEnumerable<LoadTestRunInfo> loadTestRunInfos);
void UpdateRange(IEnumerable<LoadTestRunInfo> loadTestRunInfos);
void Remove(LoadTestRunInfo loadTestRunInfo);
void RemoveRange(IEnumerable<LoadTestRunInfo> loadTestRunInfos);
}
@@ -0,0 +1,14 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public interface IRateProcessingInfoRepository
{
Task<IEnumerable<RateProcessingInfo>?> FindAsync();
Task<RateProcessingInfo?> FindByIdAsync(int id);
Task<IEnumerable<RateProcessingInfo>?> FindRangeByIdAsync(List<int> ids);
Task<IEnumerable<RateProcessingInfo>?> FindByLoadTestRunInfoIdAsync(int loadTestRunInfoId);
Task<RateProcessingInfo?> AddAsync(RateProcessingInfo rateProcessingInfo);
Task AddRangeAsync(IEnumerable<RateProcessingInfo> rateProcessingInfos);
void UpdateRange(IEnumerable<RateProcessingInfo> rateProcessingInfos);
void Remove(RateProcessingInfo rateProcessingInfo);
void RemoveRange(IEnumerable<RateProcessingInfo> rateProcessingInfos);
}
@@ -0,0 +1,7 @@
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public interface IUnitOfWork
{
Task CompleteAsync();
void Complete();
}
@@ -0,0 +1,74 @@
using LCU.API.Internal.LoanRateLoadTestingLib.Persistence;
using LCU.API.Internal.LoanRateLoadTestingLib.Extensions.Queryables;
using LCU.Library.Internal.LCUFilterModels.Pagination;
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public class LoadTestRunInfoRepository : BaseRepository, ILoadTestRunInfoRepository
{
public LoadTestRunInfoRepository(AppDbContext context) : base(context) { }
public async Task<IEnumerable<LoadTestRunInfo>?> FindAsync()
{
return await _context.LoadTestRunInfos.IncludeAll().ToListAsync();
}
public async Task<LoadTestRunInfo?> FindByIdAsync(int id)
{
return await _context.LoadTestRunInfos.IncludeAll().FirstOrDefaultAsync(loadTestRunInfo => loadTestRunInfo.LoadTestRunInfoId == id);
}
public async Task<IEnumerable<LoadTestRunInfo>?> FindRangeByIdAsync(List<int> ids)
{
return await _context.LoadTestRunInfos
.Where(loadTestRunInfo => ids.Contains(loadTestRunInfo.LoadTestRunInfoId))
.IncludeAll()
.ToListAsync();
}
public async Task<PagedResult<LoadTestRunInfo>> FindFilteredLoadTestRunInfosAsync(LoadTestRunInfoFilter loadTestRunInfoFilter)
{
var results = new PagedResult<LoadTestRunInfo>();
var skip = (loadTestRunInfoFilter.Page - 1) * loadTestRunInfoFilter.Limit;
results.Total = await _context.LoadTestRunInfos
.IncludeAll()
.IncludeFilters(loadTestRunInfoFilter)
.CountAsync();
results.Items = await _context.LoadTestRunInfos
.IncludeAll()
.IncludeFilters(loadTestRunInfoFilter)
.OrderBySortableFields(loadTestRunInfoFilter)
.Skip(skip)
.Take(loadTestRunInfoFilter.Limit)
.ToArrayAsync();
return results;
}
public async Task<LoadTestRunInfo?> AddAsync(LoadTestRunInfo loadTestRunInfo)
{
return (await _context.LoadTestRunInfos.AddAsync(loadTestRunInfo)).Entity;
}
public async Task AddRangeAsync(IEnumerable<LoadTestRunInfo> loadTestRunInfos)
{
await _context.LoadTestRunInfos.AddRangeAsync(loadTestRunInfos);
}
public void UpdateRange(IEnumerable<LoadTestRunInfo> loadTestRunInfos)
{
_context.LoadTestRunInfos.UpdateRange(loadTestRunInfos);
}
public void Remove(LoadTestRunInfo loadTestRunInfo)
{
_context.LoadTestRunInfos.Remove(loadTestRunInfo);
}
public void RemoveRange(IEnumerable<LoadTestRunInfo> loadTestRunInfos)
{
_context.LoadTestRunInfos.RemoveRange(loadTestRunInfos);
}
}
@@ -0,0 +1,56 @@
using LCU.API.Internal.LoanRateLoadTestingLib.Persistence;
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public class RateProcessingInfoRepository : BaseRepository, IRateProcessingInfoRepository
{
public RateProcessingInfoRepository(AppDbContext context) : base(context) { }
public async Task<IEnumerable<RateProcessingInfo>?> FindAsync()
{
return await _context.RateProcessingInfos.ToListAsync();
}
public async Task<RateProcessingInfo?> FindByIdAsync(int id)
{
return await _context.RateProcessingInfos.FirstOrDefaultAsync(rateProcessingInfo => rateProcessingInfo.RateProcessingInfoId == id);
}
public async Task<IEnumerable<RateProcessingInfo>?> FindRangeByIdAsync(List<int> ids)
{
return await _context.RateProcessingInfos
.Where(rateProcessingInfo => ids.Contains(rateProcessingInfo.RateProcessingInfoId))
.ToListAsync();
}
public async Task<IEnumerable<RateProcessingInfo>?> FindByLoadTestRunInfoIdAsync(int loadTestRunInfoId)
{
return await _context.RateProcessingInfos
.Where(rateProcessingInfo => rateProcessingInfo.LoadTestRunInfoId == loadTestRunInfoId)
.ToListAsync();
}
public async Task<RateProcessingInfo?> AddAsync(RateProcessingInfo rateProcessingInfo)
{
return (await _context.RateProcessingInfos.AddAsync(rateProcessingInfo)).Entity;
}
public async Task AddRangeAsync(IEnumerable<RateProcessingInfo> rateProcessingInfos)
{
await _context.RateProcessingInfos.AddRangeAsync(rateProcessingInfos);
}
public void UpdateRange(IEnumerable<RateProcessingInfo> rateProcessingInfos)
{
_context.RateProcessingInfos.UpdateRange(rateProcessingInfos);
}
public void Remove(RateProcessingInfo rateProcessingInfo)
{
_context.RateProcessingInfos.Remove(rateProcessingInfo);
}
public void RemoveRange(IEnumerable<RateProcessingInfo> rateProcessingInfos)
{
_context.RateProcessingInfos.RemoveRange(rateProcessingInfos);
}
}
@@ -0,0 +1,22 @@
using LCU.API.Internal.LoanRateLoadTestingLib.Persistence;
namespace LCU.API.Internal.LoanRateLoadTestingLib.Repositories;
public class UnitOfWork : IUnitOfWork
{
private readonly AppDbContext _context;
public UnitOfWork(AppDbContext context)
{
_context = context;
}
public async Task CompleteAsync()
{
await _context.SaveChangesAsync();
}
public void Complete()
{
_context.SaveChanges();
}
}
@@ -0,0 +1,2 @@
global using Microsoft.EntityFrameworkCore;
global using LCU.Library.Internal.LoanRateModels.Entities.LoadTestingEntities;