mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
extract middle level Entity controller for generic Seed method
This commit is contained in:
parent
a94191152b
commit
47afbbdaec
3 changed files with 33 additions and 20 deletions
|
|
@ -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>());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/FilterLists.Api/V1/Controllers/EntityController.cs
Normal file
30
src/FilterLists.Api/V1/Controllers/EntityController.cs
Normal 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>());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace FilterLists.Api.V1.Controllers
|
||||
{
|
||||
public class ListsController : BaseController
|
||||
public class ListsController : EntityController
|
||||
{
|
||||
private readonly FilterListService filterListService;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue