From 114f105f37854aec83c913a4143c817cfd121efa Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 19 Apr 2020 04:27:20 +0200 Subject: [PATCH] Adding a metadata editor for shows --- Kyoo.Common/Controllers/ILibraryManager.cs | 1 + Kyoo.Common/Models/Show.cs | 2 +- Kyoo/Controllers/LibraryManager.cs | 24 +++++++++++++++----- Kyoo/Views/API/StudioAPI.cs | 26 ++++++++++++++++++++++ Kyoo/Views/WebClient | 2 +- 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 Kyoo/Views/API/StudioAPI.cs diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index a033ff44..9dfc8a67 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -28,6 +28,7 @@ namespace Kyoo.Controllers IEnumerable SearchCollections(string searchQuery); Library GetLibrary(string librarySlug); IEnumerable GetLibraries(); + IEnumerable GetStudios(); Show GetShowBySlug(string slug); Show GetShow(string path); Season GetSeason(string showSlug, long seasonNumber); diff --git a/Kyoo.Common/Models/Show.cs b/Kyoo.Common/Models/Show.cs index 467cd04b..b4d45cf4 100644 --- a/Kyoo.Common/Models/Show.cs +++ b/Kyoo.Common/Models/Show.cs @@ -127,5 +127,5 @@ namespace Kyoo.Models } } - public enum Status { Finished, Airing } + public enum Status { Finished, Airing, Planned } } diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index e0e3a169..29714ca1 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -210,6 +210,11 @@ namespace Kyoo.Controllers return (from genre in _database.Genres where genre.Slug == slug select genre).FirstOrDefault(); } + public IEnumerable GetStudios() + { + return _database.Studios; + } + public Studio GetStudio(long showID) { return (from show in _database.Shows where show.ID == showID select show.Studio).FirstOrDefault(); @@ -371,20 +376,27 @@ namespace Kyoo.Controllers try { Show show = _database.Entry(edited).IsKeySet - ? _database.Shows.FirstOrDefault(x => x.ID == edited.ID) - : _database.Shows.FirstOrDefault(x => x.Slug == edited.Slug); + ? _database.Shows.Include(x => x.GenreLinks).FirstOrDefault(x => x.ID == edited.ID) + : _database.Shows.Include(x => x.GenreLinks).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}"); Utility.Complete(show, edited); - - Studio tmp = _database.Studios.FirstOrDefault(x => x.Slug == edited.Studio.Slug); - if (tmp != null) - show.Studio = tmp; + + if (edited.Studio != null) + { + if (edited.Studio.Slug == null) + edited.Studio.Slug = Utility.ToSlug(edited.Studio.Name); + Studio tmp = _database.Studios.FirstOrDefault(x => x.Slug == edited.Studio.Slug); + if (tmp != null) + show.Studio = tmp; + } show.GenreLinks = edited.GenreLinks?.Select(x => { + if (x.Genre.Slug == null) + x.Genre.Slug = Utility.ToSlug(x.Genre.Name); x.Genre = _database.Genres.FirstOrDefault(y => y.Slug == x.Genre.Slug) ?? x.Genre; x.GenreID = x.Genre.ID; return x; diff --git a/Kyoo/Views/API/StudioAPI.cs b/Kyoo/Views/API/StudioAPI.cs new file mode 100644 index 00000000..4437d5ca --- /dev/null +++ b/Kyoo/Views/API/StudioAPI.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/studios")] + [Route("api/studio")] + [ApiController] + public class StudioAPI : ControllerBase + { + private readonly ILibraryManager _libraryManager; + + public StudioAPI(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + + public ActionResult> Index() + { + return _libraryManager.GetStudios().ToList(); + } + } +} \ No newline at end of file diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 4288ecd0..bdac52cc 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 4288ecd02e4f5f467659eb031fb172372c8c7af4 +Subproject commit bdac52cc189dd62e5cc8c60555b9f8395c2d6079