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
663 changes: 663 additions & 0 deletions QUERY_GENERATION_FLOW.md

Large diffs are not rendered by default.

423 changes: 423 additions & 0 deletions docs/en/generators/SourceGenerator-ApplyFilter.md

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions sandbox/WebApplication.API/Dtos/AuthorFilterWithGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using AutoFilterer.Attributes;
using AutoFilterer.Types;
using AutoFilterer;
using AutoFilterer.Enums;
using WebApplication.API.Models;

namespace WebApplication.API.Dtos;

[GenerateApplyFilter(typeof(Author))]
public class AuthorFilterWithGenerator : PaginationFilterBase
{
[CompareTo(nameof(Author.Name))]
public StringFilter Name { get; set; }

[CompareTo(nameof(Author.Country))]
public string Country { get; set; }

[CompareTo(nameof(Author.Books))]
[CollectionFilter(CollectionFilterType.Any)]
public BookNestedFilter Books { get; set; }
}

public class BookNestedFilter : FilterBase
{
[CompareTo(nameof(Book.Title))]
public StringFilter Title { get; set; }

[CompareTo(nameof(Book.Year))]
public Range<int> Year { get; set; }

[CompareTo(nameof(Book.TotalPage))]
public OperatorFilter<int> TotalPage { get; set; }
}
11 changes: 11 additions & 0 deletions sandbox/WebApplication.API/Models/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace WebApplication.API.Models;

public class Author
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public List<Book> Books { get; set; } = new();
}
723 changes: 723 additions & 0 deletions src/AutoFilterer.Generators/ApplyFilterGenerator.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\common.props" />

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand All @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\AutoFilterer\AutoFilterer.csproj" />
<ProjectReference Include="..\..\src\AutoFilterer.Generators\AutoFilterer.Generators.csproj" OutputItemType="Analyzer"/>
<ProjectReference Include="..\AutoFilterer.Tests.Core\AutoFilterer.Tests.Core.csproj" />
</ItemGroup>
Expand Down
144 changes: 144 additions & 0 deletions tests/AutoFilterer.Generators.Tests/Environment/Dtos/TestFilters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
using AutoFilterer;
using AutoFilterer.Attributes;
using AutoFilterer.Enums;
using AutoFilterer.Types;
using Book = AutoFilterer.Generators.Tests.Environment.Models.Book;
using Author = AutoFilterer.Generators.Tests.Environment.Models.Author;
using Publisher = AutoFilterer.Generators.Tests.Environment.Models.Publisher;

namespace AutoFilterer.Generators.Tests.Environment.Dtos;

// Basic scalar filter
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_Basic : FilterBase
{
public string Title { get; set; }
}

// StringFilter tests
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_StringFilter : FilterBase
{
[CompareTo(nameof(Book.Title))]
public StringFilter Title { get; set; }
}

// OperatorFilter tests
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_OperatorFilter : FilterBase
{
[CompareTo(nameof(Book.TotalPage))]
public OperatorFilter<int> TotalPage { get; set; }

[CompareTo(nameof(Book.Year))]
public OperatorFilter<int> Year { get; set; }
}

// Range tests
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_Range : FilterBase
{
[CompareTo(nameof(Book.Year))]
public Range<int> Year { get; set; }

[CompareTo(nameof(Book.TotalPage))]
public Range<int> TotalPage { get; set; }
}

// Orderable tests
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_Orderable : OrderableFilterBase
{
public string Title { get; set; }
}

// Pagination tests
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_Pagination : PaginationFilterBase
{
public string Title { get; set; }
}

// Nested collection filter - Book nested
public class BookNestedFilter : FilterBase
{
[CompareTo(nameof(Book.Title))]
public StringFilter Title { get; set; }

[CompareTo(nameof(Book.Year))]
public Range<int> Year { get; set; }

[CompareTo(nameof(Book.TotalPage))]
public OperatorFilter<int> TotalPage { get; set; }
}

// Collection filter tests
[GenerateApplyFilter(typeof(Author))]
public class AuthorFilter_CollectionAny : FilterBase
{
[CompareTo(nameof(Author.Name))]
public StringFilter Name { get; set; }

[CompareTo(nameof(Author.Books))]
[CollectionFilter(CollectionFilterType.Any)]
public BookNestedFilter Books { get; set; }
}

[GenerateApplyFilter(typeof(Author))]
public class AuthorFilter_CollectionAll : FilterBase
{
[CompareTo(nameof(Author.Name))]
public string Name { get; set; }

[CompareTo(nameof(Author.Books))]
[CollectionFilter(CollectionFilterType.All)]
public BookNestedFilter Books { get; set; }
}

// Complex nested filter
public class AuthorNestedFilter : FilterBase
{
[CompareTo(nameof(Author.Name))]
public StringFilter Name { get; set; }

[CompareTo(nameof(Author.Books))]
[CollectionFilter(CollectionFilterType.Any)]
public BookNestedFilter Books { get; set; }
}

[GenerateApplyFilter(typeof(Publisher))]
public class PublisherFilter_NestedCollection : FilterBase
{
[CompareTo(nameof(Publisher.Name))]
public string Name { get; set; }

[CompareTo(nameof(Publisher.Authors))]
[CollectionFilter(CollectionFilterType.Any)]
public AuthorNestedFilter Authors { get; set; }
}

// Multiple property mapping
[GenerateApplyFilter(typeof(Book))]
public class BookFilter_MultiplePropertyOr : FilterBase
{
[CompareTo(nameof(Book.Title))]
public string SearchText { get; set; }
}

// Combined filter with all features
[GenerateApplyFilter(typeof(Author))]
public class AuthorFilter_Complete : PaginationFilterBase
{
[CompareTo(nameof(Author.Name))]
public StringFilter Name { get; set; }

[CompareTo(nameof(Author.Country))]
public string Country { get; set; }

[CompareTo(nameof(Author.Age))]
public OperatorFilter<int> Age { get; set; }

[CompareTo(nameof(Author.Books))]
[CollectionFilter(CollectionFilterType.Any)]
public BookNestedFilter Books { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;

namespace AutoFilterer.Generators.Tests.Environment.Models;

public class Book
{
public int Id { get; set; }
public string Title { get; set; }
public int TotalPage { get; set; }
public int Year { get; set; }
public bool IsPublished { get; set; }

// Navigation property
public int AuthorId { get; set; }
public Author Author { get; set; }
}

public class Author
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public int? Age { get; set; }
public List<Book> Books { get; set; } = new();
}

public class Publisher
{
public int Id { get; set; }
public string Name { get; set; }
public List<Author> Authors { get; set; } = new();
}
Loading
Loading