mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add list details API endpoint
This commit is contained in:
parent
37ff9a1cc8
commit
948cbe19f0
4 changed files with 28 additions and 1 deletions
|
|
@ -40,7 +40,9 @@ public void Configure(IApplicationBuilder app)
|
|||
app.UseStaticFiles();
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute("default", "v{version:apiVersion}/{controller=Home}/{action=Index}/{id?}");
|
||||
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?}");
|
||||
});
|
||||
MigrateAndSeedDatabase(app);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ public async Task<IActionResult> Index()
|
|||
return Json(await filterListService.GetAllSummariesAsync());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetById(int id)
|
||||
{
|
||||
return Json(await filterListService.GetDetailsAsync(id));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Seed()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
namespace FilterLists.Services.FilterListService
|
||||
{
|
||||
public class FilterListDetailsDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DescriptionSourceUrl { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ViewUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -25,5 +25,13 @@ public async Task<IEnumerable<FilterListSummaryDto>> GetAllSummariesAsync()
|
|||
.ProjectTo<FilterListSummaryDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<FilterListDetailsDto> GetDetailsAsync(int id)
|
||||
{
|
||||
return await filterListsDbContext.Set<FilterList>()
|
||||
.AsNoTracking()
|
||||
.ProjectTo<FilterListDetailsDto>()
|
||||
.FirstAsync(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue