- Add AutoMapper profile for CfgProfile and ProfileSqlJob entity-to-DTO mappings - Consolidate GetProfileByIdQuery and GetAllActiveProfilesQuery into unified GetProfileQuery - Implement flexible filtering with nullable query options (Id, Active, TypeId, ProfileName) - Add IncludeSqlJobs option for optimized SQL job loading - Move CfgProfileDto to Common/Dtos for better architecture alignment - Add comprehensive unit tests for GetProfileQuery with multiple filter scenarios - Move ISQLExecutor interface from Domain to Application layer - Add GetByIdWithSqlJobsAsync and GetAllActiveWithSqlJobsAsync to repository
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using AutoMapper;
|
|
using ECMJobRunner.Domain.Entities;
|
|
using ECMJobRunner.Domain.Interfaces;
|
|
using ECMJobRunner.Infrastructure.Data;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
#if NET48
|
|
using System.Data.Entity;
|
|
#else
|
|
using Microsoft.EntityFrameworkCore;
|
|
#endif
|
|
|
|
namespace ECMJobRunner.Infrastructure.Repositories
|
|
{
|
|
/// <summary>
|
|
/// CfgProfile repository implementation
|
|
/// </summary>
|
|
public class CfgProfileRepository : Repository<CfgProfile>, ICfgProfileRepository
|
|
{
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public CfgProfileRepository(JobRunnerDbContext context, IMapper mapper) : base(context, mapper)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets a profile by ID with associated SQL jobs eagerly loaded
|
|
/// </summary>
|
|
public async Task<CfgProfile?> GetByIdWithSqlJobsAsync(long id, CancellationToken cancellationToken = default)
|
|
{
|
|
return await _context.CfgProfiles
|
|
.Include(p => p.SqlJobs)
|
|
.FirstOrDefaultAsync(p => p.Id == id, cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all active profiles with associated SQL jobs eagerly loaded
|
|
/// </summary>
|
|
public async Task<List<CfgProfile>> GetAllActiveWithSqlJobsAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
return await _context.CfgProfiles
|
|
.Include(p => p.SqlJobs)
|
|
.Where(p => p.Active)
|
|
.ToListAsync(cancellationToken);
|
|
}
|
|
}
|
|
}
|