mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
eda625648b
commit
2b89c2b6fb
6 changed files with 73 additions and 7 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Services.Seed;
|
||||
using FilterLists.Services.Seed.Models;
|
||||
using FilterLists.Services.Tag;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
|
|
@ -9,9 +10,18 @@ namespace FilterLists.Api.V1.Controllers
|
|||
{
|
||||
public class TagsController : BaseController
|
||||
{
|
||||
public TagsController(IMemoryCache memoryCache, SeedService seedService) : base(memoryCache, seedService)
|
||||
{
|
||||
}
|
||||
private readonly TagService tagService;
|
||||
|
||||
public TagsController(IMemoryCache memoryCache, SeedService seedService, TagService tagService) :
|
||||
base(memoryCache, seedService) => this.tagService = tagService;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index() =>
|
||||
Json(await MemoryCache.GetOrCreate("TagsController_Index", entry =>
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = MemoryCacheExpirationDefault;
|
||||
return tagService.GetAll();
|
||||
}));
|
||||
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() =>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
using FilterLists.Services.Seed;
|
||||
using FilterLists.Services.Snapshot;
|
||||
using FilterLists.Services.Software;
|
||||
using FilterLists.Services.Tag;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -22,10 +23,11 @@ public static void AddFilterListsApiServices(this IServiceCollection services, I
|
|||
o.UseMySql(config.GetConnectionString("FilterListsConnection"),
|
||||
m => m.MigrationsAssembly("FilterLists.Api")));
|
||||
services.TryAddScoped<FilterListService>();
|
||||
services.TryAddScoped<RuleService>();
|
||||
services.TryAddScoped<SoftwareService>();
|
||||
services.TryAddScoped<LanguageService>();
|
||||
services.TryAddScoped<SeedService>();
|
||||
services.TryAddScoped<SoftwareService>();
|
||||
services.TryAddScoped<TagService>();
|
||||
services.TryAddScoped<RuleService>();
|
||||
services.AddAutoMapper();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using AutoMapper;
|
||||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Services.FilterList.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
|
|
@ -9,7 +8,7 @@ namespace FilterLists.Services.FilterList.MappingProfiles
|
|||
public class ListTagDtoMappingProfile : Profile
|
||||
{
|
||||
public ListTagDtoMappingProfile() =>
|
||||
CreateMap<Tag, ListTagDto>()
|
||||
CreateMap<Data.Entities.Tag, ListTagDto>()
|
||||
.ForMember(dest => dest.ColorHex,
|
||||
opt => opt.MapFrom(src =>
|
||||
TagColors.Colors[(int)src.Id]));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
using AutoMapper;
|
||||
using FilterLists.Services.Tag.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.Tag.MappingProfiles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class TagDtoMappingProfile : Profile
|
||||
{
|
||||
public TagDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.Tag, TagDto>()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id));
|
||||
}
|
||||
}
|
||||
12
src/FilterLists.Services/Tag/Models/TagDto.cs
Normal file
12
src/FilterLists.Services/Tag/Models/TagDto.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.Tag.Models
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class TagDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
27
src/FilterLists.Services/Tag/TagService.cs
Normal file
27
src/FilterLists.Services/Tag/TagService.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using FilterLists.Data;
|
||||
using FilterLists.Services.Tag.Models;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Services.Tag
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class TagService : Service
|
||||
{
|
||||
public TagService(FilterListsDbContext dbContext, IConfigurationProvider mapConfig)
|
||||
: base(dbContext, mapConfig)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TagDto>> GetAll() =>
|
||||
await DbContext.Tags
|
||||
.OrderBy(s => s.Name)
|
||||
.ProjectTo<TagDto>(MapConfig)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue