add API licenses IGet endpoints

ref #505
This commit is contained in:
Collin M. Barrett 2018-09-26 11:14:26 -05:00
parent d8d66dc5cc
commit fd66f42f1d
7 changed files with 117 additions and 5 deletions

View file

@ -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": {

View file

@ -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() =>

View file

@ -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>();

View file

@ -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

View 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);
}
}

View file

@ -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));
}
}

View 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; }
}
}