mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Creating the episode api
This commit is contained in:
parent
2df3562045
commit
7e098b4005
@ -23,6 +23,18 @@ namespace Kyoo.Controllers
|
|||||||
IGenreRepository GenreRepository { get; }
|
IGenreRepository GenreRepository { get; }
|
||||||
IProviderRepository ProviderRepository { get; }
|
IProviderRepository ProviderRepository { get; }
|
||||||
|
|
||||||
|
// Get by id
|
||||||
|
Task<Library> GetLibrary(int id);
|
||||||
|
Task<Collection> GetCollection(int id);
|
||||||
|
Task<Show> GetShow(int id);
|
||||||
|
Task<Season> GetSeason(int id);
|
||||||
|
Task<Season> GetSeason(int showID, int seasonNumber);
|
||||||
|
Task<Episode> GetEpisode(int id);
|
||||||
|
Task<Episode> GetEpisode(int showID, int seasonNumber, int episodeNumber);
|
||||||
|
Task<Genre> GetGenre(int id);
|
||||||
|
Task<Studio> GetStudio(int id);
|
||||||
|
Task<People> GetPeople(int id);
|
||||||
|
|
||||||
// Get by slug
|
// Get by slug
|
||||||
Task<Library> GetLibrary(string slug);
|
Task<Library> GetLibrary(string slug);
|
||||||
Task<Collection> GetCollection(string slug);
|
Task<Collection> GetCollection(string slug);
|
||||||
@ -31,7 +43,6 @@ namespace Kyoo.Controllers
|
|||||||
Task<Episode> GetEpisode(string showSlug, int seasonNumber, int episodeNumber);
|
Task<Episode> GetEpisode(string showSlug, int seasonNumber, int episodeNumber);
|
||||||
Task<Episode> GetMovieEpisode(string movieSlug);
|
Task<Episode> GetMovieEpisode(string movieSlug);
|
||||||
Task<Track> GetTrack(int id);
|
Task<Track> GetTrack(int id);
|
||||||
Task<Track> GetTrack(int episodeID, string language, bool isForced);
|
|
||||||
Task<Genre> GetGenre(string slug);
|
Task<Genre> GetGenre(string slug);
|
||||||
Task<Studio> GetStudio(string slug);
|
Task<Studio> GetStudio(string slug);
|
||||||
Task<People> GetPeople(string slug);
|
Task<People> GetPeople(string slug);
|
||||||
@ -150,8 +161,49 @@ namespace Kyoo.Controllers
|
|||||||
Pagination limit = default
|
Pagination limit = default
|
||||||
) => GetGenresFromShow(showSlug, where, new Sort<Genre>(sort), limit);
|
) => GetGenresFromShow(showSlug, where, new Sort<Genre>(sort), limit);
|
||||||
|
|
||||||
|
Task<ICollection<Track>> GetTracksFromEpisode(int episodeID,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default);
|
||||||
|
Task<ICollection<Track>> GetTracksFromEpisode(int episodeID,
|
||||||
|
[Optional] Expression<Func<Track, bool>> where,
|
||||||
|
Expression<Func<Track, object>> sort,
|
||||||
|
Pagination limit = default
|
||||||
|
) => GetTracksFromEpisode(episodeID, where, new Sort<Track>(sort), limit);
|
||||||
|
|
||||||
|
Task<ICollection<Track>> GetTracksFromEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default);
|
||||||
|
Task<ICollection<Track>> GetTracksFromEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
[Optional] Expression<Func<Track, bool>> where,
|
||||||
|
Expression<Func<Track, object>> sort,
|
||||||
|
Pagination limit = default
|
||||||
|
) => GetTracksFromEpisode(showID, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
|
||||||
|
|
||||||
|
Task<ICollection<Track>> GetTracksFromEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default);
|
||||||
|
Task<ICollection<Track>> GetTracksFromEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
[Optional] Expression<Func<Track, bool>> where,
|
||||||
|
Expression<Func<Track, object>> sort,
|
||||||
|
Pagination limit = default
|
||||||
|
) => GetTracksFromEpisode(showSlug, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
|
||||||
|
|
||||||
Task<Studio> GetStudioFromShow(int showID);
|
Task<Studio> GetStudioFromShow(int showID);
|
||||||
Task<Studio> GetStudioFromShow(string showSlug);
|
Task<Studio> GetStudioFromShow(string showSlug);
|
||||||
|
Task<Show> GetShowFromSeason(int seasonID);
|
||||||
|
Task<Show> GetShowFromEpisode(int episodeID);
|
||||||
|
Task<Season> GetSeasonFromEpisode(int episodeID);
|
||||||
|
|
||||||
Task<ICollection<Library>> GetLibrariesFromShow(int showID,
|
Task<ICollection<Library>> GetLibrariesFromShow(int showID,
|
||||||
Expression<Func<Library, bool>> where = null,
|
Expression<Func<Library, bool>> where = null,
|
||||||
|
@ -142,6 +142,9 @@ namespace Kyoo.Controllers
|
|||||||
Expression<Func<Show, object>> sort,
|
Expression<Func<Show, object>> sort,
|
||||||
Pagination limit = default
|
Pagination limit = default
|
||||||
) => GetFromCollection(slug, where, new Sort<Show>(sort), limit);
|
) => GetFromCollection(slug, where, new Sort<Show>(sort), limit);
|
||||||
|
|
||||||
|
Task<Show> GetFromSeason(int seasonID);
|
||||||
|
Task<Show> GetFromEpisode(int episodeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ISeasonRepository : IRepository<Season>
|
public interface ISeasonRepository : IRepository<Season>
|
||||||
@ -169,11 +172,17 @@ namespace Kyoo.Controllers
|
|||||||
Expression<Func<Season, object>> sort,
|
Expression<Func<Season, object>> sort,
|
||||||
Pagination limit = default
|
Pagination limit = default
|
||||||
) => GetFromShow(showSlug, where, new Sort<Season>(sort), limit);
|
) => GetFromShow(showSlug, where, new Sort<Season>(sort), limit);
|
||||||
|
|
||||||
|
Task<Season> GetFromEpisode(int episodeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IEpisodeRepository : IRepository<Episode>
|
public interface IEpisodeRepository : IRepository<Episode>
|
||||||
{
|
{
|
||||||
|
Task<Episode> Get(int showID, int seasonNumber, int episodeNumber);
|
||||||
Task<Episode> Get(string showSlug, int seasonNumber, int episodeNumber);
|
Task<Episode> Get(string showSlug, int seasonNumber, int episodeNumber);
|
||||||
|
Task<Episode> Get(int seasonID, int episodeNumber);
|
||||||
|
Task<Episode> GetAbsolute(int showID, int absoluteNumber);
|
||||||
|
Task<Episode> GetAbsolute(string showSlug, int absoluteNumber);
|
||||||
Task Delete(string showSlug, int seasonNumber, int episodeNumber);
|
Task Delete(string showSlug, int seasonNumber, int episodeNumber);
|
||||||
|
|
||||||
Task<ICollection<Episode>> GetFromShow(int showID,
|
Task<ICollection<Episode>> GetFromShow(int showID,
|
||||||
@ -231,7 +240,43 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
public interface ITrackRepository : IRepository<Track>
|
public interface ITrackRepository : IRepository<Track>
|
||||||
{
|
{
|
||||||
Task<Track> Get(int episodeID, string languageTag, bool isForced);
|
Task<ICollection<Track>> GetFromEpisode(int episodeID,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default);
|
||||||
|
Task<ICollection<Track>> GetFromEpisode(int episodeID,
|
||||||
|
[Optional] Expression<Func<Track, bool>> where,
|
||||||
|
Expression<Func<Track, object>> sort,
|
||||||
|
Pagination limit = default
|
||||||
|
) => GetFromEpisode(episodeID, where, new Sort<Track>(sort), limit);
|
||||||
|
|
||||||
|
Task<ICollection<Track>> GetFromEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default);
|
||||||
|
Task<ICollection<Track>> GetFromEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
[Optional] Expression<Func<Track, bool>> where,
|
||||||
|
Expression<Func<Track, object>> sort,
|
||||||
|
Pagination limit = default
|
||||||
|
) => GetFromEpisode(showID, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
|
||||||
|
|
||||||
|
Task<ICollection<Track>> GetFromEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default);
|
||||||
|
Task<ICollection<Track>> GetFromEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
[Optional] Expression<Func<Track, bool>> where,
|
||||||
|
Expression<Func<Track, object>> sort,
|
||||||
|
Pagination limit = default
|
||||||
|
) => GetFromEpisode(showSlug, seasonNumber, episodeNumber, where, new Sort<Track>(sort), limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ILibraryRepository : IRepository<Library>
|
public interface ILibraryRepository : IRepository<Library>
|
||||||
|
@ -75,6 +75,56 @@ namespace Kyoo.Controllers
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Library> GetLibrary(int id)
|
||||||
|
{
|
||||||
|
return LibraryRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Collection> GetCollection(int id)
|
||||||
|
{
|
||||||
|
return CollectionRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Show> GetShow(int id)
|
||||||
|
{
|
||||||
|
return ShowRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Season> GetSeason(int id)
|
||||||
|
{
|
||||||
|
return SeasonRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Season> GetSeason(int showID, int seasonNumber)
|
||||||
|
{
|
||||||
|
return SeasonRepository.Get(showID, seasonNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Episode> GetEpisode(int id)
|
||||||
|
{
|
||||||
|
return EpisodeRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Episode> GetEpisode(int showID, int seasonNumber, int episodeNumber)
|
||||||
|
{
|
||||||
|
return EpisodeRepository.Get(showID, seasonNumber, episodeNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Genre> GetGenre(int id)
|
||||||
|
{
|
||||||
|
return GenreRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Studio> GetStudio(int id)
|
||||||
|
{
|
||||||
|
return StudioRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<People> GetPeople(int id)
|
||||||
|
{
|
||||||
|
return PeopleRepository.Get(id);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<Library> GetLibrary(string slug)
|
public Task<Library> GetLibrary(string slug)
|
||||||
{
|
{
|
||||||
return LibraryRepository.Get(slug);
|
return LibraryRepository.Get(slug);
|
||||||
@ -109,11 +159,6 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
return TrackRepository.Get(id);
|
return TrackRepository.Get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Track> GetTrack(int episodeID, string language, bool isForced)
|
|
||||||
{
|
|
||||||
return TrackRepository.Get(episodeID, language, isForced);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<Genre> GetGenre(string slug)
|
public Task<Genre> GetGenre(string slug)
|
||||||
{
|
{
|
||||||
@ -290,6 +335,34 @@ namespace Kyoo.Controllers
|
|||||||
return GenreRepository.GetFromShow(showSlug, where, sort, limit);
|
return GenreRepository.GetFromShow(showSlug, where, sort, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<ICollection<Track>> GetTracksFromEpisode(int episodeID,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default)
|
||||||
|
{
|
||||||
|
return TrackRepository.GetFromEpisode(episodeID, where, sort, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ICollection<Track>> GetTracksFromEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default)
|
||||||
|
{
|
||||||
|
return TrackRepository.GetFromEpisode(showID, seasonNumber, episodeNumber, where, sort, limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ICollection<Track>> GetTracksFromEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default)
|
||||||
|
{
|
||||||
|
return TrackRepository.GetFromEpisode(showSlug, seasonNumber, episodeNumber, where, sort, limit);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<Studio> GetStudioFromShow(int showID)
|
public Task<Studio> GetStudioFromShow(int showID)
|
||||||
{
|
{
|
||||||
return StudioRepository.GetFromShow(showID);
|
return StudioRepository.GetFromShow(showID);
|
||||||
@ -300,6 +373,21 @@ namespace Kyoo.Controllers
|
|||||||
return StudioRepository.GetFromShow(showSlug);
|
return StudioRepository.GetFromShow(showSlug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Show> GetShowFromSeason(int seasonID)
|
||||||
|
{
|
||||||
|
return ShowRepository.GetFromSeason(seasonID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Show> GetShowFromEpisode(int episodeID)
|
||||||
|
{
|
||||||
|
return ShowRepository.GetFromEpisode(episodeID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Season> GetSeasonFromEpisode(int episodeID)
|
||||||
|
{
|
||||||
|
return SeasonRepository.GetFromEpisode(episodeID);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<ICollection<Library>> GetLibrariesFromShow(int showID,
|
public Task<ICollection<Library>> GetLibrariesFromShow(int showID,
|
||||||
Expression<Func<Library, bool>> where = null,
|
Expression<Func<Library, bool>> where = null,
|
||||||
Sort<Library> sort = default,
|
Sort<Library> sort = default,
|
||||||
|
@ -61,7 +61,32 @@ namespace Kyoo.Controllers
|
|||||||
&& x.SeasonNumber == seasonNumber
|
&& x.SeasonNumber == seasonNumber
|
||||||
&& x.EpisodeNumber == episodeNumber);
|
&& x.EpisodeNumber == episodeNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Episode> Get(int showID, int seasonNumber, int episodeNumber)
|
||||||
|
{
|
||||||
|
return _database.Episodes.FirstOrDefaultAsync(x => x.ShowID == showID
|
||||||
|
&& x.SeasonNumber == seasonNumber
|
||||||
|
&& x.EpisodeNumber == episodeNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Episode> Get(int seasonID, int episodeNumber)
|
||||||
|
{
|
||||||
|
return _database.Episodes.FirstOrDefaultAsync(x => x.SeasonID == seasonID
|
||||||
|
&& x.EpisodeNumber == episodeNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Episode> GetAbsolute(int showID, int absoluteNumber)
|
||||||
|
{
|
||||||
|
return _database.Episodes.FirstOrDefaultAsync(x => x.ShowID == showID
|
||||||
|
&& x.AbsoluteNumber == absoluteNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Episode> GetAbsolute(string showSlug, int absoluteNumber)
|
||||||
|
{
|
||||||
|
return _database.Episodes.FirstOrDefaultAsync(x => x.Show.Slug == showSlug
|
||||||
|
&& x.AbsoluteNumber == absoluteNumber);
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task<ICollection<Episode>> Search(string query)
|
public override async Task<ICollection<Episode>> Search(string query)
|
||||||
{
|
{
|
||||||
return await _database.Episodes
|
return await _database.Episodes
|
||||||
|
@ -155,5 +155,10 @@ namespace Kyoo.Controllers
|
|||||||
if (obj.Episodes != null)
|
if (obj.Episodes != null)
|
||||||
await _episodes.Value.DeleteRange(obj.Episodes);
|
await _episodes.Value.DeleteRange(obj.Episodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Season> GetFromEpisode(int episodeID)
|
||||||
|
{
|
||||||
|
return _database.Seasons.FirstOrDefaultAsync(x => x.Episodes.Any(y => y.ID == episodeID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -244,5 +244,15 @@ namespace Kyoo.Controllers
|
|||||||
throw new ItemNotFound();
|
throw new ItemNotFound();
|
||||||
return shows;
|
return shows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Show> GetFromSeason(int seasonID)
|
||||||
|
{
|
||||||
|
return _database.Shows.FirstOrDefaultAsync(x => x.Seasons.Any(y => y.ID == seasonID));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Show> GetFromEpisode(int episodeID)
|
||||||
|
{
|
||||||
|
return _database.Shows.FirstOrDefaultAsync(x => x.Episodes.Any(y => y.ID == episodeID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,41 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Kyoo.Models.Exceptions;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kyoo.Controllers
|
namespace Kyoo.Controllers
|
||||||
{
|
{
|
||||||
public class TrackRepository : LocalRepository<Track>, ITrackRepository
|
public class TrackRepository : LocalRepository<Track>, ITrackRepository
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext _database;
|
private readonly DatabaseContext _database;
|
||||||
|
private readonly Lazy<IEpisodeRepository> _episodes;
|
||||||
protected override Expression<Func<Track, object>> DefaultSort => x => x.ID;
|
protected override Expression<Func<Track, object>> DefaultSort => x => x.ID;
|
||||||
|
|
||||||
|
|
||||||
public TrackRepository(DatabaseContext database) : base(database)
|
public TrackRepository(DatabaseContext database, IServiceProvider services) : base(database)
|
||||||
{
|
{
|
||||||
_database = database;
|
_database = database;
|
||||||
|
_episodes = new Lazy<IEpisodeRepository>(services.GetRequiredService<IEpisodeRepository>);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
_database.Dispose();
|
||||||
|
if (_episodes.IsValueCreated)
|
||||||
|
_episodes.Value.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
await _database.DisposeAsync();
|
||||||
|
if (_episodes.IsValueCreated)
|
||||||
|
await _episodes.Value.DisposeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<Track> Get(string slug)
|
public override Task<Track> Get(string slug)
|
||||||
@ -42,14 +61,6 @@ namespace Kyoo.Controllers
|
|||||||
&& x.Language == language
|
&& x.Language == language
|
||||||
&& x.IsForced == forced);
|
&& x.IsForced == forced);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<Track> Get(int episodeID, string languageTag, bool isForced)
|
|
||||||
{
|
|
||||||
return _database.Tracks.FirstOrDefaultAsync(x => x.EpisodeID == episodeID
|
|
||||||
&& x.Language == languageTag
|
|
||||||
&& x.IsForced == isForced);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Task<ICollection<Track>> Search(string query)
|
public override Task<ICollection<Track>> Search(string query)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Tracks do not support the search method.");
|
throw new InvalidOperationException("Tracks do not support the search method.");
|
||||||
@ -82,5 +93,55 @@ namespace Kyoo.Controllers
|
|||||||
_database.Entry(obj).State = EntityState.Deleted;
|
_database.Entry(obj).State = EntityState.Deleted;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<Track>> GetFromEpisode(int episodeID,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default)
|
||||||
|
{
|
||||||
|
ICollection<Track> tracks = await ApplyFilters(_database.Tracks.Where(x => x.EpisodeID == episodeID),
|
||||||
|
where,
|
||||||
|
sort,
|
||||||
|
limit);
|
||||||
|
if (!tracks.Any() && await _episodes.Value.Get(episodeID) == null)
|
||||||
|
throw new ItemNotFound();
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<Track>> GetFromEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default)
|
||||||
|
{
|
||||||
|
ICollection<Track> tracks = await ApplyFilters(_database.Tracks.Where(x => x.Episode.ShowID == showID
|
||||||
|
&& x.Episode.SeasonNumber == seasonNumber
|
||||||
|
&& x.Episode.EpisodeNumber == episodeNumber),
|
||||||
|
where,
|
||||||
|
sort,
|
||||||
|
limit);
|
||||||
|
if (!tracks.Any() && await _episodes.Value.Get(showID, seasonNumber, episodeNumber) == null)
|
||||||
|
throw new ItemNotFound();
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ICollection<Track>> GetFromEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
Expression<Func<Track, bool>> where = null,
|
||||||
|
Sort<Track> sort = default,
|
||||||
|
Pagination limit = default)
|
||||||
|
{
|
||||||
|
ICollection<Track> tracks = await ApplyFilters(_database.Tracks.Where(x => x.Episode.Show.Slug == showSlug
|
||||||
|
&& x.Episode.SeasonNumber == seasonNumber
|
||||||
|
&& x.Episode.EpisodeNumber == episodeNumber),
|
||||||
|
where,
|
||||||
|
sort,
|
||||||
|
limit);
|
||||||
|
if (!tracks.Any() && await _episodes.Value.Get(showSlug, seasonNumber, episodeNumber) == null)
|
||||||
|
throw new ItemNotFound();
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,43 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Kyoo.Models;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Kyoo.Controllers;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
|
|
||||||
namespace Kyoo.Api
|
|
||||||
{
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
[ApiController]
|
|
||||||
public class EpisodesController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly ILibraryManager _libraryManager;
|
|
||||||
|
|
||||||
public EpisodesController(ILibraryManager libraryManager)
|
|
||||||
{
|
|
||||||
_libraryManager = libraryManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{showSlug}/season/{seasonNumber}")]
|
|
||||||
[Authorize(Policy="Read")]
|
|
||||||
public Task<ActionResult<IEnumerable<Episode>>> GetEpisodesForSeason(string showSlug, int seasonNumber)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{showSlug}/season/{seasonNumber}/episode/{episodeNumber}")]
|
|
||||||
[Authorize(Policy="Read")]
|
|
||||||
[JsonDetailed]
|
|
||||||
public async Task<ActionResult<Episode>> GetEpisode(string showSlug, int seasonNumber, int episodeNumber)
|
|
||||||
{
|
|
||||||
Episode episode = await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
|
|
||||||
|
|
||||||
if (episode == null)
|
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
return episode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
173
Kyoo/Views/API/EpisodesApi.cs
Normal file
173
Kyoo/Views/API/EpisodesApi.cs
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
using System;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.CommonApi;
|
||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models.Exceptions;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace Kyoo.Api
|
||||||
|
{
|
||||||
|
[Route("api/episode")]
|
||||||
|
[Route("api/episodes")]
|
||||||
|
[ApiController]
|
||||||
|
public class EpisodesApi : CrudApi<Episode>
|
||||||
|
{
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
|
||||||
|
public EpisodesApi(ILibraryManager libraryManager, IConfiguration configuration)
|
||||||
|
: base(libraryManager.EpisodeRepository, configuration)
|
||||||
|
{
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{episodeID:int}/show")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Show>> GetShow(int episodeID)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetShowFromEpisode(episodeID);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}/show")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Show>> GetShow(string showSlug)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetShow(showSlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showID:int}-{seasonNumber:int}e{episodeNumber:int}/show")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Show>> GetShow(int showID, int _)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetShow(showID);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{episodeID:int}/season")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Season>> GetSeason(int episodeID)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetSeasonFromEpisode(episodeID);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}/season")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Season>> GetSeason(string showSlug, int seasonNuber)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetSeason(showSlug, seasonNuber);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showID:int}-{seasonNumber:int}e{episodeNumber:int}/season")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Season>> GetSeason(int showID, int seasonNumber)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetSeason(showID, seasonNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{episodeID:int}/track")]
|
||||||
|
[HttpGet("{episodeID:int}/tracks")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Page<Track>>> GetEpisode(int episodeID,
|
||||||
|
[FromQuery] string sortBy,
|
||||||
|
[FromQuery] int afterID,
|
||||||
|
[FromQuery] Dictionary<string, string> where,
|
||||||
|
[FromQuery] int limit = 30)
|
||||||
|
{
|
||||||
|
where.Remove("sortBy");
|
||||||
|
where.Remove("limit");
|
||||||
|
where.Remove("afterID");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ICollection<Track> ressources = await _libraryManager.GetTracksFromEpisode(episodeID,
|
||||||
|
ApiHelper.ParseWhere<Track>(where),
|
||||||
|
new Sort<Track>(sortBy),
|
||||||
|
new Pagination(limit, afterID));
|
||||||
|
|
||||||
|
return Page(ressources, limit);
|
||||||
|
}
|
||||||
|
catch (ItemNotFound)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new {Error = ex.Message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showID:int}-s{seasonNumber:int}e{episodeNumber:int}/track")]
|
||||||
|
[HttpGet("{showID:int}-s{seasonNumber:int}e{episodeNumber:int}/tracks")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Page<Track>>> GetEpisode(int showID,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
[FromQuery] string sortBy,
|
||||||
|
[FromQuery] int afterID,
|
||||||
|
[FromQuery] Dictionary<string, string> where,
|
||||||
|
[FromQuery] int limit = 30)
|
||||||
|
{
|
||||||
|
where.Remove("sortBy");
|
||||||
|
where.Remove("limit");
|
||||||
|
where.Remove("afterID");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ICollection<Track> ressources = await _libraryManager.GetTracksFromEpisode(showID,
|
||||||
|
seasonNumber,
|
||||||
|
episodeNumber,
|
||||||
|
ApiHelper.ParseWhere<Track>(where),
|
||||||
|
new Sort<Track>(sortBy),
|
||||||
|
new Pagination(limit, afterID));
|
||||||
|
|
||||||
|
return Page(ressources, limit);
|
||||||
|
}
|
||||||
|
catch (ItemNotFound)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new {Error = ex.Message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}/track")]
|
||||||
|
[HttpGet("{showSlug}-s{seasonNumber:int}e{episodeNumber:int}/tracks")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Page<Track>>> GetEpisode(string showSlug,
|
||||||
|
int seasonNumber,
|
||||||
|
int episodeNumber,
|
||||||
|
[FromQuery] string sortBy,
|
||||||
|
[FromQuery] int afterID,
|
||||||
|
[FromQuery] Dictionary<string, string> where,
|
||||||
|
[FromQuery] int limit = 30)
|
||||||
|
{
|
||||||
|
where.Remove("sortBy");
|
||||||
|
where.Remove("limit");
|
||||||
|
where.Remove("afterID");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ICollection<Track> ressources = await _libraryManager.GetTracksFromEpisode(showSlug,
|
||||||
|
seasonNumber,
|
||||||
|
episodeNumber,
|
||||||
|
ApiHelper.ParseWhere<Track>(where),
|
||||||
|
new Sort<Track>(sortBy),
|
||||||
|
new Pagination(limit, afterID));
|
||||||
|
|
||||||
|
return Page(ressources, limit);
|
||||||
|
}
|
||||||
|
catch (ItemNotFound)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
return BadRequest(new {Error = ex.Message});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -56,8 +56,8 @@ namespace Kyoo.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{showSlug}-{seasonNumber:int}/episode")]
|
[HttpGet("{showSlug}-s{seasonNumber:int}/episode")]
|
||||||
[HttpGet("{showSlug}-{seasonNumber:int}/episodes")]
|
[HttpGet("{showSlug}-s{seasonNumber:int}/episodes")]
|
||||||
[Authorize(Policy = "Read")]
|
[Authorize(Policy = "Read")]
|
||||||
public async Task<ActionResult<Page<Episode>>> GetEpisode(string showSlug,
|
public async Task<ActionResult<Page<Episode>>> GetEpisode(string showSlug,
|
||||||
int seasonNumber,
|
int seasonNumber,
|
||||||
@ -90,8 +90,8 @@ namespace Kyoo.Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{showID:int}-{seasonNumber:int}/episode")]
|
[HttpGet("{showID:int}-s{seasonNumber:int}/episode")]
|
||||||
[HttpGet("{showID:int}-{seasonNumber:int}/episodes")]
|
[HttpGet("{showID:int}-s{seasonNumber:int}/episodes")]
|
||||||
[Authorize(Policy = "Read")]
|
[Authorize(Policy = "Read")]
|
||||||
public async Task<ActionResult<Page<Episode>>> GetEpisode(int showID,
|
public async Task<ActionResult<Page<Episode>>> GetEpisode(int showID,
|
||||||
int seasonNumber,
|
int seasonNumber,
|
||||||
@ -123,5 +123,26 @@ namespace Kyoo.Api
|
|||||||
return BadRequest(new {Error = ex.Message});
|
return BadRequest(new {Error = ex.Message});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("{seasonID:int}/show")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Show>> GetShow(int seasonID)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetShowFromSeason(seasonID);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showSlug}-s{seasonNumber:int}/show")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Show>> GetShow(string showSlug, int _)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetShow(showSlug);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{showID:int}-s{seasonNumber:int}/show")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<ActionResult<Show>> GetShow(int showID, int _)
|
||||||
|
{
|
||||||
|
return await _libraryManager.GetShow(showID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit 3dad4b29d6565d08ef0bce1e450b5de65f6fac16
|
Subproject commit 7e8c74206356587b06272c5dd7c22fa09420d421
|
Loading…
x
Reference in New Issue
Block a user