mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 18:54:22 -04:00
Adding the /items route
This commit is contained in:
parent
5b0b2fbb7b
commit
24355bac84
@ -46,9 +46,9 @@ namespace Kyoo
|
|||||||
services.AddDbContext<DatabaseContext>(options =>
|
services.AddDbContext<DatabaseContext>(options =>
|
||||||
{
|
{
|
||||||
options.UseLazyLoadingProxies()
|
options.UseLazyLoadingProxies()
|
||||||
.UseNpgsql(_configuration.GetConnectionString("Database"))
|
.UseNpgsql(_configuration.GetConnectionString("Database"));
|
||||||
.EnableSensitiveDataLogging()
|
// .EnableSensitiveDataLogging()
|
||||||
.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
|
// .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole()));
|
||||||
}, ServiceLifetime.Transient);
|
}, ServiceLifetime.Transient);
|
||||||
|
|
||||||
services.AddDbContext<IdentityDatabase>(options =>
|
services.AddDbContext<IdentityDatabase>(options =>
|
||||||
|
63
Kyoo/Views/API/LibraryItemsApi.cs
Normal file
63
Kyoo/Views/API/LibraryItemsApi.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.CommonApi;
|
||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace Kyoo.Api
|
||||||
|
{
|
||||||
|
[Route("api/item")]
|
||||||
|
[Route("api/items")]
|
||||||
|
[ApiController]
|
||||||
|
public class LibraryItemsApi : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ILibraryItemRepository _libraryItems;
|
||||||
|
private readonly string _baseURL;
|
||||||
|
|
||||||
|
|
||||||
|
public LibraryItemsApi(ILibraryItemRepository libraryItems, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_libraryItems = libraryItems;
|
||||||
|
_baseURL = configuration.GetValue<string>("public_url").TrimEnd('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Page<LibraryItem>>> GetAll([FromQuery] string sortBy,
|
||||||
|
[FromQuery] int afterID,
|
||||||
|
[FromQuery] Dictionary<string, string> where,
|
||||||
|
[FromQuery] int limit = 50)
|
||||||
|
{
|
||||||
|
where.Remove("sortBy");
|
||||||
|
where.Remove("limit");
|
||||||
|
where.Remove("afterID");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ICollection<LibraryItem> ressources = await _libraryItems.GetAll(
|
||||||
|
ApiHelper.ParseWhere<LibraryItem>(where),
|
||||||
|
new Sort<LibraryItem>(sortBy),
|
||||||
|
new Pagination(limit, afterID));
|
||||||
|
|
||||||
|
return new Page<LibraryItem>(ressources,
|
||||||
|
_baseURL + Request.Path,
|
||||||
|
Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString(), StringComparer.InvariantCultureIgnoreCase),
|
||||||
|
limit);
|
||||||
|
}
|
||||||
|
catch (ItemNotFound)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new {Error = ex.Message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user