add langs id endpoint

ref #505
This commit is contained in:
Collin M. Barrett 2018-09-25 12:55:33 -05:00
parent 2e2724983b
commit 949768be50
2 changed files with 23 additions and 8 deletions

View file

@ -17,10 +17,19 @@ public LanguagesController(IMemoryCache memoryCache, SeedService seedService, La
[HttpGet]
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("LanguageService_Index", entry =>
Json(await MemoryCache.GetOrCreate("LanguagesController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return languageService.GetAllTargeted();
return languageService.GetAllTargetedAsync();
}));
[HttpGet]
[Route("{id}")]
public async Task<IActionResult> GetById(int id) =>
Json(await MemoryCache.GetOrCreate("LanguagesController_GetById_" + id, entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return languageService.GetTargetedByIdAsync(id);
}));
[HttpGet("seed")]

View file

@ -18,11 +18,17 @@ public LanguageService(FilterListsDbContext dbContext, IConfigurationProvider ma
{
}
public async Task<IEnumerable<LanguageDto>> GetAllTargeted() =>
await DbContext.Languages
.Where(l => l.FilterListLanguages.Any())
.OrderBy(s => s.Name)
.ProjectTo<LanguageDto>(MapConfig)
.ToListAsync();
private IQueryable<Data.Entities.Language> TargetedLanguages =>
DbContext.Languages.Where(l => l.FilterListLanguages.Any());
public async Task<IEnumerable<LanguageDto>> GetAllTargetedAsync() =>
await TargetedLanguages.OrderBy(s => s.Name)
.ProjectTo<LanguageDto>(MapConfig)
.ToListAsync();
public async Task<LanguageDto> GetTargetedByIdAsync(int id) =>
await TargetedLanguages.Where(l => l.Id == (uint)id)
.ProjectTo<LanguageDto>(MapConfig)
.FirstOrDefaultAsync();
}
}