Skip to content

Commit

Permalink
[BR-3461] Expose filter/sort values to make serialization easier
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanjthompson committed Sep 8, 2023
1 parent 9eb9d41 commit ca92c6d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 37 deletions.
6 changes: 4 additions & 2 deletions Gibe.Umbraco.Blog/Filters/AtLeastOneMatchingTagFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class AtLeastOneMatchingTagFilter : IBlogPostFilter
{
public IEnumerable<string> Tags { get; }

public AtLeastOneMatchingTagFilter() { }

public AtLeastOneMatchingTagFilter(IEnumerable<string> tags)
{
Tags = tags?.Select(t => t.ToLower()).ToList(); ;
Expand All @@ -15,7 +19,5 @@ public IBooleanOperation GetCriteria(IQuery query)
{
return query.GroupedOr(new[] { ExamineFields.Tag }, Tags.ToArray());
}

public IEnumerable<string> Tags { get; }
}
}
8 changes: 5 additions & 3 deletions Gibe.Umbraco.Blog/Filters/AuthorBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class AuthorBlogPostFilter : IBlogPostFilter
{
private readonly string _author;
public string Author { get; set; }

public AuthorBlogPostFilter() { }

public AuthorBlogPostFilter(string author)
{
_author = author;
Author = author;
}

public IBooleanOperation GetCriteria(IQuery query)
{
return query.ManagedQuery(_author.ToLower(), new[] { ExamineFields.PostAuthorName });
return query.ManagedQuery(Author.ToLower(), new[] { ExamineFields.PostAuthorName });
}
}
}
8 changes: 5 additions & 3 deletions Gibe.Umbraco.Blog/Filters/CategoryBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class CategoryBlogPostFilter : IBlogPostFilter
{
private readonly string _categoryName;
public string CategoryName { get; set; }

public CategoryBlogPostFilter() { }

public CategoryBlogPostFilter(string categoryName)
{
_categoryName = categoryName;
CategoryName = categoryName;
}

public IBooleanOperation GetCriteria(IQuery query)
{
return query.ManagedQuery(_categoryName.ToLower(), new[] { ExamineFields.CategoryName });
return query.ManagedQuery(CategoryName.ToLower(), new[] { ExamineFields.CategoryName });
}
}
}
26 changes: 14 additions & 12 deletions Gibe.Umbraco.Blog/Filters/DateBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class DateBlogPostFilter : IBlogPostFilter
{
private readonly int _year;
private readonly int? _month;
private readonly int? _day;
public int Year { get; set; }
public int? Month { get; set; }
public int? Day { get; set; }

public DateBlogPostFilter() { }

public DateBlogPostFilter(int year, int? month = null, int? day = null)
{
_year = year;
_month = month;
_day = day;
Year = year;
Month = month;
Day = day;
}

public IBooleanOperation GetCriteria(IQuery query)
{
var output = query.Field(ExamineFields.PostDateYear, _year.ToString("00"));
var output = query.Field(ExamineFields.PostDateYear, Year.ToString("00"));

if (_month.HasValue)
if (Month.HasValue)
{
output = output.And().Field(ExamineFields.PostDateMonth, _month.Value.ToString("00"));
output = output.And().Field(ExamineFields.PostDateMonth, Month.Value.ToString("00"));
}
if (_day.HasValue)
if (Day.HasValue)
{
output = output.And().Field(ExamineFields.PostDateDay, _day.Value.ToString("00"));
output = output.And().Field(ExamineFields.PostDateDay, Day.Value.ToString("00"));
}
return output;
}
Expand Down
6 changes: 3 additions & 3 deletions Gibe.Umbraco.Blog/Filters/SearchTermBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class SearchTermBlogPostFilter : IBlogPostFilter
{
private readonly string _searchTerm;
public string SearchTerm { get; set; }

public SearchTermBlogPostFilter(string searchTerm)
{
_searchTerm = searchTerm;
SearchTerm = searchTerm;
}

public IBooleanOperation GetCriteria(IQuery query)
{
return query.Field(ExamineFields.BodyText, _searchTerm);
return query.Field(ExamineFields.BodyText, SearchTerm);
}
}
}
6 changes: 3 additions & 3 deletions Gibe.Umbraco.Blog/Filters/SectionBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class SectionBlogPostFilter : IBlogPostFilter
{
private readonly int _sectionNodeId;
public int SectionNodeId;

public SectionBlogPostFilter(int sectionNodeId)
{
_sectionNodeId = sectionNodeId;
SectionNodeId = sectionNodeId;
}

public IBooleanOperation GetCriteria(IQuery query)
{
return query.Field(ExamineFields.Path, _sectionNodeId.ToString());
return query.Field(ExamineFields.Path, SectionNodeId.ToString());
}
}
}
10 changes: 5 additions & 5 deletions Gibe.Umbraco.Blog/Filters/StandardBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class StandardBlogPostFilter : IBlogPostFilter
{
private readonly string _propertyName;
private readonly string _propertyValue;
public string PropertyName { get; set; }
public string PropertyValue { get; set; }

public StandardBlogPostFilter(string propertyName, string value)
{
_propertyName = propertyName;
_propertyValue = value;
PropertyName = propertyName;
PropertyValue = value;
}

public IBooleanOperation GetCriteria(IQuery query)
{
return query.Field(_propertyName, _propertyValue);
return query.Field(PropertyName, PropertyValue);
}
}
}
6 changes: 3 additions & 3 deletions Gibe.Umbraco.Blog/Filters/TagBlogPostFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Gibe.Umbraco.Blog.Filters
{
public class TagBlogPostFilter : IBlogPostFilter
{
private readonly string _tag;
public string Tag { get; set; }

public TagBlogPostFilter(string tag)
{
_tag = tag;
Tag = tag;
}

public IBooleanOperation GetCriteria(IQuery query)
{
return query.ManagedQuery(_tag.ToLower(), new[] {ExamineFields.Tag});
return query.ManagedQuery(Tag.ToLower(), new[] {ExamineFields.Tag});
}
}
}
6 changes: 3 additions & 3 deletions Gibe.Umbraco.Blog/Sort/DateSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Gibe.Umbraco.Blog.Sort
{
public class DateSort : ISort
{
private readonly bool _descending;
public bool Descending { get; set; }

public DateSort(bool descending = true)
{
_descending = descending;
Descending = descending;
}

public IOrdering GetCriteria(IBooleanOperation query)
{
if (_descending)
if (Descending)
{
return query.And().All().OrderByDescending(new SortableField(ExamineFields.PostDate, SortType.Long));
}
Expand Down

0 comments on commit ca92c6d

Please sign in to comment.