Skip to content

Commit

Permalink
feature: add created date time to filter (elsa-workflows#4932)
Browse files Browse the repository at this point in the history
Co-authored-by: BEN AMEUR <[email protected]>
  • Loading branch information
bbenameur and BEN AMEUR committed Feb 17, 2024
1 parent f85615f commit f7e224e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public override async Task<Response> ExecuteAsync(Request request, CancellationT
WorkflowStatus = request.Status,
WorkflowSubStatus = request.SubStatus,
WorkflowStatuses = request.Statuses?.Select(Enum.Parse<WorkflowStatus>).ToList(),
WorkflowSubStatuses = request.SubStatuses?.Select(Enum.Parse<WorkflowSubStatus>).ToList()
WorkflowSubStatuses = request.SubStatuses?.Select(Enum.Parse<WorkflowSubStatus>).ToList(),
ToCreatedAt = request.ToCreatedAt,
FromCreatedAt = request.FromCreatedAt,
};

var summaries = await FindAsync(request, filter, pageArgs, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Request
public ICollection<string>? SubStatuses { get; set; }
public OrderByWorkflowInstance? OrderBy { get; set; }
public OrderDirection? OrderDirection { get; set; }
public DateTimeOffset? FromCreatedAt { get; set; }
public DateTimeOffset? ToCreatedAt { get; set; }
}

public class Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public class WorkflowInstanceFilter
/// </summary>
public ICollection<WorkflowSubStatus>? WorkflowSubStatuses { get; set; }

/// <summary>
/// Filter workflow instances by created date time, start from this date time.
/// </summary>
public DateTimeOffset? FromCreatedAt { get; set; }

/// <summary>
/// Filter workflow instances by created date time, to this date time.
/// </summary>
public DateTimeOffset? ToCreatedAt { get; set; }

/// <summary>
/// Applies the filter to the specified query.
/// </summary>
Expand All @@ -96,6 +106,8 @@ public IQueryable<WorkflowInstance> Apply(IQueryable<WorkflowInstance> query)
if (filter.WorkflowSubStatus != null) query = query.Where(x => x.SubStatus == filter.WorkflowSubStatus);
if (filter.WorkflowStatuses != null) query = query.Where(x => filter.WorkflowStatuses.Contains(x.Status));
if (filter.WorkflowSubStatuses != null) query = query.Where(x => filter.WorkflowSubStatuses.Contains(x.SubStatus));
if (filter.ToCreatedAt is not null) query = query.Where(x => filter.ToCreatedAt >= x.CreatedAt);
if (filter.FromCreatedAt is not null) query = query.Where(x => filter.FromCreatedAt <= x.CreatedAt);

var searchTerm = filter.SearchTerm;
if (!string.IsNullOrWhiteSpace(searchTerm))
Expand Down

0 comments on commit f7e224e

Please sign in to comment.