// 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.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
{
///
/// An endpoint to search for every resources of kyoo. Searching for only a specific type of resource
/// is available on the said endpoint.
///
[Route("search")]
[ApiController]
[ApiDefinition("Search", Group = ResourcesGroup)]
public class SearchApi : BaseApi
{
private readonly ISearchManager _searchManager;
public SearchApi(ISearchManager searchManager)
{
_searchManager = searchManager;
}
// TODO: add filters and facets
///
/// Search collections
///
///
/// Search for collections
///
/// The query to search for.
/// Sort information about the query (sort by, sort order).
/// How many items per page should be returned, where should the page start...
/// The aditional fields to include in the result.
/// A list of collections found for the specified query.
[HttpGet("collections")]
[HttpGet("collection", Order = AlternativeRoute)]
[Permission(nameof(Collection), Kind.Read)]
[ApiDefinition("Collections")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> SearchCollections(
[FromQuery] string? q,
[FromQuery] Sort sortBy,
[FromQuery] SearchPagination pagination,
[FromQuery] Include fields)
{
return SearchPage(await _searchManager.SearchCollections(q, sortBy, pagination, fields));
}
///
/// Search shows
///
///
/// Search for shows
///
/// The query to search for.
/// Sort information about the query (sort by, sort order).
/// How many items per page should be returned, where should the page start...
/// The aditional fields to include in the result.
/// A list of shows found for the specified query.
[HttpGet("shows")]
[HttpGet("show", Order = AlternativeRoute)]
[Permission(nameof(Show), Kind.Read)]
[ApiDefinition("Show")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> SearchShows(
[FromQuery] string? q,
[FromQuery] Sort sortBy,
[FromQuery] SearchPagination pagination,
[FromQuery] Include fields)
{
return SearchPage(await _searchManager.SearchShows(q, sortBy, pagination, fields));
}
///
/// Search movie
///
///
/// Search for movie
///
/// The query to search for.
/// Sort information about the query (sort by, sort order).
/// How many items per page should be returned, where should the page start...
/// The aditional fields to include in the result.
/// A list of movies found for the specified query.
[HttpGet("movies")]
[HttpGet("movie", Order = AlternativeRoute)]
[Permission(nameof(Movie), Kind.Read)]
[ApiDefinition("Movie")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> SearchMovies(
[FromQuery] string? q,
[FromQuery] Sort sortBy,
[FromQuery] SearchPagination pagination,
[FromQuery] Include fields)
{
return SearchPage(await _searchManager.SearchMovies(q, sortBy, pagination, fields));
}
///
/// Search items
///
///
/// Search for items
///
/// The query to search for.
/// Sort information about the query (sort by, sort order).
/// How many items per page should be returned, where should the page start...
/// The aditional fields to include in the result.
/// A list of items found for the specified query.
[HttpGet("items")]
[HttpGet("item", Order = AlternativeRoute)]
[Permission(nameof(ILibraryItem), Kind.Read)]
[ApiDefinition("Item")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> SearchItems(
[FromQuery] string? q,
[FromQuery] Sort sortBy,
[FromQuery] SearchPagination pagination,
[FromQuery] Include fields)
{
return SearchPage(await _searchManager.SearchItems(q, sortBy, pagination, fields));
}
///
/// Search episodes
///
///
/// Search for episodes
///
/// The query to search for.
/// Sort information about the query (sort by, sort order).
/// How many items per page should be returned, where should the page start...
/// The aditional fields to include in the result.
/// A list of episodes found for the specified query.
[HttpGet("episodes")]
[HttpGet("episode", Order = AlternativeRoute)]
[Permission(nameof(Episode), Kind.Read)]
[ApiDefinition("Episodes")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> SearchEpisodes(
[FromQuery] string? q,
[FromQuery] Sort sortBy,
[FromQuery] SearchPagination pagination,
[FromQuery] Include fields)
{
return SearchPage(await _searchManager.SearchEpisodes(q, sortBy, pagination, fields));
}
///
/// Search studios
///
///
/// Search for studios
///
/// The query to search for.
/// Sort information about the query (sort by, sort order).
/// How many items per page should be returned, where should the page start...
/// The aditional fields to include in the result.
/// A list of studios found for the specified query.
[HttpGet("studios")]
[HttpGet("studio", Order = AlternativeRoute)]
[Permission(nameof(Studio), Kind.Read)]
[ApiDefinition("Studios")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> SearchStudios(
[FromQuery] string? q,
[FromQuery] Sort sortBy,
[FromQuery] SearchPagination pagination,
[FromQuery] Include fields)
{
return SearchPage(await _searchManager.SearchStudios(q, sortBy, pagination, fields));
}
}
}