From 593d3ed39b187df147a2baf4f44d3178cc1b4a85 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 24 Aug 2018 14:54:14 -0500 Subject: [PATCH] fix list rulecounts --- .../ListDetailsDtoMappingProfile.cs | 23 +++++++++++-------- .../ListMaintainerDtoMappingProfile.cs | 2 +- .../ListSummaryDtoMappingProfile.cs | 7 +++--- .../ListSyntaxDtoMappingProfile.cs | 2 +- .../ListTagDtoMappingProfile.cs | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs index 145ca8bd6..eb9d323ed 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs @@ -8,16 +8,21 @@ namespace FilterLists.Services.FilterList.MappingProfiles [UsedImplicitly] public class ListDetailsDtoMappingProfile : Profile { - //TODO: fix UpdatedDate and RuleCount public ListDetailsDtoMappingProfile() => CreateMap() - .ForMember(d => d.Languages, c => c.MapFrom(l => l.FilterListLanguages.Select(la => la.Language.Name))) - .ForMember(d => d.Maintainers, c => c.MapFrom(l => l.FilterListMaintainers.Select(m => m.Maintainer))) - .ForMember(d => d.Tags, c => c.MapFrom(l => l.FilterListTags.Select(m => m.Tag))) - .ForMember(d => d.RuleCount, - c => c.MapFrom(l => 0)) - .ForMember(d => d.UpdatedDate, - c => c.MapFrom(l => - l.ModifiedDateUtc)); + .ForMember(d => d.Languages, o => o.MapFrom(l => l.FilterListLanguages.Select(la => la.Language.Name))) + .ForMember(d => d.Maintainers, o => o.MapFrom(l => l.FilterListMaintainers.Select(m => m.Maintainer))) + .ForMember(d => d.Tags, o => o.MapFrom(l => l.FilterListTags.Select(m => m.Tag))) + .ForMember(d => d.RuleCount, o => o.MapFrom(l => + l.Snapshots + .Count(s => s.WasSuccessful) > 0 + ? l.Snapshots + .Where(s => s.WasSuccessful) + .OrderByDescending(s => s.CreatedDateUtc) + .FirstOrDefault() + .SnapshotRules + .Count + : 0)) + .ForMember(d => d.UpdatedDate, o => o.MapFrom(l => l.ModifiedDateUtc)); } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs index a54f3eec3..532e24e7b 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs @@ -12,6 +12,6 @@ public class ListMaintainerDtoMappingProfile : Profile public ListMaintainerDtoMappingProfile() => CreateMap() .ForMember(d => d.AdditionalLists, - c => c.MapFrom(m => m.FilterListMaintainers.Select(lm => lm.FilterList))); + o => o.MapFrom(m => m.FilterListMaintainers.Select(lm => lm.FilterList))); } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListSummaryDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListSummaryDtoMappingProfile.cs index 3a4274cbe..d6ae4a3d4 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles/ListSummaryDtoMappingProfile.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListSummaryDtoMappingProfile.cs @@ -8,11 +8,10 @@ namespace FilterLists.Services.FilterList.MappingProfiles [UsedImplicitly] public class ListSummaryDtoMappingProfile : Profile { - //TODO: fix UpdatedDate to look at most recent snapshot with changes public ListSummaryDtoMappingProfile() => CreateMap() - .ForMember(d => d.Languages, c => c.MapFrom(l => l.FilterListLanguages.Select(la => la.Language))) - .ForMember(d => d.Tags, c => c.MapFrom(l => l.FilterListTags.Select(m => m.Tag))) - .ForMember(d => d.UpdatedDate, c => c.MapFrom(l => l.ModifiedDateUtc)); + .ForMember(d => d.Languages, o => o.MapFrom(l => l.FilterListLanguages.Select(la => la.Language))) + .ForMember(d => d.Tags, o => o.MapFrom(l => l.FilterListTags.Select(m => m.Tag))) + .ForMember(d => d.UpdatedDate, o => o.MapFrom(l => l.ModifiedDateUtc)); } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs index 084058287..ae720c35e 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs @@ -11,6 +11,6 @@ public class ListSyntaxDtoMappingProfile : Profile { public ListSyntaxDtoMappingProfile() => CreateMap() - .ForMember(d => d.SupportedSoftware, c => c.MapFrom(s => s.SoftwareSyntaxes.Select(ss => ss.Software))); + .ForMember(d => d.SupportedSoftware, o => o.MapFrom(s => s.SoftwareSyntaxes.Select(ss => ss.Software))); } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListTagDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListTagDtoMappingProfile.cs index 5925950c8..c7f75460c 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles/ListTagDtoMappingProfile.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListTagDtoMappingProfile.cs @@ -9,6 +9,6 @@ namespace FilterLists.Services.FilterList.MappingProfiles public class ListTagDtoMappingProfile : Profile { public ListTagDtoMappingProfile() => - CreateMap().ForMember(d => d.ColorHex, c => c.MapFrom(m => TagColors.Colors[(int)m.Id])); + CreateMap().ForMember(d => d.ColorHex, o => o.MapFrom(m => TagColors.Colors[(int)m.Id])); } } \ No newline at end of file