diff --git a/FilterLists.postman_collection.json b/FilterLists.postman_collection.json index f28d0f1c6..61e474ef3 100644 --- a/FilterLists.postman_collection.json +++ b/FilterLists.postman_collection.json @@ -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": { diff --git a/src/FilterLists.Api/V1/Controllers/LicensesController.cs b/src/FilterLists.Api/V1/Controllers/LicensesController.cs index c8f2b496c..eeafc8a79 100644 --- a/src/FilterLists.Api/V1/Controllers/LicensesController.cs +++ b/src/FilterLists.Api/V1/Controllers/LicensesController.cs @@ -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 GetAll() => + await Get(() => licenseService.GetAllAsync()); + + [HttpGet] + [Route("{id}")] + public async Task GetById(int id) => + await Get(() => licenseService.GetByIdAsync(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 61a4aac53..e0ae37bcd 100644 --- a/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs +++ b/src/FilterLists.Services/DependencyInjection/Extensions/ConfigureServicesCollection.cs @@ -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(); services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); diff --git a/src/FilterLists.Services/Language/MappingProfiles/LanguageDtoMappingProfile.cs b/src/FilterLists.Services/Language/MappingProfiles/LanguageDtoMappingProfile.cs index 1d97496eb..821fcec0a 100644 --- a/src/FilterLists.Services/Language/MappingProfiles/LanguageDtoMappingProfile.cs +++ b/src/FilterLists.Services/Language/MappingProfiles/LanguageDtoMappingProfile.cs @@ -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 diff --git a/src/FilterLists.Services/License/LicenseService.cs b/src/FilterLists.Services/License/LicenseService.cs new file mode 100644 index 000000000..a82cd5424 --- /dev/null +++ b/src/FilterLists.Services/License/LicenseService.cs @@ -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> GetAllAsync() => + await DbContext.Licenses + .OrderBy(s => s.Name) + .ProjectTo(MapConfig) + .ToListAsync(); + + public async Task GetByIdAsync(int id) => + await DbContext.Licenses + .ProjectTo(MapConfig) + .FirstOrDefaultAsync(l => l.Id == id); + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/License/MappingProfiles/LicenseDtoMappingProfile.cs b/src/FilterLists.Services/License/MappingProfiles/LicenseDtoMappingProfile.cs new file mode 100644 index 000000000..d5a508c6a --- /dev/null +++ b/src/FilterLists.Services/License/MappingProfiles/LicenseDtoMappingProfile.cs @@ -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() + .ForMember(dest => dest.Id, + opt => opt.MapFrom(src => + (int)src.Id)); + } +} \ No newline at end of file diff --git a/src/FilterLists.Services/License/Models/LicenseDto.cs b/src/FilterLists.Services/License/Models/LicenseDto.cs new file mode 100644 index 000000000..43ccd6dea --- /dev/null +++ b/src/FilterLists.Services/License/Models/LicenseDto.cs @@ -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; } + } +} \ No newline at end of file