Adding
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
namespace LCU.Api.Internal.DispatcherLib.Extensions.Queryables;
|
||||
|
||||
public static class ContainsTagIdQueryable
|
||||
{
|
||||
public static IQueryable<Job> FilterOnTagId(this IQueryable<Job> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.TagIdFilters == null || !filter.TagIdFilters.Any())
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(job => job.JobTags.Any(jobTag => filter.TagIdFilters.Contains(jobTag.TagId)));
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
namespace LCU.Api.Internal.DispatcherLib.Extensions.Queryables;
|
||||
|
||||
public static class IncludeAllQueryable
|
||||
{
|
||||
/// <summary>
|
||||
/// Since this runs as Split Query, the OrderyByDescending only works during the querying but not in our result set.
|
||||
/// OrderbyDescending on WorkItemExecutions will have to be done prior to use if need be.
|
||||
/// </summary>
|
||||
/// <param name="queryable"></param>
|
||||
/// <param name="numberOfWorkItems"></param>
|
||||
/// <returns></returns>
|
||||
public static IQueryable<Job> IncludeAll(this IQueryable<Job> queryable, int numberOfWorkItemExecutions, int numberOfExecutionMessages)
|
||||
{
|
||||
return queryable.Include(job => job.WorkItems)
|
||||
.ThenInclude(wi => wi.WorkItemExecutions
|
||||
.OrderByDescending(workItemExecution => workItemExecution.StartedTimestamp)
|
||||
.Take(numberOfWorkItemExecutions))
|
||||
.ThenInclude(workItemExecution => workItemExecution.ExecutionMessages
|
||||
.OrderByDescending(executionMessage => executionMessage.MessageDate)
|
||||
.Take(numberOfExecutionMessages))
|
||||
.Include(job => job.JobErrorRecipients)
|
||||
.Include(jobTag => jobTag.JobTags)
|
||||
.ThenInclude(jobTag => jobTag.Tag)
|
||||
.AsSplitQuery();
|
||||
}
|
||||
|
||||
public static IQueryable<Job> IncludeErrorRecipients(this IQueryable<Job> queryable)
|
||||
{
|
||||
return queryable.Include(job => job.JobErrorRecipients);
|
||||
}
|
||||
|
||||
public static IQueryable<WorkItem> IncludeAll(this IQueryable<WorkItem> queryable)
|
||||
{
|
||||
return queryable.Include(workItem => workItem.WorkItemExecutions);
|
||||
}
|
||||
|
||||
public static IQueryable<WorkItem> IncludeAll(this IQueryable<WorkItem> queryable, int numberOfWorkItemExecutions, int numberOfExecutionMessages)
|
||||
{
|
||||
return queryable.Include(wi => wi.WorkItemExecutions
|
||||
.OrderByDescending(workItemExecution => workItemExecution.StartedTimestamp)
|
||||
.Take(numberOfWorkItemExecutions))
|
||||
.ThenInclude(workItemExecution => workItemExecution.ExecutionMessages
|
||||
.OrderByDescending(executionMessage => executionMessage.MessageDate)
|
||||
.Take(numberOfExecutionMessages));
|
||||
}
|
||||
|
||||
public static IQueryable<JobTag> IncludeAll(this IQueryable<JobTag> queryable)
|
||||
{
|
||||
return queryable.Include(jobTag => jobTag.Tag);
|
||||
}
|
||||
|
||||
public static IQueryable<WorkItemExecution> IncludeAll(this IQueryable<WorkItemExecution> queryable)
|
||||
{
|
||||
return queryable.Include(workItemExecution => workItemExecution.ExecutionMessages);
|
||||
}
|
||||
|
||||
public static IQueryable<CleanUpJobSetting> IncludeAll(this IQueryable<CleanUpJobSetting> queryable)
|
||||
{
|
||||
return queryable.Include(cleanUpJobSetting => cleanUpJobSetting.CleanUpJobTags)
|
||||
.ThenInclude(cleanUpJobTag => cleanUpJobTag.Tag);
|
||||
}
|
||||
|
||||
public static IQueryable<CleanUpJobTag> IncludeAll(this IQueryable<CleanUpJobTag> queryable)
|
||||
{
|
||||
return queryable.Include(cleanUpJobTag => cleanUpJobTag.Tag);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
namespace LCU.Api.Internal.DispatcherLib.Extensions.Queryables;
|
||||
|
||||
public static class JobDescriptionQueryable
|
||||
{
|
||||
public static IQueryable<Job> FilterJobDescription(this IQueryable<Job> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.JobDescription == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(job => job.Description.Contains(filter.JobDescription));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
namespace LCU.Api.Internal.DispatcherLib.Extensions.Queryables;
|
||||
|
||||
public static class JobNameQueryable
|
||||
{
|
||||
public static IQueryable<Job> FilterJobName(this IQueryable<Job> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.JobName == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(job => job.Name.Contains(filter.JobName));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
namespace LCU.Api.Internal.DispatcherLib.Extensions.Queryables;
|
||||
|
||||
public static class NextRunTimeGreaterThanDateQueryable
|
||||
{
|
||||
public static IQueryable<Job> FilterNextRunTimeGreaterThanDate(this IQueryable<Job> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.NextRuntimeGreaterThanDate == null)
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
return queryable.Where(job => job.NextRunTime >= filter.NextRuntimeGreaterThanDate);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Linq.Dynamic.Core;
|
||||
using LCU.Library.Internal.DispatcherModels.Models;
|
||||
using LCU.Library.Internal.DispatcherModels.Entities;
|
||||
namespace LCU.Api.Internal.DispatcherLib.Extensions.Queryables;
|
||||
|
||||
public static class SortableFieldsQueryable
|
||||
{
|
||||
public static IQueryable<Job> OrderBySortableFields(this IQueryable<Job> queryable, Filter filter)
|
||||
{
|
||||
if (filter?.SortableFields == null || !filter.SortableFields.Any())
|
||||
{
|
||||
return queryable;
|
||||
}
|
||||
|
||||
var orderBy = new StringBuilder();
|
||||
foreach (var field in filter.SortableFields.OrderBy(sortableField => sortableField.Position))
|
||||
{
|
||||
var addedComma = orderBy.ToString() == "" ? "" : " ,";
|
||||
var desc = field.IsDescending ? " desc" : "";
|
||||
orderBy.Append($"{addedComma}{field.Field}{desc}");
|
||||
}
|
||||
|
||||
return queryable.OrderBy(orderBy.ToString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user