Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AutoFilterer/Abstractions/IOrderable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IOrderable
{
[IgnoreFilter] Sorting SortBy { get; set; }

[IgnoreFilter] string Sort { get; }
[IgnoreFilter] string? Sort { get; }

IOrderedQueryable<TSource> ApplyOrder<TSource>(IQueryable<TSource> source);
}
4 changes: 2 additions & 2 deletions src/AutoFilterer/Abstractions/IPaginationFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace AutoFilterer.Abstractions;

public interface IPaginationFilter : IFilter
{
[IgnoreFilter] int Page { get; set; }
[IgnoreFilter] int PerPage { get; set; }
[IgnoreFilter] int? Page { get; set; }
[IgnoreFilter] int? PerPage { get; set; }

IQueryable<T> ApplyFilterWithoutPagination<T>(IQueryable<T> query);
}
2 changes: 1 addition & 1 deletion src/AutoFilterer/Types/OrderableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class OrderableBase : IOrderable
private static readonly MethodInfo orderByDescending = typeof(Queryable).GetMethods().First(x => x.Name == nameof(Queryable.OrderByDescending));

[IgnoreFilter] public virtual Sorting SortBy { get; set; }
[IgnoreFilter] public virtual string Sort { get; }
[IgnoreFilter] public virtual string? Sort { get; }

public virtual IOrderedQueryable<TSource> ApplyOrder<TSource>(IQueryable<TSource> queryable)
{
Expand Down
8 changes: 4 additions & 4 deletions src/AutoFilterer/Types/PaginationFilterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace AutoFilterer.Types;
public class PaginationFilterBase : OrderableFilterBase, IOrderablePaginationFilter
{
[IgnoreFilter]
public virtual int Page { get; set; } = 1;
public virtual int? Page { get; set; } = 1;

[IgnoreFilter]
public virtual int PerPage { get; set; } = 10;
public virtual int? PerPage { get; set; } = 10;

public override IQueryable<TEntity> ApplyFilterTo<TEntity>(IQueryable<TEntity> query)
{
if (query is IOrderedQueryable<TEntity> ordered)
return this.ApplyFilterTo(ordered);

return base.ApplyFilterTo(query).ToPaged(Page, PerPage);
return base.ApplyFilterTo(query).ToPaged(Page ?? 1, PerPage ?? 10);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Page or PrePage is null, consider skipping pagination.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be modified, it is required to pass in paging parameters here. What's your opinion.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have ApplyFilterWithoutPagination() method to ignore pagination. It's not client-controlled since skipping pagination may cause big performance problems and a bottleneck in the main application. When required, calling query.ApplyFilterWithoutPagination(filter) method in the code is a good approach. Makes the developer know about no-filtering instead of being managed by the client. But it depends on case, but this one is more common

}

public virtual IQueryable<TEntity> ApplyFilterTo<TEntity>(IOrderedQueryable<TEntity> query)
=> base.ApplyFilterTo(query).ToPaged(Page, PerPage);
=> base.ApplyFilterTo(query).ToPaged(Page ?? 1, PerPage ?? 10);

public virtual IQueryable<T> ApplyFilterWithoutPagination<T>(IQueryable<T> query)
=> base.ApplyFilterTo(query);
Expand Down
18 changes: 9 additions & 9 deletions src/AutoFilterer/Types/StringFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,47 @@ public class StringFilter : IFilterableType
/// <summary>
/// Provides parameter for equal operator '==' in query.
/// </summary>
public virtual string Eq { get; set; }
public virtual string? Eq { get; set; }

/// <summary>
/// Provides parameter to not equal operator '!=' in query.
/// </summary>
public virtual string Not { get; set; }
public virtual string? Not { get; set; }

/// <summary>
/// Provides parameter to String.Equals method query.
/// </summary>
public virtual new string Equals { get; set; }
public virtual new string? Equals { get; set; }

/// <summary>
/// Provides parameter to String.Contains method query.
/// </summary>
public virtual string Contains { get; set; }
public virtual string? Contains { get; set; }

/// <summary>
/// Provides parameter to !String.Contains method query.
/// </summary>
public virtual string NotContains { get; set; }
public virtual string? NotContains { get; set; }

/// <summary>
/// Provides parameter to String.StartsWith method query.
/// </summary>
public virtual string StartsWith { get; set; }
public virtual string? StartsWith { get; set; }

/// <summary>
/// Provides parameter to !String.StartsWith method query.
/// </summary>
public virtual string NotStartsWith { get; set; }
public virtual string? NotStartsWith { get; set; }

/// <summary>
/// Provides parameter to String.EndsWith method query.
/// </summary>
public virtual string EndsWith { get; set; }
public virtual string? EndsWith { get; set; }

/// <summary>
/// Provides parameter to !String.EndsWith method query.
/// </summary>
public virtual string NotEndsWith { get; set; }
public virtual string? NotEndsWith { get; set; }

/// <summary>
/// Provides parameter to check is null.
Expand Down