From ca92c6d3dde4b0b8575f6fff7b375a07000df006 Mon Sep 17 00:00:00 2001 From: Tristan Thompson Date: Fri, 8 Sep 2023 14:43:54 +0100 Subject: [PATCH] [BR-3461] Expose filter/sort values to make serialization easier --- .../Filters/AtLeastOneMatchingTagFilter.cs | 6 +++-- .../Filters/AuthorBlogPostFilter.cs | 8 +++--- .../Filters/CategoryBlogPostFilter.cs | 8 +++--- .../Filters/DateBlogPostFilter.cs | 26 ++++++++++--------- .../Filters/SearchTermBlogPostFilter.cs | 6 ++--- .../Filters/SectionBlogPostFilter.cs | 6 ++--- .../Filters/StandardBlogPostFilter.cs | 10 +++---- .../Filters/TagBlogPostFilter.cs | 6 ++--- Gibe.Umbraco.Blog/Sort/DateSort.cs | 6 ++--- 9 files changed, 45 insertions(+), 37 deletions(-) diff --git a/Gibe.Umbraco.Blog/Filters/AtLeastOneMatchingTagFilter.cs b/Gibe.Umbraco.Blog/Filters/AtLeastOneMatchingTagFilter.cs index 2250991..1f7b7cd 100644 --- a/Gibe.Umbraco.Blog/Filters/AtLeastOneMatchingTagFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/AtLeastOneMatchingTagFilter.cs @@ -6,6 +6,10 @@ namespace Gibe.Umbraco.Blog.Filters { public class AtLeastOneMatchingTagFilter : IBlogPostFilter { + public IEnumerable Tags { get; } + + public AtLeastOneMatchingTagFilter() { } + public AtLeastOneMatchingTagFilter(IEnumerable tags) { Tags = tags?.Select(t => t.ToLower()).ToList(); ; @@ -15,7 +19,5 @@ public IBooleanOperation GetCriteria(IQuery query) { return query.GroupedOr(new[] { ExamineFields.Tag }, Tags.ToArray()); } - - public IEnumerable Tags { get; } } } \ No newline at end of file diff --git a/Gibe.Umbraco.Blog/Filters/AuthorBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/AuthorBlogPostFilter.cs index 09f4582..95f5e66 100644 --- a/Gibe.Umbraco.Blog/Filters/AuthorBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/AuthorBlogPostFilter.cs @@ -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 }); } } } \ No newline at end of file diff --git a/Gibe.Umbraco.Blog/Filters/CategoryBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/CategoryBlogPostFilter.cs index 63bc231..985ab2d 100644 --- a/Gibe.Umbraco.Blog/Filters/CategoryBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/CategoryBlogPostFilter.cs @@ -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 }); } } } diff --git a/Gibe.Umbraco.Blog/Filters/DateBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/DateBlogPostFilter.cs index 75e71fe..0ef6d0b 100644 --- a/Gibe.Umbraco.Blog/Filters/DateBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/DateBlogPostFilter.cs @@ -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; } diff --git a/Gibe.Umbraco.Blog/Filters/SearchTermBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/SearchTermBlogPostFilter.cs index f35934d..9d0331a 100644 --- a/Gibe.Umbraco.Blog/Filters/SearchTermBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/SearchTermBlogPostFilter.cs @@ -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); } } } diff --git a/Gibe.Umbraco.Blog/Filters/SectionBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/SectionBlogPostFilter.cs index 326222e..6630f73 100644 --- a/Gibe.Umbraco.Blog/Filters/SectionBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/SectionBlogPostFilter.cs @@ -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()); } } } \ No newline at end of file diff --git a/Gibe.Umbraco.Blog/Filters/StandardBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/StandardBlogPostFilter.cs index 4adbb74..435ea4c 100644 --- a/Gibe.Umbraco.Blog/Filters/StandardBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/StandardBlogPostFilter.cs @@ -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); } } } \ No newline at end of file diff --git a/Gibe.Umbraco.Blog/Filters/TagBlogPostFilter.cs b/Gibe.Umbraco.Blog/Filters/TagBlogPostFilter.cs index 777e389..491d6c5 100644 --- a/Gibe.Umbraco.Blog/Filters/TagBlogPostFilter.cs +++ b/Gibe.Umbraco.Blog/Filters/TagBlogPostFilter.cs @@ -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}); } } } \ No newline at end of file diff --git a/Gibe.Umbraco.Blog/Sort/DateSort.cs b/Gibe.Umbraco.Blog/Sort/DateSort.cs index 2d3793a..2d5d94d 100644 --- a/Gibe.Umbraco.Blog/Sort/DateSort.cs +++ b/Gibe.Umbraco.Blog/Sort/DateSort.cs @@ -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)); }