return 404s from API as warranted

This commit is contained in:
Collin M. Barrett 2018-09-25 13:19:32 -05:00
parent 949768be50
commit d6c39f0c12
16 changed files with 45 additions and 42 deletions

View file

@ -26,5 +26,8 @@ protected BaseController(IMemoryCache memoryCache, SeedService seedService)
MemoryCache = memoryCache;
SeedService = seedService;
}
protected IActionResult CoalesceNotFound(JsonResult result) =>
result.Value is null ? NotFound() : (IActionResult)result;
}
}

View file

@ -15,11 +15,11 @@ public DependentsController(IMemoryCache memoryCache, SeedService seedService) :
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("DependentsController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("DependentsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Dependent, DependentSeedDto>(typeof(Dependent).GetProperty("DependentFilterListId"),
typeof(Dependent).GetProperty("DependencyFilterListId"));
}));
})));
}
}

View file

@ -15,11 +15,11 @@ public ForksController(IMemoryCache memoryCache, SeedService seedService) : base
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ForksController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ForksController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Fork, ForkSeedDto>(typeof(Fork).GetProperty("UpstreamFilterListId"),
typeof(Fork).GetProperty("ForkFilterListId"));
}));
})));
}
}

View file

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

View file

@ -15,10 +15,10 @@ public LicensesController(IMemoryCache memoryCache, SeedService seedService) : b
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("LicensesController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("LicensesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<License, LicenseSeedDto>();
}));
})));
}
}

View file

@ -17,27 +17,27 @@ public ListsController(IMemoryCache memoryCache, SeedService seedService, Filter
[HttpGet]
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("ListsController_Index", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ListsController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return filterListService.GetAllAsync();
}));
})));
[HttpGet]
[Route("{id}")]
public async Task<IActionResult> GetById(int id) =>
Json(await MemoryCache.GetOrCreate("ListsController_GetById_" + id, entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ListsController_GetById_" + id, entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return filterListService.GetDetailsAsync((uint)id);
}));
})));
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ListsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<FilterList, FilterListSeedDto>();
}));
})));
}
}

View file

@ -16,12 +16,12 @@ public ListsLanguagesController(IMemoryCache memoryCache, SeedService seedServic
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsLanguagesController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ListsLanguagesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<FilterListLanguage, FilterListLanguageSeedDto>(
typeof(FilterListLanguage).GetProperty("FilterListId"),
typeof(FilterListLanguage).GetProperty("LanguageId"));
}));
})));
}
}

View file

@ -16,12 +16,12 @@ public ListsMaintainersController(IMemoryCache memoryCache, SeedService seedServ
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsMaintainersController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ListsMaintainersController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<FilterListMaintainer, FilterListMaintainerSeedDto>(
typeof(FilterListMaintainer).GetProperty("MaintainerId"),
typeof(FilterListMaintainer).GetProperty("FilterListId"));
}));
})));
}
}

View file

@ -16,12 +16,12 @@ public ListsTagsController(IMemoryCache memoryCache, SeedService seedService)
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsTagsController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("ListsTagsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<FilterListTag, FilterListTagSeedDto>(
typeof(FilterListTag).GetProperty("FilterListId"),
typeof(FilterListTag).GetProperty("TagId"));
}));
})));
}
}

View file

@ -15,10 +15,10 @@ public MaintainersController(IMemoryCache memoryCache, SeedService seedService)
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("MaintainersController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("MaintainersController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Maintainer, MaintainerSeedDto>();
}));
})));
}
}

View file

@ -15,11 +15,11 @@ public MergesController(IMemoryCache memoryCache, SeedService seedService) : bas
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("MergesController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("MergesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Merge, MergeSeedDto>(typeof(Merge).GetProperty("MergeFilterListId"),
typeof(Merge).GetProperty("UpstreamFilterListId"));
}));
})));
}
}

View file

@ -14,10 +14,10 @@ public RulesController(IMemoryCache memoryCache, RuleService ruleService) : base
[HttpGet]
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("RulesController_Index", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("RulesController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return ruleService.GetCountAll();
}));
})));
}
}

View file

@ -17,18 +17,18 @@ public SoftwareController(IMemoryCache memoryCache, SeedService seedService, Sof
[HttpGet]
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("SoftwareController_Index", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("SoftwareController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return softwareService.GetAll();
}));
})));
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("SoftwareController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("SoftwareController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Software, SoftwareSeedDto>();
}));
})));
}
}

View file

@ -16,11 +16,11 @@ public SoftwareSyntaxesController(IMemoryCache memoryCache, SeedService seedServ
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("SoftwareSyntaxesController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("SoftwareSyntaxesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<SoftwareSyntax, SoftwareSyntaxSeedDto>(
typeof(SoftwareSyntax).GetProperty("SyntaxId"), typeof(SoftwareSyntax).GetProperty("SoftwareId"));
}));
})));
}
}

View file

@ -15,10 +15,10 @@ public SyntaxesController(IMemoryCache memoryCache, SeedService seedService) : b
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("SyntaxesController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("SyntaxesController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Syntax, SyntaxSeedDto>();
}));
})));
}
}

View file

@ -17,18 +17,18 @@ public TagsController(IMemoryCache memoryCache, SeedService seedService, TagServ
[HttpGet]
public async Task<IActionResult> Index() =>
Json(await MemoryCache.GetOrCreate("TagsController_Index", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("TagsController_Index", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return tagService.GetAll();
}));
})));
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("TagsController_Seed", entry =>
CoalesceNotFound(Json(await MemoryCache.GetOrCreate("TagsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
return SeedService.GetAllAsync<Tag, TagSeedDto>();
}));
})));
}
}