fill out/standardize some API endpoints

ref #505
This commit is contained in:
collinbarrett 2018-09-26 13:26:17 -05:00
parent f4f1298448
commit c121ca555e
16 changed files with 44 additions and 28 deletions

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
@ -18,14 +17,13 @@ public FilterListService(FilterListsDbContext dbContext, IConfigurationProvider
public async Task<IEnumerable<List>> GetAllAsync() =>
await DbContext.FilterLists
.OrderBy(l => l.Name)
.ProjectTo<List>(MapConfig)
.ToListAsync();
public async Task<ListDetails> GetDetailsAsync(int id) =>
await DbContext.FilterLists
.ProjectTo<ListDetails>(MapConfig)
.FirstOrDefaultAsync(x => x.Id == id)
.FirstOrDefaultAsync(l => l.Id == id)
.FilterParentListFromMaintainerAdditionalLists();
}
}

View file

@ -22,8 +22,7 @@ public LanguageService(FilterListsDbContext dbContext, IConfigurationProvider ma
DbContext.Languages.Where(l => l.FilterListLanguages.Any());
public async Task<IEnumerable<LanguageDto>> GetAllTargetedAsync() =>
await TargetedLanguages.OrderBy(s => s.Name)
.ProjectTo<LanguageDto>(MapConfig)
await TargetedLanguages.ProjectTo<LanguageDto>(MapConfig)
.ToListAsync();
public async Task<LanguageDto> GetTargetedByIdAsync(int id) =>

View file

@ -1,4 +1,5 @@
using AutoMapper;
using System.Linq;
using AutoMapper;
using FilterLists.Services.Language.Models;
using JetBrains.Annotations;
@ -11,6 +12,10 @@ public LanguageDtoMappingProfile() =>
CreateMap<Data.Entities.Language, LanguageDto>()
.ForMember(dest => dest.Id,
opt => opt.MapFrom(src =>
(int)src.Id));
(int)src.Id))
.ForMember(dest => dest.FilterListIds,
opt => opt.MapFrom(src =>
src.FilterListLanguages
.Select(fl => (int)fl.FilterListId)));
}
}

View file

@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace FilterLists.Services.Language.Models
{
@ -6,6 +7,7 @@ namespace FilterLists.Services.Language.Models
public class LanguageDto
{
public int Id { get; set; }
public List<int> FilterListIds { get; set; }
public string Iso6391 { get; set; }
public string Name { get; set; }
}

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
@ -20,7 +19,6 @@ public LicenseService(FilterListsDbContext dbContext, IConfigurationProvider map
public async Task<IEnumerable<LicenseDto>> GetAllAsync() =>
await DbContext.Licenses
.OrderBy(s => s.Name)
.ProjectTo<LicenseDto>(MapConfig)
.ToListAsync();

View file

@ -1,4 +1,5 @@
using AutoMapper;
using System.Linq;
using AutoMapper;
using FilterLists.Services.License.Models;
using JetBrains.Annotations;
@ -11,6 +12,10 @@ public LicenseDtoMappingProfile() =>
CreateMap<Data.Entities.License, LicenseDto>()
.ForMember(dest => dest.Id,
opt => opt.MapFrom(src =>
(int)src.Id));
(int)src.Id))
.ForMember(dest => dest.FilterListIds,
opt => opt.MapFrom(src =>
src.FilterLists
.Select(l => (int)l.Id)));
}
}

View file

@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace FilterLists.Services.License.Models
{
@ -7,6 +8,7 @@ public class LicenseDto
{
public int Id { get; set; }
public string DescriptionUrl { get; set; }
public List<int> FilterListIds { get; set; }
public string Name { get; set; }
}
}

View file

@ -25,6 +25,6 @@ await DbContext.Maintainers
public async Task<MaintainerDto> GetByIdAsync(int id) =>
await DbContext.Maintainers
.ProjectTo<MaintainerDto>(MapConfig)
.FirstOrDefaultAsync(l => l.Id == id);
.FirstOrDefaultAsync(m => m.Id == id);
}
}

View file

@ -19,15 +19,15 @@ public SeedService(FilterListsDbContext dbContext, IConfigurationProvider mapCon
}
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>() where TEntity : class =>
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>(MapConfig).ToArrayAsync();
await DbContext.Set<TEntity>().ProjectTo<TSeedDto>(MapConfig).ToListAsync();
public async Task<IEnumerable<TSeedDto>> GetAllAsync<TEntity, TSeedDto>(PropertyInfo primarySort,
PropertyInfo secondarySort)
where TEntity : class =>
await DbContext.Set<TEntity>()
.OrderBy(x => primarySort.GetValue(x, null))
.ThenBy(x => secondarySort.GetValue(x, null))
.OrderBy(s => primarySort.GetValue(s, null))
.ThenBy(s => secondarySort.GetValue(s, null))
.ProjectTo<TSeedDto>(MapConfig)
.ToArrayAsync();
.ToListAsync();
}
}

View file

@ -3,7 +3,7 @@
using FilterLists.Services.Software.Models;
using JetBrains.Annotations;
namespace FilterLists.Services.FilterList.MappingProfiles
namespace FilterLists.Services.Software.MappingProfiles
{
[UsedImplicitly]
public class SoftwareDtoMappingProfile : Profile
@ -15,6 +15,7 @@ public SoftwareDtoMappingProfile() =>
(int)src.Id))
.ForMember(dest => dest.SyntaxIds,
opt => opt.MapFrom(src =>
src.SoftwareSyntaxes.Select(ss => (int)ss.SyntaxId)));
src.SoftwareSyntaxes
.Select(ss => (int)ss.SyntaxId)));
}
}

View file

@ -7,6 +7,8 @@ namespace FilterLists.Services.Software.Models
public class SoftwareDto
{
public int Id { get; set; }
public string HomeUrl { get; set; }
public bool IsAbpSubscribable { get; set; }
public string Name { get; set; }
public List<int> SyntaxIds { get; set; }
}

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
@ -20,7 +19,6 @@ public SoftwareService(FilterListsDbContext dbContext, IConfigurationProvider ma
public async Task<IEnumerable<SoftwareDto>> GetAll() =>
await DbContext.Software
.OrderBy(s => s.Name)
.ProjectTo<SoftwareDto>(MapConfig)
.ToListAsync();

View file

@ -1,4 +1,5 @@
using AutoMapper;
using System.Linq;
using AutoMapper;
using FilterLists.Services.Tag.Models;
using JetBrains.Annotations;
@ -11,6 +12,10 @@ public TagDtoMappingProfile() =>
CreateMap<Data.Entities.Tag, TagDto>()
.ForMember(dest => dest.Id,
opt => opt.MapFrom(src =>
(int)src.Id));
(int)src.Id))
.ForMember(dest => dest.FilterListIds,
opt => opt.MapFrom(src =>
src.FilterListTags
.Select(ft => (int)ft.FilterListId)));
}
}

View file

@ -1,4 +1,5 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace FilterLists.Services.Tag.Models
{
@ -6,7 +7,8 @@ namespace FilterLists.Services.Tag.Models
public class TagDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<int> FilterListIds { get; set; }
public string Name { get; set; }
}
}

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
@ -20,7 +19,6 @@ public TagService(FilterListsDbContext dbContext, IConfigurationProvider mapConf
public async Task<IEnumerable<TagDto>> GetAll() =>
await DbContext.Tags
.OrderBy(s => s.Name)
.ProjectTo<TagDto>(MapConfig)
.ToListAsync();

View file

@ -30,6 +30,7 @@ export const ListsTable = (props: IProps) =>
UpdatedDate(props.columnVisibility),
DetailsButton
]}
defaultSorted={[{ id: "name" }]}
SubComponent={(r: any) => <DetailsExpander listId={r.original.id}/>}
className="-striped -highlight"/>
: <div className="loader">Loading...</div>;