mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Kyoo.Abstractions.Controllers;
|
|
using Kyoo.Abstractions.Models;
|
|
using Kyoo.Abstractions.Models.Permissions;
|
|
using Kyoo.Core.Models.Options;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Kyoo.Core.Api
|
|
{
|
|
[Route("api/studio")]
|
|
[Route("api/studios")]
|
|
[ApiController]
|
|
[PartialPermission(nameof(ShowApi))]
|
|
public class StudioApi : CrudApi<Studio>
|
|
{
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
public StudioApi(ILibraryManager libraryManager, IOptions<BasicOptions> options)
|
|
: base(libraryManager.StudioRepository, options.Value.PublicUrl)
|
|
{
|
|
_libraryManager = libraryManager;
|
|
}
|
|
|
|
[HttpGet("{id:int}/show")]
|
|
[HttpGet("{id:int}/shows")]
|
|
[PartialPermission(Kind.Read)]
|
|
public async Task<ActionResult<Page<Show>>> GetShows(int id,
|
|
[FromQuery] string sortBy,
|
|
[FromQuery] int afterID,
|
|
[FromQuery] Dictionary<string, string> where,
|
|
[FromQuery] int limit = 20)
|
|
{
|
|
try
|
|
{
|
|
ICollection<Show> resources = await _libraryManager.GetAll(
|
|
ApiHelper.ParseWhere<Show>(where, x => x.StudioID == id),
|
|
new Sort<Show>(sortBy),
|
|
new Pagination(limit, afterID));
|
|
|
|
if (!resources.Any() && await _libraryManager.GetOrDefault<Studio>(id) == null)
|
|
return NotFound();
|
|
return Page(resources, limit);
|
|
}
|
|
catch (ArgumentException ex)
|
|
{
|
|
return BadRequest(new { Error = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpGet("{slug}/show")]
|
|
[HttpGet("{slug}/shows")]
|
|
[PartialPermission(Kind.Read)]
|
|
public async Task<ActionResult<Page<Show>>> GetShows(string slug,
|
|
[FromQuery] string sortBy,
|
|
[FromQuery] int afterID,
|
|
[FromQuery] Dictionary<string, string> where,
|
|
[FromQuery] int limit = 20)
|
|
{
|
|
try
|
|
{
|
|
ICollection<Show> resources = await _libraryManager.GetAll(
|
|
ApiHelper.ParseWhere<Show>(where, x => x.Studio.Slug == slug),
|
|
new Sort<Show>(sortBy),
|
|
new Pagination(limit, afterID));
|
|
|
|
if (!resources.Any() && await _libraryManager.GetOrDefault<Studio>(slug) == null)
|
|
return NotFound();
|
|
return Page(resources, limit);
|
|
}
|
|
catch (ArgumentException ex)
|
|
{
|
|
return BadRequest(new { Error = ex.Message });
|
|
}
|
|
}
|
|
}
|
|
}
|