mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
d8d66dc5cc
commit
fd66f42f1d
7 changed files with 117 additions and 5 deletions
|
|
@ -122,6 +122,45 @@
|
|||
{
|
||||
"name": "licenses",
|
||||
"item": [
|
||||
{
|
||||
"name": "licenses",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/{{version}}/licenses",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"{{version}}",
|
||||
"licenses"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "licenses/{id}",
|
||||
"request": {
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {},
|
||||
"url": {
|
||||
"raw": "{{baseUrl}}/{{version}}/licenses/1",
|
||||
"host": [
|
||||
"{{baseUrl}}"
|
||||
],
|
||||
"path": [
|
||||
"{{version}}",
|
||||
"licenses",
|
||||
"1"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "licenses/seed",
|
||||
"request": {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using FilterLists.Api.V1.Interfaces;
|
||||
using FilterLists.Data.Entities;
|
||||
using FilterLists.Services.License;
|
||||
using FilterLists.Services.Seed;
|
||||
using FilterLists.Services.Seed.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -8,11 +9,21 @@
|
|||
|
||||
namespace FilterLists.Api.V1.Controllers
|
||||
{
|
||||
public class LicensesController : BaseController, ISeed
|
||||
public class LicensesController : BaseController, IGet, ISeed
|
||||
{
|
||||
public LicensesController(IMemoryCache memoryCache, SeedService seedService) : base(memoryCache, seedService)
|
||||
{
|
||||
}
|
||||
private readonly LicenseService licenseService;
|
||||
|
||||
public LicensesController(IMemoryCache memoryCache, SeedService seedService, LicenseService licenseService) :
|
||||
base(memoryCache, seedService) => this.licenseService = licenseService;
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll() =>
|
||||
await Get(() => licenseService.GetAllAsync());
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<IActionResult> GetById(int id) =>
|
||||
await Get(() => licenseService.GetByIdAsync(id), id);
|
||||
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() =>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using FilterLists.Data;
|
||||
using FilterLists.Services.FilterList;
|
||||
using FilterLists.Services.Language;
|
||||
using FilterLists.Services.License;
|
||||
using FilterLists.Services.Seed;
|
||||
using FilterLists.Services.Snapshot;
|
||||
using FilterLists.Services.Software;
|
||||
|
|
@ -24,6 +25,7 @@ public static void AddFilterListsApiServices(this IServiceCollection services, I
|
|||
m => m.MigrationsAssembly("FilterLists.Api")));
|
||||
services.TryAddScoped<FilterListService>();
|
||||
services.TryAddScoped<LanguageService>();
|
||||
services.TryAddScoped<LicenseService>();
|
||||
services.TryAddScoped<SeedService>();
|
||||
services.TryAddScoped<SoftwareService>();
|
||||
services.TryAddScoped<TagService>();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using FilterLists.Services.Language.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.FilterList.MappingProfiles
|
||||
namespace FilterLists.Services.Language.MappingProfiles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class LanguageDtoMappingProfile : Profile
|
||||
|
|
|
|||
32
src/FilterLists.Services/License/LicenseService.cs
Normal file
32
src/FilterLists.Services/License/LicenseService.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using FilterLists.Data;
|
||||
using FilterLists.Services.License.Models;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FilterLists.Services.License
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class LicenseService : Service
|
||||
{
|
||||
public LicenseService(FilterListsDbContext dbContext, IConfigurationProvider mapConfig)
|
||||
: base(dbContext, mapConfig)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LicenseDto>> GetAllAsync() =>
|
||||
await DbContext.Licenses
|
||||
.OrderBy(s => s.Name)
|
||||
.ProjectTo<LicenseDto>(MapConfig)
|
||||
.ToListAsync();
|
||||
|
||||
public async Task<LicenseDto> GetByIdAsync(int id) =>
|
||||
await DbContext.Licenses
|
||||
.ProjectTo<LicenseDto>(MapConfig)
|
||||
.FirstOrDefaultAsync(l => l.Id == id);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using AutoMapper;
|
||||
using FilterLists.Services.License.Models;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.License.MappingProfiles
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class LicenseDtoMappingProfile : Profile
|
||||
{
|
||||
public LicenseDtoMappingProfile() =>
|
||||
CreateMap<Data.Entities.License, LicenseDto>()
|
||||
.ForMember(dest => dest.Id,
|
||||
opt => opt.MapFrom(src =>
|
||||
(int)src.Id));
|
||||
}
|
||||
}
|
||||
12
src/FilterLists.Services/License/Models/LicenseDto.cs
Normal file
12
src/FilterLists.Services/License/Models/LicenseDto.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Services.License.Models
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class LicenseDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string DescriptionUrl { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue