mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-07 18:24:14 -04:00
Finishing the Lazy load migration and solving some bugs with the API
This commit is contained in:
parent
cbc10acf54
commit
d28f976d2b
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Kyoo.Models
|
namespace Kyoo.Models
|
||||||
{
|
{
|
||||||
@ -7,6 +8,8 @@ namespace Kyoo.Models
|
|||||||
[JsonIgnore] public long ID { get; set; }
|
[JsonIgnore] public long ID { get; set; }
|
||||||
public string Slug { get; set; }
|
public string Slug { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
// public IEnumerable<Show> Shows { get; set; }
|
||||||
|
|
||||||
public Genre(string slug, string name)
|
public Genre(string slug, string name)
|
||||||
{
|
{
|
||||||
|
@ -2,12 +2,17 @@ namespace Kyoo.Models
|
|||||||
{
|
{
|
||||||
public class GenreLink
|
public class GenreLink
|
||||||
{
|
{
|
||||||
// TODO Make json serializer ignore this class and only serialize the Genre child.
|
|
||||||
// TODO include this class in the EF workflows.
|
|
||||||
|
|
||||||
public long ShowID { get; set; }
|
public long ShowID { get; set; }
|
||||||
public virtual Show Show { get; set; }
|
public virtual Show Show { get; set; }
|
||||||
public long GenreID { get; set; }
|
public long GenreID { get; set; }
|
||||||
public virtual Genre Genre { get; set; }
|
public virtual Genre Genre { get; set; }
|
||||||
|
|
||||||
|
public GenreLink() {}
|
||||||
|
|
||||||
|
public GenreLink(Show show, Genre genre)
|
||||||
|
{
|
||||||
|
Show = show;
|
||||||
|
Genre = genre;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,12 @@ namespace Kyoo.Models
|
|||||||
{
|
{
|
||||||
[JsonIgnore] public long ID { get; set; }
|
[JsonIgnore] public long ID { get; set; }
|
||||||
[JsonIgnore] public long PeopleID { get; set; }
|
[JsonIgnore] public long PeopleID { get; set; }
|
||||||
public virtual People People { get; set; }
|
[JsonIgnore] public virtual People People { get; set; }
|
||||||
|
|
||||||
|
public string Slug => People.Slug;
|
||||||
|
public string Name => People.Name;
|
||||||
|
public string ExternalIDs => People.ExternalIDs;
|
||||||
|
|
||||||
[JsonIgnore] public long ShowID { get; set; }
|
[JsonIgnore] public long ShowID { get; set; }
|
||||||
[JsonIgnore] public virtual Show Show { get; set; }
|
[JsonIgnore] public virtual Show Show { get; set; }
|
||||||
public string Role { get; set; }
|
public string Role { get; set; }
|
||||||
|
@ -29,7 +29,12 @@ namespace Kyoo.Models
|
|||||||
|
|
||||||
public bool IsCollection;
|
public bool IsCollection;
|
||||||
|
|
||||||
public virtual IEnumerable<Genre> Genres { get; set; }
|
public virtual IEnumerable<Genre> Genres
|
||||||
|
{
|
||||||
|
get { return GenreLinks?.Select(x => x.Genre); }
|
||||||
|
set { GenreLinks = value?.Select(x => new GenreLink(this, x)).ToList(); }
|
||||||
|
}
|
||||||
|
[JsonIgnore] public virtual List<GenreLink> GenreLinks { get; set; }
|
||||||
public virtual Studio Studio { get; set; }
|
public virtual Studio Studio { get; set; }
|
||||||
public virtual IEnumerable<PeopleLink> People { get; set; }
|
public virtual IEnumerable<PeopleLink> People { get; set; }
|
||||||
public virtual IEnumerable<Season> Seasons { get; set; }
|
public virtual IEnumerable<Season> Seasons { get; set; }
|
||||||
|
@ -56,7 +56,7 @@ namespace Kyoo.Models
|
|||||||
|
|
||||||
public class Track : Stream
|
public class Track : Stream
|
||||||
{
|
{
|
||||||
public int ID { get; set; }
|
[JsonIgnore] public long ID { get; set; }
|
||||||
[JsonIgnore] public long EpisodeID { get; set; }
|
[JsonIgnore] public long EpisodeID { get; set; }
|
||||||
public bool IsDefault
|
public bool IsDefault
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ namespace Kyoo.Models
|
|||||||
public string Link;
|
public string Link;
|
||||||
|
|
||||||
[JsonIgnore] public bool IsExternal { get; set; }
|
[JsonIgnore] public bool IsExternal { get; set; }
|
||||||
public virtual Episode Episode { get; set; }
|
[JsonIgnore] public virtual Episode Episode { get; set; }
|
||||||
|
|
||||||
public Track() { }
|
public Track() { }
|
||||||
|
|
||||||
|
@ -76,14 +76,7 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
public Show GetShowBySlug(string slug)
|
public Show GetShowBySlug(string slug)
|
||||||
{
|
{
|
||||||
Show ret = (from show in _database.Shows where show.Slug == slug select show).FirstOrDefault();
|
return (from show in _database.Shows where show.Slug == slug select show).FirstOrDefault();
|
||||||
// if (ret == null)
|
|
||||||
// return null;
|
|
||||||
//_database.Entry(ret).Collection(x => x.Genres).Load();
|
|
||||||
// _database.Entry(ret).Reference(x => x.Studio).Load();
|
|
||||||
// _database.Entry(ret).Collection(x => x.People).Load();
|
|
||||||
// _database.Entry(ret).Collection(x => x.Seasons).Load();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Show GetShow(string path)
|
public Show GetShow(string path)
|
||||||
|
@ -25,6 +25,10 @@ namespace Kyoo
|
|||||||
public DbSet<CollectionLink> CollectionLinks { get; set; }
|
public DbSet<CollectionLink> CollectionLinks { get; set; }
|
||||||
public DbSet<PeopleLink> PeopleLinks { get; set; }
|
public DbSet<PeopleLink> PeopleLinks { get; set; }
|
||||||
|
|
||||||
|
// This is used because EF doesn't support Many-To-Many relationships so for now we need to override the getter/setters to store this.
|
||||||
|
public DbSet<GenreLink> GenreLinks { get; set; }
|
||||||
|
|
||||||
|
|
||||||
private ValueConverter<string[], string> stringArrayConverter = new ValueConverter<string[], string>(
|
private ValueConverter<string[], string> stringArrayConverter = new ValueConverter<string[], string>(
|
||||||
arr => string.Join("|", arr),
|
arr => string.Join("|", arr),
|
||||||
str => str.Split("|", StringSplitOptions.None));
|
str => str.Split("|", StringSplitOptions.None));
|
||||||
@ -48,6 +52,16 @@ namespace Kyoo
|
|||||||
modelBuilder.Entity<Track>()
|
modelBuilder.Entity<Track>()
|
||||||
.Property(t => t.IsForced)
|
.Property(t => t.IsForced)
|
||||||
.ValueGeneratedNever();
|
.ValueGeneratedNever();
|
||||||
|
|
||||||
|
|
||||||
|
modelBuilder.Entity<GenreLink>()
|
||||||
|
.HasKey(x => new {x.ShowID, x.GenreID});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Show>()
|
||||||
|
.Ignore(x => x.Genres);
|
||||||
|
|
||||||
|
// modelBuilder.Entity<Genre>()
|
||||||
|
// .Ignore(x => x.Shows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user