| | | 1 | | using Elsa.Alterations.Core.Entities; |
| | | 2 | | using Elsa.Alterations.Core.Enums; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Alterations.Core.Filters; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// A filter for querying alteration jobs. |
| | | 8 | | /// </summary> |
| | | 9 | | public class AlterationJobFilter |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// The ID of the job. |
| | | 13 | | /// </summary> |
| | 0 | 14 | | public string? Id { get; set; } |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// The ID of the plan. |
| | | 18 | | /// </summary> |
| | 0 | 19 | | public string? PlanId { get; set; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// The status of the job. |
| | | 23 | | /// </summary> |
| | 0 | 24 | | public AlterationJobStatus? Status { get; set; } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// The statuses of the job to match. |
| | | 28 | | /// </summary> |
| | 0 | 29 | | public ICollection<AlterationJobStatus>? Statuses { get; set; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Applies the filter to the specified query. |
| | | 33 | | /// </summary> |
| | | 34 | | public IQueryable<AlterationJob> Apply(IQueryable<AlterationJob> query) |
| | | 35 | | { |
| | 0 | 36 | | if (!string.IsNullOrWhiteSpace(Id)) |
| | 0 | 37 | | query = query.Where(x => x.Id == Id); |
| | | 38 | | |
| | 0 | 39 | | if (!string.IsNullOrWhiteSpace(PlanId)) |
| | 0 | 40 | | query = query.Where(x => x.PlanId == PlanId); |
| | | 41 | | |
| | 0 | 42 | | if (Status != null) |
| | 0 | 43 | | query = query.Where(x => x.Status == Status); |
| | | 44 | | |
| | 0 | 45 | | if (Statuses != null) |
| | 0 | 46 | | query = query.Where(x => Statuses.Contains(x.Status)); |
| | | 47 | | |
| | 0 | 48 | | return query; |
| | | 49 | | } |
| | | 50 | | } |