mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
ec4e72b83c
commit
b6c199da03
4 changed files with 49 additions and 3 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Services.Seed;
|
||||
using FilterLists.Services.Seed.Models;
|
||||
using FilterLists.Services.Software;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
|
|
@ -9,9 +10,18 @@ namespace FilterLists.Api.V1.Controllers
|
|||
{
|
||||
public class SoftwareController : BaseController
|
||||
{
|
||||
public SoftwareController(IMemoryCache memoryCache, SeedService seedService) : base(memoryCache, seedService)
|
||||
{
|
||||
}
|
||||
private readonly SoftwareService softwareService;
|
||||
|
||||
public SoftwareController(IMemoryCache memoryCache, SeedService seedService, SoftwareService softwareService) :
|
||||
base(memoryCache, seedService) => this.softwareService = softwareService;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index() =>
|
||||
Json(await MemoryCache.GetOrCreate("SoftwareController_Index", entry =>
|
||||
{
|
||||
entry.AbsoluteExpirationRelativeToNow = FourHoursFromNow;
|
||||
return softwareService.GetAll();
|
||||
}));
|
||||
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() =>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
using FilterLists.Services.FilterList;
|
||||
using FilterLists.Services.Seed;
|
||||
using FilterLists.Services.Snapshot;
|
||||
using FilterLists.Services.Software;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -21,6 +22,7 @@ public static void AddFilterListsApiServices(this IServiceCollection services, I
|
|||
m => m.MigrationsAssembly("FilterLists.Api")));
|
||||
services.TryAddScoped<FilterListService>();
|
||||
services.TryAddScoped<RuleService>();
|
||||
services.TryAddScoped<SoftwareService>();
|
||||
services.TryAddScoped<SeedService>();
|
||||
services.AddAutoMapper();
|
||||
}
|
||||
|
|
|
|||
11
src/FilterLists.Services/Software/Models/SoftwareDto.cs
Normal file
11
src/FilterLists.Services/Software/Models/SoftwareDto.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.Software.Models
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SoftwareDto
|
||||
{
|
||||
public uint Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
23
src/FilterLists.Services/Software/SoftwareService.cs
Normal file
23
src/FilterLists.Services/Software/SoftwareService.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using FilterLists.Data;
|
||||
using FilterLists.Services.Software.Models;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Services.Software
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SoftwareService : Service
|
||||
{
|
||||
public SoftwareService(FilterListsDbContext dbContext, IConfigurationProvider mapConfig)
|
||||
: base(dbContext, mapConfig)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SoftwareDto>> GetAll() =>
|
||||
await DbContext.Software.ProjectTo<SoftwareDto>(MapConfig).ToListAsync();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue