diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index 260b0ea6..a033ff44 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -37,6 +37,7 @@ namespace Kyoo.Controllers WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true); WatchItem GetMovieWatchItem(string movieSlug); People GetPeopleBySlug(string slug); + IEnumerable GetGenres(); Genre GetGenreBySlug(string slug); Studio GetStudioBySlug(string slug); Collection GetCollection(string slug); diff --git a/Kyoo.Common/Models/Genre.cs b/Kyoo.Common/Models/Genre.cs index 333fa900..e57cd286 100644 --- a/Kyoo.Common/Models/Genre.cs +++ b/Kyoo.Common/Models/Genre.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Kyoo.Models { diff --git a/Kyoo.Common/Utility.cs b/Kyoo.Common/Utility.cs index 296e8310..092d8275 100644 --- a/Kyoo.Common/Utility.cs +++ b/Kyoo.Common/Utility.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 7a6dbe81..e0e3a169 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -2,7 +2,6 @@ using Kyoo.Models; using Kyoo.Models.Watch; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; using Kyoo.Models.Exceptions; using Microsoft.EntityFrameworkCore; @@ -196,9 +195,14 @@ namespace Kyoo.Controllers return (from people in _database.Peoples where people.Slug == slug select people).FirstOrDefault(); } + public IEnumerable GetGenres() + { + return _database.Genres; + } + public IEnumerable GetGenreForShow(long showID) { - return ((from show in _database.Shows where show.ID == showID select show.Genres).FirstOrDefault()); + return (from show in _database.Shows where show.ID == showID select show.Genres).FirstOrDefault(); } public Genre GetGenreBySlug(string slug) @@ -368,7 +372,7 @@ namespace Kyoo.Controllers { Show show = _database.Entry(edited).IsKeySet ? _database.Shows.FirstOrDefault(x => x.ID == edited.ID) - : GetShowBySlug(edited.Slug); + : _database.Shows.FirstOrDefault(x => x.Slug == edited.Slug); if (show == null) throw new ItemNotFound($"No show could be found with the id {edited.ID} or the slug {edited.Slug}"); diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo/Tasks/Crawler.cs index 219e65e1..d856e97d 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo/Tasks/Crawler.cs @@ -136,6 +136,11 @@ namespace Kyoo.Controllers People existing = _libraryManager.GetPeopleBySlug(x.Slug); return existing != null ? new PeopleLink(existing, show, x.Role, x.Type) : x; }).ToList(); + show.Genres = show.Genres.Select(x => + { + Genre existing = _libraryManager.GetGenreBySlug(x.Slug); + return existing ?? x; + }); return show; } diff --git a/Kyoo/Views/API/GenresAPI.cs b/Kyoo/Views/API/GenresAPI.cs new file mode 100644 index 00000000..21dc5643 --- /dev/null +++ b/Kyoo/Views/API/GenresAPI.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using System.Linq; +using Kyoo.Controllers; +using Kyoo.Models; +using Microsoft.AspNetCore.Mvc; + +namespace Kyoo.API +{ + [Route("api/genres")] + [Route("api/genre")] + [ApiController] + public class GenresAPI : ControllerBase + { + private readonly ILibraryManager _libraryManager; + + public GenresAPI(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + + public ActionResult> Index() + { + return _libraryManager.GetGenres().ToList(); + } + } +} \ No newline at end of file diff --git a/Kyoo/Views/API/ShowsAPI.cs b/Kyoo/Views/API/ShowsAPI.cs index 310a83cd..5f1a8fa3 100644 --- a/Kyoo/Views/API/ShowsAPI.cs +++ b/Kyoo/Views/API/ShowsAPI.cs @@ -1,5 +1,4 @@ -using System; -using Kyoo.Models; +using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using Kyoo.Controllers;