extract middle level Entity controller for generic Seed method

This commit is contained in:
Collin M. Barrett 2018-01-24 07:10:37 -06:00
parent a94191152b
commit 47afbbdaec
3 changed files with 33 additions and 20 deletions

View file

@ -1,7 +1,4 @@
using System;
using FilterLists.Services.Models;
using FilterLists.Services.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
namespace FilterLists.Api.V1.Controllers
@ -12,24 +9,10 @@ namespace FilterLists.Api.V1.Controllers
public class BaseController : Controller
{
protected readonly IMemoryCache MemoryCache;
protected readonly SeedService SeedService;
public BaseController(IMemoryCache memoryCache, SeedService seedService)
protected BaseController(IMemoryCache memoryCache)
{
MemoryCache = memoryCache;
SeedService = seedService;
}
[HttpGet]
public IActionResult Seed()
{
var controllerName = ControllerContext.RouteData.Values["controller"].ToString();
return MemoryCache.GetOrCreate(CacheKeys.Entry, entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(86400);
//TODO: GetAll<T>() by seed type of request controller
return Json(SeedService.GetAll<FilterListSeedDto>());
});
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using FilterLists.Services.Models;
using FilterLists.Services.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
namespace FilterLists.Api.V1.Controllers
{
public class EntityController : BaseController
{
protected readonly SeedService SeedService;
protected EntityController(IMemoryCache memoryCache, SeedService seedService) : base(memoryCache)
{
SeedService = seedService;
}
[HttpGet]
public IActionResult Seed()
{
var controllerName = ControllerContext.RouteData.Values["controller"].ToString();
return MemoryCache.GetOrCreate(CacheKeys.Entry, entry =>
{
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(86400);
//TODO: GetAll<T>() by seed type of request controller
return Json(SeedService.GetAll<FilterListSeedDto>());
});
}
}
}

View file

@ -5,7 +5,7 @@
namespace FilterLists.Api.V1.Controllers
{
public class ListsController : BaseController
public class ListsController : EntityController
{
private readonly FilterListService filterListService;