Solving a bug with genres in the crawler and adding a genre api

This commit is contained in:
Zoe Roux 2020-04-19 03:09:41 +02:00
parent 7d7265ba12
commit 2293eb9494
7 changed files with 41 additions and 8 deletions

View File

@ -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<Genre> GetGenres();
Genre GetGenreBySlug(string slug);
Studio GetStudioBySlug(string slug);
Collection GetCollection(string slug);

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json;
namespace Kyoo.Models
{

View File

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

View File

@ -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<Genre> GetGenres()
{
return _database.Genres;
}
public IEnumerable<Genre> 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}");

View File

@ -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;
}

View File

@ -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<IEnumerable<Genre>> Index()
{
return _libraryManager.GetGenres().ToList();
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using Kyoo.Models;
using Kyoo.Models;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Kyoo.Controllers;