diff --git a/src/FilterLists.Services/FilterList/MappingProfiles.cs b/src/FilterLists.Services/FilterList/MappingProfiles.cs deleted file mode 100644 index 3561a29f7..000000000 --- a/src/FilterLists.Services/FilterList/MappingProfiles.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Linq; -using AutoMapper; -using FilterLists.Data.Entities; -using FilterLists.Services.FilterList.Models; -using JetBrains.Annotations; - -namespace FilterLists.Services.FilterList -{ - [UsedImplicitly] - public class MappingProfiles : Profile - { - public MappingProfiles() - { - CreateListSummaryDtoMap(); - CreateListDetailsDtoMap(); - CreateListMaintainerDtoMap(); - CreateListSyntaxDtoMap(); - } - - private void CreateListSummaryDtoMap() => - CreateMap() - .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)) - .ForMember(dto => dto.Languages, - conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language))) - .ForMember(dto => dto.UpdatedDate, - conf => conf.MapFrom(list => - list.Snapshots.Where(s => - s.IsCompleted && s.HttpStatusCode == "200" && - (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) - .OrderByDescending(s => s.CreatedDateUtc) - .Select(s => s.CreatedDateUtc) - .Cast() - .FirstOrDefault())); - - private void CreateListDetailsDtoMap() => - CreateMap() - .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)) - .ForMember(dto => dto.Languages, - conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language.Name))) - .ForMember(dto => dto.Maintainers, - conf => conf.MapFrom(list => - list.FilterListMaintainers.Select(listMaints => listMaints.Maintainer))) - .ForMember(dto => dto.RuleCount, - conf => conf.MapFrom(list => - list.Snapshots.Where(s => s.IsCompleted && s.HttpStatusCode == "200") - .SelectMany(sr => sr.AddedSnapshotRules) - .Count() - - list.Snapshots.Where(s => s.IsCompleted && s.HttpStatusCode == "200") - .SelectMany(sr => sr.RemovedSnapshotRules) - .Count())) - .ForMember(dto => dto.UpdatedDate, - conf => conf.MapFrom(list => - list.Snapshots.Where(s => - s.IsCompleted && s.HttpStatusCode == "200" && - (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) - .OrderByDescending(s => s.CreatedDateUtc) - .Select(s => s.CreatedDateUtc) - .Cast() - .FirstOrDefault())); - - private void CreateListMaintainerDtoMap() => - CreateMap() - .ForMember(dto => dto.AdditionalLists, - conf => conf.MapFrom(maint => - maint.FilterListMaintainers.Select(listMaints => listMaints.FilterList))); - - private void CreateListSyntaxDtoMap() => - CreateMap() - .ForMember(dto => dto.SupportedSoftware, - conf => conf.MapFrom(syntax => syntax.SoftwareSyntaxes.Select(softSyn => softSyn.Software))); - } -} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs new file mode 100644 index 000000000..b6ad13e77 --- /dev/null +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListDetailsDtoMappingProfile.cs @@ -0,0 +1,37 @@ +using System; +using System.Linq; +using AutoMapper; +using FilterLists.Services.FilterList.Models; +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList.MappingProfiles +{ + [UsedImplicitly] + public class ListDetailsDtoMappingProfile : Profile + { + public ListDetailsDtoMappingProfile() => + CreateMap() + .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)) + .ForMember(dto => dto.Languages, + conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language.Name))) + .ForMember(dto => dto.Maintainers, + conf => conf.MapFrom(list => + list.FilterListMaintainers.Select(listMaints => listMaints.Maintainer))) + .ForMember(dto => dto.RuleCount, + conf => conf.MapFrom(list => + list.Snapshots.Where(s => s.IsCompleted && s.HttpStatusCode == "200") + .SelectMany(sr => sr.AddedSnapshotRules) + .Count() - list.Snapshots.Where(s => s.IsCompleted && s.HttpStatusCode == "200") + .SelectMany(sr => sr.RemovedSnapshotRules) + .Count())) + .ForMember(dto => dto.UpdatedDate, + conf => conf.MapFrom(list => + list.Snapshots.Where(s => + s.IsCompleted && s.HttpStatusCode == "200" && + (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) + .OrderByDescending(s => s.CreatedDateUtc) + .Select(s => s.CreatedDateUtc) + .Cast() + .FirstOrDefault())); + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs new file mode 100644 index 000000000..612cfb3d3 --- /dev/null +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListMaintainerDtoMappingProfile.cs @@ -0,0 +1,18 @@ +using System.Linq; +using AutoMapper; +using FilterLists.Data.Entities; +using FilterLists.Services.FilterList.Models; +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList.MappingProfiles +{ + [UsedImplicitly] + public class ListMaintainerDtoMappingProfile : Profile + { + public ListMaintainerDtoMappingProfile() => + CreateMap() + .ForMember(dto => dto.AdditionalLists, + conf => conf.MapFrom(maint => + maint.FilterListMaintainers.Select(listMaints => listMaints.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 new file mode 100644 index 000000000..53867243c --- /dev/null +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListSummaryDtoMappingProfile.cs @@ -0,0 +1,27 @@ +using System; +using System.Linq; +using AutoMapper; +using FilterLists.Services.FilterList.Models; +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList.MappingProfiles +{ + [UsedImplicitly] + public class ListSummaryDtoMappingProfile : Profile + { + public ListSummaryDtoMappingProfile() => + CreateMap() + .ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc)) + .ForMember(dto => dto.Languages, + conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language))) + .ForMember(dto => dto.UpdatedDate, + conf => conf.MapFrom(list => + list.Snapshots.Where(s => + s.IsCompleted && s.HttpStatusCode == "200" && + (s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)) + .OrderByDescending(s => s.CreatedDateUtc) + .Select(s => s.CreatedDateUtc) + .Cast() + .FirstOrDefault())); + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs new file mode 100644 index 000000000..a2a7f9fd2 --- /dev/null +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs @@ -0,0 +1,17 @@ +using System.Linq; +using AutoMapper; +using FilterLists.Data.Entities; +using FilterLists.Services.FilterList.Models; +using JetBrains.Annotations; + +namespace FilterLists.Services.FilterList.MappingProfiles +{ + [UsedImplicitly] + public class ListSyntaxDtoMappingProfile : Profile + { + public ListSyntaxDtoMappingProfile() => + CreateMap() + .ForMember(dto => dto.SupportedSoftware, + conf => conf.MapFrom(syntax => syntax.SoftwareSyntaxes.Select(softSyn => softSyn.Software))); + } +} \ No newline at end of file