mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor mapping profiles
This commit is contained in:
parent
7d2b586ffb
commit
4eb9b1273e
5 changed files with 99 additions and 73 deletions
|
|
@ -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<Data.Entities.FilterList, ListSummaryDto>()
|
||||
.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<DateTime?>()
|
||||
.FirstOrDefault()));
|
||||
|
||||
private void CreateListDetailsDtoMap() =>
|
||||
CreateMap<Data.Entities.FilterList, ListDetailsDto>()
|
||||
.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<DateTime?>()
|
||||
.FirstOrDefault()));
|
||||
|
||||
private void CreateListMaintainerDtoMap() =>
|
||||
CreateMap<Maintainer, ListMaintainerDto>()
|
||||
.ForMember(dto => dto.AdditionalLists,
|
||||
conf => conf.MapFrom(maint =>
|
||||
maint.FilterListMaintainers.Select(listMaints => listMaints.FilterList)));
|
||||
|
||||
private void CreateListSyntaxDtoMap() =>
|
||||
CreateMap<Syntax, ListSyntaxDto>()
|
||||
.ForMember(dto => dto.SupportedSoftware,
|
||||
conf => conf.MapFrom(syntax => syntax.SoftwareSyntaxes.Select(softSyn => softSyn.Software)));
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Data.Entities.FilterList, ListDetailsDto>()
|
||||
.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<DateTime?>()
|
||||
.FirstOrDefault()));
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Maintainer, ListMaintainerDto>()
|
||||
.ForMember(dto => dto.AdditionalLists,
|
||||
conf => conf.MapFrom(maint =>
|
||||
maint.FilterListMaintainers.Select(listMaints => listMaints.FilterList)));
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Data.Entities.FilterList, ListSummaryDto>()
|
||||
.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<DateTime?>()
|
||||
.FirstOrDefault()));
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Syntax, ListSyntaxDto>()
|
||||
.ForMember(dto => dto.SupportedSoftware,
|
||||
conf => conf.MapFrom(syntax => syntax.SoftwareSyntaxes.Select(softSyn => softSyn.Software)));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue