add API syntaxes IGet endpoints

ref #505
This commit is contained in:
Collin M. Barrett 2018-09-26 13:54:36 -05:00
parent dcc68c59e8
commit 9e4bc01ac5
7 changed files with 128 additions and 8 deletions

View file

@ -351,14 +351,14 @@
"header": [],
"body": {},
"url": {
"raw": "{{baseUrl}}/{{version}}/maintainers/1",
"raw": "{{baseUrl}}/{{version}}/maintainers/2",
"host": [
"{{baseUrl}}"
],
"path": [
"{{version}}",
"maintainers",
"1"
"2"
]
}
},
@ -527,6 +527,45 @@
{
"name": "syntaxes",
"item": [
{
"name": "syntaxes",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": "{{baseUrl}}/{{version}}/syntaxes",
"host": [
"{{baseUrl}}"
],
"path": [
"{{version}}",
"syntaxes"
]
}
},
"response": []
},
{
"name": "syntaxes/{id}",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": "{{baseUrl}}/{{version}}/syntaxes/1",
"host": [
"{{baseUrl}}"
],
"path": [
"{{version}}",
"syntaxes",
"1"
]
}
},
"response": []
},
{
"name": "syntaxes/seed",
"request": {

View file

@ -3,16 +3,27 @@
using FilterLists.Data.Entities;
using FilterLists.Services.Seed;
using FilterLists.Services.Seed.Models;
using FilterLists.Services.Syntax;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
namespace FilterLists.Api.V1.Controllers
{
public class SyntaxesController : BaseController, ISeed
public class SyntaxesController : BaseController, IGet, ISeed
{
public SyntaxesController(IMemoryCache memoryCache, SeedService seedService) : base(memoryCache, seedService)
{
}
private readonly SyntaxService syntaxService;
public SyntaxesController(IMemoryCache memoryCache, SeedService seedService, SyntaxService syntaxService) :
base(memoryCache, seedService) => this.syntaxService = syntaxService;
[HttpGet]
public async Task<IActionResult> GetAll() =>
await Get(() => syntaxService.GetAll());
[HttpGet]
[Route("{id}")]
public async Task<IActionResult> GetById(int id) =>
await Get(() => syntaxService.GetById(id), id);
[HttpGet("seed")]
public async Task<IActionResult> Seed() =>

View file

@ -7,6 +7,7 @@
using FilterLists.Services.Seed;
using FilterLists.Services.Snapshot;
using FilterLists.Services.Software;
using FilterLists.Services.Syntax;
using FilterLists.Services.Tag;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
@ -30,6 +31,7 @@ public static void AddFilterListsApiServices(this IServiceCollection services, I
services.TryAddScoped<MaintainerService>();
services.TryAddScoped<SeedService>();
services.TryAddScoped<SoftwareService>();
services.TryAddScoped<SyntaxService>();
services.TryAddScoped<TagService>();
services.TryAddScoped<RuleService>();
services.AddAutoMapper();

View file

@ -1,6 +1,5 @@
using System.Linq;
using AutoMapper;
using FilterLists.Data.Entities;
using FilterLists.Services.FilterList.Models;
using JetBrains.Annotations;
@ -10,7 +9,7 @@ namespace FilterLists.Services.FilterList.MappingProfiles
public class ListSyntaxDtoMappingProfile : Profile
{
public ListSyntaxDtoMappingProfile() =>
CreateMap<Syntax, ListSyntaxDto>()
CreateMap<Data.Entities.Syntax, ListSyntaxDto>()
.ForMember(dest => dest.SupportedSoftware,
opt => opt.MapFrom(src =>
src.SoftwareSyntaxes

View file

@ -0,0 +1,25 @@
using System.Linq;
using AutoMapper;
using FilterLists.Services.Syntax.Models;
using JetBrains.Annotations;
namespace FilterLists.Services.Syntax.MappingProfiles
{
[UsedImplicitly]
public class SyntaxDtoMappingProfile : Profile
{
public SyntaxDtoMappingProfile() =>
CreateMap<Data.Entities.Syntax, SyntaxDto>()
.ForMember(dest => dest.Id,
opt => opt.MapFrom(src =>
(int)src.Id))
.ForMember(dest => dest.FilterListIds,
opt => opt.MapFrom(src =>
src.FilterLists
.Select(l => (int)l.Id)))
.ForMember(dest => dest.SoftwareIds,
opt => opt.MapFrom(src =>
src.SoftwareSyntaxes
.Select(ss => (int)ss.SoftwareId)));
}
}

View file

@ -0,0 +1,14 @@
using System.Collections.Generic;
using JetBrains.Annotations;
namespace FilterLists.Services.Syntax.Models
{
[UsedImplicitly]
public class SyntaxDto
{
public int Id { get; set; }
public List<int> FilterListIds { get; set; }
public string Name { get; set; }
public List<int> SoftwareIds { get; set; }
}
}

View file

@ -0,0 +1,30 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using FilterLists.Data;
using FilterLists.Services.Syntax.Models;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
namespace FilterLists.Services.Syntax
{
[UsedImplicitly]
public class SyntaxService : Service
{
public SyntaxService(FilterListsDbContext dbContext, IConfigurationProvider mapConfig)
: base(dbContext, mapConfig)
{
}
public async Task<IEnumerable<SyntaxDto>> GetAll() =>
await DbContext.Syntaxes
.ProjectTo<SyntaxDto>(MapConfig)
.ToListAsync();
public async Task<SyntaxDto> GetById(int id) =>
await DbContext.Syntaxes
.ProjectTo<SyntaxDto>(MapConfig)
.FirstOrDefaultAsync(s => s.Id == id);
}
}