From 31d65ec2b74ef068f82dbbebde04c4ef0ac58a20 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Wed, 22 Aug 2018 10:54:57 -0500 Subject: [PATCH] add Tag seed API endpoints ref #65 --- data/Tag.json | 4 +-- .../V1/Controllers/ListsTagsController.cs | 27 +++++++++++++++++++ .../V1/Controllers/TagsController.cs | 24 +++++++++++++++++ src/FilterLists.Data/Entities/Tag.cs | 2 +- .../Models/Junctions/FilterListTagSeedDto.cs | 11 ++++++++ .../Seed/Models/TagSeedDto.cs | 12 +++++++++ 6 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/FilterLists.Api/V1/Controllers/ListsTagsController.cs create mode 100644 src/FilterLists.Api/V1/Controllers/TagsController.cs create mode 100644 src/FilterLists.Services/Seed/Models/Junctions/FilterListTagSeedDto.cs create mode 100644 src/FilterLists.Services/Seed/Models/TagSeedDto.cs diff --git a/data/Tag.json b/data/Tag.json index 775762e9b..ca2ef70d1 100644 --- a/data/Tag.json +++ b/data/Tag.json @@ -1,7 +1,7 @@ [ { "id": 1, - "name": "crypto", - "description": "Blocks cryptomining and/or cryptojacking" + "description": "Blocks cryptomining and/or cryptojacking", + "name": "crypto" } ] \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs b/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs new file mode 100644 index 000000000..4cccf5fea --- /dev/null +++ b/src/FilterLists.Api/V1/Controllers/ListsTagsController.cs @@ -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 Seed() => + Json(await MemoryCache.GetOrCreate("ListsTagsController_Seed", entry => + { + entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + return SeedService.GetAllAsync( + typeof(FilterListTag).GetProperty("FilterListId"), + typeof(FilterListTag).GetProperty("TagId")); + })); + } +} \ No newline at end of file diff --git a/src/FilterLists.Api/V1/Controllers/TagsController.cs b/src/FilterLists.Api/V1/Controllers/TagsController.cs new file mode 100644 index 000000000..ca19b50d0 --- /dev/null +++ b/src/FilterLists.Api/V1/Controllers/TagsController.cs @@ -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 Seed() => + Json(await MemoryCache.GetOrCreate("TagsController_Seed", entry => + { + entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow; + return SeedService.GetAllAsync(); + })); + } +} \ No newline at end of file diff --git a/src/FilterLists.Data/Entities/Tag.cs b/src/FilterLists.Data/Entities/Tag.cs index 684a46f60..4d478e617 100644 --- a/src/FilterLists.Data/Entities/Tag.cs +++ b/src/FilterLists.Data/Entities/Tag.cs @@ -5,8 +5,8 @@ namespace FilterLists.Data.Entities { public class Tag : BaseEntity { - public string Name { get; set; } public string Description { get; set; } public ICollection FilterListTags { get; set; } + public string Name { get; set; } } } \ No newline at end of file diff --git a/src/FilterLists.Services/Seed/Models/Junctions/FilterListTagSeedDto.cs b/src/FilterLists.Services/Seed/Models/Junctions/FilterListTagSeedDto.cs new file mode 100644 index 000000000..d6d9673db --- /dev/null +++ b/src/FilterLists.Services/Seed/Models/Junctions/FilterListTagSeedDto.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/Seed/Models/TagSeedDto.cs b/src/FilterLists.Services/Seed/Models/TagSeedDto.cs new file mode 100644 index 000000000..ef74b34b0 --- /dev/null +++ b/src/FilterLists.Services/Seed/Models/TagSeedDto.cs @@ -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; } + } +} \ No newline at end of file