mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add SyntaxIds to Software endpoint, make mapping profiles consistent
ref #505
This commit is contained in:
parent
ef360fe4a7
commit
fb8d308dc8
17 changed files with 183 additions and 97 deletions
|
|
@ -10,36 +10,46 @@ public class ListDetailsDtoMappingProfile : Profile
|
|||
{
|
||||
public ListDetailsDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.FilterList, ListDetailsDto>()
|
||||
.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
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id))
|
||||
.ForMember(dest => dest.Languages,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListLanguages.Select(la => la.Language.Name)))
|
||||
.ForMember(dest => dest.Maintainers,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListMaintainers.Select(m => m.Maintainer)))
|
||||
.ForMember(dest => dest.Tags,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListTags.Select(m => m.Tag)))
|
||||
.ForMember(dest => dest.RuleCount,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.Snapshots
|
||||
.Count(s => s.WasSuccessful) > 0
|
||||
? src.Snapshots
|
||||
.Where(s => s.WasSuccessful)
|
||||
.OrderByDescending(s => s.CreatedDateUtc)
|
||||
.FirstOrDefault()
|
||||
.SnapshotRules
|
||||
.Count
|
||||
: 0))
|
||||
.ForMember(dest => dest.UpdatedDate,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.DiscontinuedDate ??
|
||||
(src.Snapshots
|
||||
.Count(s => s.WasSuccessful && s.Md5Checksum != null) >= 2
|
||||
? src.Snapshots
|
||||
.Where(s => s.WasSuccessful && s.Md5Checksum != null)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(c => c)
|
||||
.FirstOrDefault()
|
||||
: null)))
|
||||
.ForMember(dest => dest.ViewUrl,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.Snapshots
|
||||
.Where(s => s.WasSuccessful)
|
||||
.OrderByDescending(s => s.CreatedDateUtc)
|
||||
.FirstOrDefault()
|
||||
.SnapshotRules
|
||||
.Count
|
||||
: 0))
|
||||
.ForMember(d => d.UpdatedDate,
|
||||
o => o.MapFrom(l =>
|
||||
l.DiscontinuedDate ??
|
||||
(l.Snapshots
|
||||
.Count(s => s.WasSuccessful && s.Md5Checksum != null) >= 2
|
||||
? l.Snapshots
|
||||
.Where(s => s.WasSuccessful && s.Md5Checksum != null)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(c => c)
|
||||
.FirstOrDefault()
|
||||
: null)))
|
||||
.ForMember(d => d.ViewUrl,
|
||||
o => o.MapFrom(l =>
|
||||
l.Snapshots
|
||||
.Where(s => s.WasSuccessful)
|
||||
.OrderByDescending(s => s.CreatedDateUtc)
|
||||
.FirstOrDefault()
|
||||
.WaybackUrl ?? l.ViewUrl));
|
||||
.WaybackUrl ?? src.ViewUrl));
|
||||
}
|
||||
}
|
||||
|
|
@ -11,43 +11,43 @@ public class ListIndexRecordMappingProfile : Profile
|
|||
{
|
||||
public ListIndexRecordMappingProfile() =>
|
||||
CreateMap<Data.Entities.FilterList, ListIndexRecord>()
|
||||
.ForMember(r => r.Id,
|
||||
o => o.MapFrom(l =>
|
||||
(int)l.Id))
|
||||
.ForMember(r => r.LanguageIds,
|
||||
o => o.MapFrom(l =>
|
||||
l.FilterListLanguages.Select(ll => (int)ll.LanguageId)))
|
||||
.ForMember(r => r.MaintainerIds,
|
||||
o => o.MapFrom(l =>
|
||||
l.FilterListMaintainers.Select(ll => (int)ll.MaintainerId)))
|
||||
.ForMember(r => r.RuleCount,
|
||||
o => o.MapFrom(l =>
|
||||
l.Snapshots
|
||||
.Where(s => s.WasSuccessful)
|
||||
.Select(s => (int?)s.SnapshotRules.Count)
|
||||
.FirstOrDefault()))
|
||||
.ForMember(r => r.SyntaxId,
|
||||
o => o.MapFrom(l =>
|
||||
(int)l.SyntaxId))
|
||||
.ForMember(r => r.TagIds,
|
||||
o => o.MapFrom(l =>
|
||||
l.FilterListTags.Select(lt => (int)lt.TagId)))
|
||||
.ForMember(r => r.UpdatedDate,
|
||||
o => o.MapFrom(l =>
|
||||
l.Snapshots
|
||||
.Count(s => s.WasSuccessful && s.WasUpdated) >= 2
|
||||
? l.Snapshots
|
||||
.Where(s => s.WasSuccessful && s.WasUpdated)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(c => c)
|
||||
.FirstOrDefault()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id))
|
||||
.ForMember(dest => dest.LanguageIds,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListLanguages.Select(ll => (int)ll.LanguageId)))
|
||||
.ForMember(dest => dest.MaintainerIds,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListMaintainers.Select(ll => (int)ll.MaintainerId)))
|
||||
.ForMember(dest => dest.RuleCount,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.Snapshots
|
||||
.Where(s => s.WasSuccessful)
|
||||
.Select(s => (int?)s.SnapshotRules.Count)
|
||||
.FirstOrDefault()))
|
||||
.ForMember(dest => dest.SyntaxId,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.SyntaxId))
|
||||
.ForMember(dest => dest.TagIds,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListTags.Select(lt => (int)lt.TagId)))
|
||||
.ForMember(dest => dest.UpdatedDate,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.Snapshots
|
||||
.Count(s => s.WasSuccessful && s.WasUpdated) >= 2
|
||||
? src.Snapshots
|
||||
.Where(s => s.WasSuccessful && s.WasUpdated)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(c => c)
|
||||
.FirstOrDefault()
|
||||
: null))
|
||||
.ForMember(r => r.ViewUrlMirrors,
|
||||
o => o.MapFrom(l =>
|
||||
l.ViewUrlMirror1 != null
|
||||
? l.ViewUrlMirror2 != null
|
||||
? new List<string> {l.ViewUrlMirror1, l.ViewUrlMirror2}
|
||||
: new List<string> {l.ViewUrlMirror1}
|
||||
.ForMember(dest => dest.ViewUrlMirrors,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.ViewUrlMirror1 != null
|
||||
? src.ViewUrlMirror2 != null
|
||||
? new List<string> {src.ViewUrlMirror1, src.ViewUrlMirror2}
|
||||
: new List<string> {src.ViewUrlMirror1}
|
||||
: null));
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,11 @@ public class ListMaintainerDtoMappingProfile : Profile
|
|||
{
|
||||
public ListMaintainerDtoMappingProfile() =>
|
||||
CreateMap<Maintainer, ListMaintainerDto>()
|
||||
.ForMember(d => d.AdditionalLists,
|
||||
o => o.MapFrom(m => m.FilterListMaintainers.Select(lm => lm.FilterList)));
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id))
|
||||
.ForMember(dest => dest.AdditionalLists,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListMaintainers.Select(lm => lm.FilterList)));
|
||||
}
|
||||
}
|
||||
|
|
@ -10,25 +10,31 @@ public class ListSummaryDtoMappingProfile : Profile
|
|||
{
|
||||
public ListSummaryDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.FilterList, ListSummaryDto>()
|
||||
.ForMember(d => d.Languages, o => o.MapFrom(l => l.FilterListLanguages.Select(la => la.Language)))
|
||||
.ForMember(d => d.SoftwareIds,
|
||||
o => o.MapFrom(l =>
|
||||
l.Syntax
|
||||
.SoftwareSyntaxes
|
||||
.Select(ss => ss.Software)
|
||||
.OrderBy(s => s.Name)
|
||||
.Select(s => (int)s.Id)))
|
||||
.ForMember(d => d.Tags, o => o.MapFrom(l => l.FilterListTags.Select(m => m.Tag)))
|
||||
.ForMember(d => d.UpdatedDate,
|
||||
o => o.MapFrom(l =>
|
||||
l.DiscontinuedDate ??
|
||||
(l.Snapshots
|
||||
.Count(s => s.WasSuccessful && s.Md5Checksum != null) >= 2
|
||||
? l.Snapshots
|
||||
.Where(s => s.WasSuccessful && s.Md5Checksum != null)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(c => c)
|
||||
.FirstOrDefault()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id))
|
||||
.ForMember(dest => dest.Languages,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListLanguages.Select(la => la.Language)))
|
||||
.ForMember(dest => dest.SoftwareIds,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.Syntax
|
||||
.SoftwareSyntaxes
|
||||
.Select(ss => ss.Software)
|
||||
.OrderBy(s => s.Name)
|
||||
.Select(s => (int)s.Id)))
|
||||
.ForMember(dest => dest.Tags,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.FilterListTags.Select(m => m.Tag)))
|
||||
.ForMember(dest => dest.UpdatedDate,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.DiscontinuedDate ??
|
||||
(src.Snapshots.Count(s => s.WasSuccessful && s.Md5Checksum != null) >= 2
|
||||
? src.Snapshots
|
||||
.Where(s => s.WasSuccessful && s.Md5Checksum != null)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(c => c)
|
||||
.FirstOrDefault()
|
||||
: null)));
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,10 @@ public class ListSyntaxDtoMappingProfile : Profile
|
|||
{
|
||||
public ListSyntaxDtoMappingProfile() =>
|
||||
CreateMap<Syntax, ListSyntaxDto>()
|
||||
.ForMember(d => d.SupportedSoftware,
|
||||
o => o.MapFrom(s => s.SoftwareSyntaxes.Select(ss => ss.Software).OrderBy(sw => sw.Name)));
|
||||
.ForMember(dest => dest.SupportedSoftware,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.SoftwareSyntaxes
|
||||
.Select(ss => ss.Software)
|
||||
.OrderBy(s => s.Name)));
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,9 @@ namespace FilterLists.Services.FilterList.MappingProfiles
|
|||
public class ListTagDtoMappingProfile : Profile
|
||||
{
|
||||
public ListTagDtoMappingProfile() =>
|
||||
CreateMap<Tag, ListTagDto>().ForMember(d => d.ColorHex, o => o.MapFrom(m => TagColors.Colors[(int)m.Id]));
|
||||
CreateMap<Tag, ListTagDto>()
|
||||
.ForMember(dest => dest.ColorHex,
|
||||
opt => opt.MapFrom(src =>
|
||||
TagColors.Colors[(int)src.Id]));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using AutoMapper;
|
||||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Services.FilterList.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.FilterList.MappingProfiles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class MaintainerAdditionalListsDtoMappingProfile : Profile
|
||||
{
|
||||
public MaintainerAdditionalListsDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.FilterList, MaintainerAdditionalListsDto>()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using AutoMapper;
|
||||
using FilterLists.Services.FilterList.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.FilterList.MappingProfiles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SyntaxSupportedSoftwareDtoMappingProfile : Profile
|
||||
{
|
||||
public SyntaxSupportedSoftwareDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.Software, SyntaxSupportedSoftwareDto>()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id));
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ namespace FilterLists.Services.FilterList.Models
|
|||
[UsedImplicitly]
|
||||
public class ListDetailsDto
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string ChatUrl { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DescriptionSourceUrl { get; set; }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace FilterLists.Services.FilterList.Models
|
|||
[UsedImplicitly]
|
||||
public class ListMaintainerDto
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string HomeUrl { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace FilterLists.Services.FilterList.Models
|
|||
[UsedImplicitly]
|
||||
public class ListSummaryDto
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public IEnumerable<ListLanguagesDto> Languages { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IEnumerable<int> SoftwareIds { get; set; }
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace FilterLists.Services.FilterList.Models
|
|||
[UsedImplicitly]
|
||||
public class MaintainerAdditionalListsDto
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -5,8 +5,8 @@ namespace FilterLists.Services.FilterList.Models
|
|||
[UsedImplicitly]
|
||||
public class SyntaxSupportedSoftwareDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string HomeUrl { get; set; }
|
||||
public uint Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ public class LanguageDtoMappingProfile : Profile
|
|||
{
|
||||
public LanguageDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.Language, LanguageDto>()
|
||||
.ForMember(d => d.Id, o => o.MapFrom(l => (int)l.Id));
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using FilterLists.Services.Software.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.FilterList.MappingProfiles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SoftwareDtoMappingProfile : Profile
|
||||
{
|
||||
public SoftwareDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.Software, SoftwareDto>()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id))
|
||||
.ForMember(dest => dest.SyntaxIds,
|
||||
opt => opt.MapFrom(src =>
|
||||
src.SoftwareSyntaxes.Select(ss => (int)ss.SyntaxId)));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
using JetBrains.Annotations;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.Software.Models
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SoftwareDto
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<int> SyntaxIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,9 @@ public SoftwareService(FilterListsDbContext dbContext, IConfigurationProvider ma
|
|||
}
|
||||
|
||||
public async Task<IEnumerable<SoftwareDto>> GetAll() =>
|
||||
await DbContext.Software.OrderBy(s => s.Name).ProjectTo<SoftwareDto>(MapConfig).ToListAsync();
|
||||
await DbContext.Software
|
||||
.OrderBy(s => s.Name)
|
||||
.ProjectTo<SoftwareDto>(MapConfig)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue