mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-07 10:14:13 -04:00
Fixing collection's link & cleaning library's link
This commit is contained in:
parent
aeed35bea6
commit
fdfd42c7c1
@ -8,7 +8,13 @@ namespace Kyoo.Models
|
||||
public int FirstID { get; set; }
|
||||
public int SecondID { get; set; }
|
||||
|
||||
public Link() {}
|
||||
public Link() {}
|
||||
|
||||
public Link(int firstID, int secondID)
|
||||
{
|
||||
FirstID = firstID;
|
||||
SecondID = secondID;
|
||||
}
|
||||
|
||||
public Link(IResource first, IResource second)
|
||||
{
|
||||
@ -39,7 +45,7 @@ namespace Kyoo.Models
|
||||
{
|
||||
get
|
||||
{
|
||||
return x => new {LibraryID = x.FirstID, ProviderID = x.SecondID};
|
||||
return x => new {First = x.FirstID, Second = x.SecondID};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,11 +69,15 @@ namespace Kyoo.Models
|
||||
Second = second;
|
||||
}
|
||||
|
||||
public Link(int firstID, int secondID)
|
||||
: base(firstID, secondID)
|
||||
{ }
|
||||
|
||||
public new static Expression<Func<Link<T1, T2>, object>> PrimaryKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return x => new {LibraryID = x.FirstID, ProviderID = x.SecondID};
|
||||
return x => new {First = x.FirstID, Second = x.SecondID};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Models;
|
||||
using Kyoo.Models.Exceptions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@ -148,31 +147,23 @@ namespace Kyoo.Controllers
|
||||
|
||||
public async Task AddShowLink(int showID, int? libraryID, int? collectionID)
|
||||
{
|
||||
Show show = await Get(showID);
|
||||
if (collectionID != null)
|
||||
{
|
||||
Collection collection = _database.GetTemporaryObject(new Collection {ID = collectionID.Value});
|
||||
|
||||
show.Collections ??= new List<Collection>();
|
||||
show.Collections.Add(collection);
|
||||
await _database.Links<Collection, Show>()
|
||||
.AddAsync(new Link<Collection, Show>(collectionID.Value, showID));
|
||||
await _database.SaveIfNoDuplicates();
|
||||
|
||||
if (libraryID != null)
|
||||
{
|
||||
Library library = await _database.Libraries.FirstOrDefaultAsync(x => x.ID == libraryID.Value);
|
||||
if (library == null)
|
||||
throw new ItemNotFound($"No library found with the ID {libraryID.Value}");
|
||||
library.Collections ??= new List<Collection>();
|
||||
library.Collections.Add(collection);
|
||||
await _database.Links<Library, Collection>()
|
||||
.AddAsync(new Link<Library, Collection>(libraryID.Value, collectionID.Value));
|
||||
await _database.SaveIfNoDuplicates();
|
||||
}
|
||||
}
|
||||
if (libraryID != null)
|
||||
{
|
||||
Library library = _database.GetTemporaryObject(new Library {ID = libraryID.Value});
|
||||
|
||||
show.Libraries ??= new List<Library>();
|
||||
show.Libraries.Add(library);
|
||||
await _database.Links<Library, Show>()
|
||||
.AddAsync(new Link<Library, Show>(libraryID.Value, showID));
|
||||
await _database.SaveIfNoDuplicates();
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,14 @@ namespace Kyoo
|
||||
public DbSet<ProviderID> Providers { get; set; }
|
||||
public DbSet<MetadataID> MetadataIds { get; set; }
|
||||
|
||||
// TODO Many to many with UsingEntity for this.
|
||||
public DbSet<PeopleRole> PeopleRoles { get; set; }
|
||||
|
||||
public DbSet<Link<T1, T2>> Links<T1, T2>()
|
||||
where T1 : class, IResource
|
||||
where T2 : class, IResource
|
||||
{
|
||||
return Set<Link<T1, T2>>();
|
||||
}
|
||||
|
||||
|
||||
public DatabaseContext()
|
||||
@ -115,7 +121,7 @@ namespace Kyoo
|
||||
.HasOne(x => x.Second)
|
||||
.WithMany(x => x.CollectionLinks),
|
||||
y => y.HasKey(Link<Collection, Show>.PrimaryKey));
|
||||
|
||||
|
||||
modelBuilder.Entity<Genre>()
|
||||
.HasMany(x => x.Shows)
|
||||
.WithMany(x => x.Genres)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f36ac1bb9bf60329a7f04ba76730f43ded7b0d9d
|
||||
Subproject commit a8a576bdd9e0c69fbae8e5e4f392c112fe3af8a2
|
Loading…
x
Reference in New Issue
Block a user