diff --git a/FilterLists.postman_collection.json b/FilterLists.postman_collection.json index ee006a5dd..5223a4d1f 100644 --- a/FilterLists.postman_collection.json +++ b/FilterLists.postman_collection.json @@ -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": { diff --git a/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs b/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs index a1233576c..56d5185b9 100644 --- a/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs +++ b/src/FilterLists.Api/V1/Controllers/SyntaxesController.cs @@ -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 GetAll() => + await Get(() => syntaxService.GetAll()); + + [HttpGet] + [Route("{id}")] + public async Task GetById(int id) => + await Get(() => syntaxService.GetById(id), id); [HttpGet("seed")] public async Task Seed() => diff --git a/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs b/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs index dfd8565b2..45a74f08c 100644 --- a/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs +++ b/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs @@ -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(); services.TryAddScoped(); services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.AddAutoMapper(); diff --git a/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs b/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs index fe4f7be25..6d58f4a6d 100644 --- a/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs +++ b/src/FilterLists.Services/FilterList/MappingProfiles/ListSyntaxDtoMappingProfile.cs @@ -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() + CreateMap() .ForMember(dest => dest.SupportedSoftware, opt => opt.MapFrom(src => src.SoftwareSyntaxes diff --git a/src/FilterLists.Services/Syntax/MappingProfiles/SyntaxDtoMappingProfile.cs b/src/FilterLists.Services/Syntax/MappingProfiles/SyntaxDtoMappingProfile.cs new file mode 100644 index 000000000..82eae0e5e --- /dev/null +++ b/src/FilterLists.Services/Syntax/MappingProfiles/SyntaxDtoMappingProfile.cs @@ -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() + .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))); + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/Syntax/Models/SyntaxDto.cs b/src/FilterLists.Services/Syntax/Models/SyntaxDto.cs new file mode 100644 index 000000000..9b72d2001 --- /dev/null +++ b/src/FilterLists.Services/Syntax/Models/SyntaxDto.cs @@ -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 FilterListIds { get; set; } + public string Name { get; set; } + public List SoftwareIds { get; set; } + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/Syntax/SyntaxService.cs b/src/FilterLists.Services/Syntax/SyntaxService.cs new file mode 100644 index 000000000..7e51a1a4b --- /dev/null +++ b/src/FilterLists.Services/Syntax/SyntaxService.cs @@ -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> GetAll() => + await DbContext.Syntaxes + .ProjectTo(MapConfig) + .ToListAsync(); + + public async Task GetById(int id) => + await DbContext.Syntaxes + .ProjectTo(MapConfig) + .FirstOrDefaultAsync(s => s.Id == id); + } +} \ No newline at end of file