add Tag seed API endpoints

ref #65
This commit is contained in:
Collin M. Barrett 2018-08-22 10:54:57 -05:00
parent 7bcd1ba389
commit 31d65ec2b7
6 changed files with 77 additions and 3 deletions

View file

@ -1,7 +1,7 @@
[
{
"id": 1,
"name": "crypto",
"description": "Blocks cryptomining and/or cryptojacking"
"description": "Blocks cryptomining and/or cryptojacking",
"name": "crypto"
}
]

View file

@ -0,0 +1,27 @@
using System.Threading.Tasks;
using FilterLists.Data.Entities.Junctions;
using FilterLists.Services.Seed;
using FilterLists.Services.Seed.Models.Junctions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
namespace FilterLists.Api.V1.Controllers
{
public class ListsTagsController : BaseController
{
public ListsTagsController(IMemoryCache memoryCache, SeedService seedService)
: base(memoryCache, seedService)
{
}
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("ListsTagsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
return SeedService.GetAllAsync<FilterListTag, FilterListTagSeedDto>(
typeof(FilterListTag).GetProperty("FilterListId"),
typeof(FilterListTag).GetProperty("TagId"));
}));
}
}

View file

@ -0,0 +1,24 @@
using System.Threading.Tasks;
using FilterLists.Data.Entities;
using FilterLists.Services.Seed;
using FilterLists.Services.Seed.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
namespace FilterLists.Api.V1.Controllers
{
public class TagsController : BaseController
{
public TagsController(IMemoryCache memoryCache, SeedService seedService) : base(memoryCache, seedService)
{
}
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>
Json(await MemoryCache.GetOrCreate("TagsController_Seed", entry =>
{
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
return SeedService.GetAllAsync<Tag, TagSeedDto>();
}));
}
}

View file

@ -5,8 +5,8 @@ namespace FilterLists.Data.Entities
{
public class Tag : BaseEntity
{
public string Name { get; set; }
public string Description { get; set; }
public ICollection<FilterListTag> FilterListTags { get; set; }
public string Name { get; set; }
}
}

View file

@ -0,0 +1,11 @@
using JetBrains.Annotations;
namespace FilterLists.Services.Seed.Models.Junctions
{
[UsedImplicitly]
public class FilterListTagSeedDto
{
public uint FilterListId { get; set; }
public uint TagId { get; set; }
}
}

View file

@ -0,0 +1,12 @@
using JetBrains.Annotations;
namespace FilterLists.Services.Seed.Models
{
[UsedImplicitly]
public class TagSeedDto
{
public uint Id { get; set; }
public string Description { get; set; }
public string Name { get; set; }
}
}