mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
f7568a62a8
commit
fc1ec001a6
14 changed files with 33 additions and 21 deletions
|
|
@ -10,7 +10,8 @@ public static class ConfigureServicesCollection
|
|||
{
|
||||
public static void AddFilterListsApi(this IServiceCollection services)
|
||||
{
|
||||
services.AddMvc();
|
||||
services.AddRouting(options => options.LowercaseUrls = true);
|
||||
services.AddMvcCore();
|
||||
services.AddApiVersioning();
|
||||
services.AddSwaggerGenCustom();
|
||||
TelemetryDebugWriter.IsTracingDisabled = true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using FilterLists.Api.DependencyInjection.Extensions;
|
||||
using System.Linq;
|
||||
using FilterLists.Api.DependencyInjection.Extensions;
|
||||
using FilterLists.Data;
|
||||
using FilterLists.Data.Seed.Extensions;
|
||||
using FilterLists.Services.DependencyInjection.Extensions;
|
||||
|
|
@ -11,6 +12,7 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
|
||||
namespace FilterLists.Api
|
||||
{
|
||||
|
|
@ -52,24 +54,30 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
|||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
app.UseSwagger();
|
||||
app.UseSwagger(UseLowercaseControllerNameInSwaggerHack);
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
c.SwaggerEndpoint("/api/swagger/v1/swagger.json", "FilterLists API V1");
|
||||
c.SwaggerEndpoint("../swagger/v1/swagger.json", "FilterLists API V1");
|
||||
c.RoutePrefix = "docs";
|
||||
});
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseCookiePolicy();
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute("noAction", "v{version:apiVersion}/{controller}/{id:int}",
|
||||
new {controller = "{controller}", action = "GetById", id = "{id}"});
|
||||
routes.MapRoute("default", "v{version:apiVersion}/{controller}/{action=Index}/{id:int?}");
|
||||
});
|
||||
app.UseMvc();
|
||||
MigrateAndSeedDatabase(app);
|
||||
}
|
||||
|
||||
//https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/74#issuecomment-386762178
|
||||
private static void UseLowercaseControllerNameInSwaggerHack(SwaggerOptions c)
|
||||
{
|
||||
c.PreSerializeFilters.Add((document, request) =>
|
||||
{
|
||||
var paths = document.Paths.ToDictionary(item => item.Key.ToLowerInvariant(), item => item.Value);
|
||||
document.Paths.Clear();
|
||||
foreach (var pathItem in paths) document.Paths.Add(pathItem.Key, pathItem.Value);
|
||||
});
|
||||
}
|
||||
|
||||
private void MigrateAndSeedDatabase(IApplicationBuilder app)
|
||||
{
|
||||
var dataPath = Configuration.GetSection("DataDirectory").GetValue<string>("Path");
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
namespace FilterLists.Api.V1.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
//https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/370
|
||||
[Route("v{version:apiVersion}/[controller]")]
|
||||
public class BaseController : Controller
|
||||
{
|
||||
protected readonly SeedService SeedService;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public ForksController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Fork, ForkSeedDto>(
|
||||
typeof(Fork).GetProperty("UpstreamFilterListId"), typeof(Fork).GetProperty("ForkFilterListId")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public LanguagesController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Language, LanguageSeedDto>());
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public LicensesController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<License, LicenseSeedDto>());
|
||||
}
|
||||
}
|
||||
|
|
@ -20,9 +20,10 @@ public ListsController(SeedService seedService, FilterListService filterListServ
|
|||
public async Task<IActionResult> Index() => Json(await _filterListService.GetAllSummariesAsync());
|
||||
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public async Task<IActionResult> GetById(int id) => Json(await _filterListService.GetDetailsAsync(id));
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<FilterList, FilterListSeedDto>());
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public ListsLanguagesController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() =>
|
||||
Json(await SeedService.GetAllAsync<FilterListLanguage, FilterListLanguageSeedDto>(
|
||||
typeof(FilterListLanguage).GetProperty("FilterListId"),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public ListsMaintainersController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(
|
||||
await SeedService.GetAllAsync<FilterListMaintainer, FilterListMaintainerSeedDto>(
|
||||
typeof(FilterListMaintainer).GetProperty("MaintainerId"),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public MaintainersController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Maintainer, MaintainerSeedDto>());
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public MergesController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Merge, MergeSeedDto>(
|
||||
typeof(Merge).GetProperty("MergeFilterListId"), typeof(Merge).GetProperty("UpstreamFilterListId")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public SoftwareController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Software, SoftwareSeedDto>());
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ public SoftwareSyntaxesController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() =>
|
||||
Json(await SeedService.GetAllAsync<SoftwareSyntax, SoftwareSyntaxSeedDto>(
|
||||
typeof(SoftwareSyntax).GetProperty("SyntaxId"), typeof(SoftwareSyntax).GetProperty("SoftwareId")));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public SyntaxesController(SeedService seedService) : base(seedService)
|
|||
{
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpGet("seed")]
|
||||
public async Task<IActionResult> Seed() => Json(await SeedService.GetAllAsync<Syntax, SyntaxSeedDto>());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue