mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Solving a bug with genres in the crawler and adding a genre api
This commit is contained in:
parent
7d7265ba12
commit
2293eb9494
@ -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);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
@ -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}");
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
26
Kyoo/Views/API/GenresAPI.cs
Normal file
26
Kyoo/Views/API/GenresAPI.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Kyoo.Models;
|
||||
using Kyoo.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using Kyoo.Controllers;
|
||||
|
Loading…
x
Reference in New Issue
Block a user