// Kyoo - A portable and vast media library solution. // Copyright (c) Kyoo. // // See AUTHORS.md and LICENSE file in the project root for full license information. // // Kyoo is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // Kyoo is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . 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.Attributes; using Kyoo.Abstractions.Models.Permissions; using Kyoo.Abstractions.Models.Utils; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using static Kyoo.Abstractions.Models.Utils.Constants; namespace Kyoo.Core.Api; /// /// Information about one or multiple . /// [Route("seasons")] [Route("season", Order = AlternativeRoute)] [ApiController] [PartialPermission(nameof(Season))] [ApiDefinition("Seasons", Group = ResourcesGroup)] public class SeasonApi(ILibraryManager libraryManager) : CrudThumbsApi(libraryManager.Seasons) { /// /// Refresh /// /// /// Ask a metadata refresh. /// /// The ID or slug of the . /// Nothing /// No episode with the given ID or slug could be found. [HttpPost("{identifier:id}/refresh")] [PartialPermission(Kind.Write)] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task Refresh(Identifier identifier, [FromServices] IScanner scanner) { Guid id = await identifier.Match( id => Task.FromResult(id), async slug => (await libraryManager.Seasons.Get(slug)).Id ); await scanner.SendRefreshRequest(nameof(Season), id); return NoContent(); } /// /// Get episodes in the season /// /// /// List the episodes that are part of the specified season. /// /// The ID or slug of the . /// A key to sort episodes by. /// An optional list of filters. /// The number of episodes to return. /// The aditional fields to include in the result. /// A page of episodes. /// The filters or the sort parameters are invalid. /// No season with the given ID or slug could be found. [HttpGet("{identifier:id}/episodes")] [HttpGet("{identifier:id}/episode", Order = AlternativeRoute)] [PartialPermission(Kind.Read)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(RequestError))] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task>> GetEpisode( Identifier identifier, [FromQuery] Sort sortBy, [FromQuery] Filter? filter, [FromQuery] Pagination pagination, [FromQuery] Include fields ) { ICollection resources = await libraryManager.Episodes.GetAll( Filter.And(filter, identifier.Matcher(x => x.SeasonId, x => x.Season!.Slug)), sortBy, fields, pagination ); if ( !resources.Any() && await libraryManager.Seasons.GetOrDefault(identifier.IsSame()) == null ) return NotFound(); return Page(resources, pagination.Limit); } /// /// Get season's show /// /// /// Get the show that this season is part of. /// /// The ID or slug of the . /// The aditional fields to include in the result. /// The show that contains this season. /// No season with the given ID or slug could be found. [HttpGet("{identifier:id}/show")] [PartialPermission(Kind.Read)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> GetShow( Identifier identifier, [FromQuery] Include fields ) { Show? ret = await libraryManager.Shows.GetOrDefault( identifier.IsContainedIn(x => x.Seasons!), fields ); if (ret == null) return NotFound(); return ret; } }