mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Making repositories return whole objects
This commit is contained in:
parent
d0117a8325
commit
b94328688b
@ -71,7 +71,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Episodes.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Episode obj)
|
||||
public async Task<Episode> Create(Episode obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -109,17 +109,17 @@ namespace Kyoo.Controllers
|
||||
* }
|
||||
*/
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(Episode obj)
|
||||
public async Task<Episode> CreateIfNotExists(Episode obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
Episode old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -129,11 +129,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(Episode edited, bool resetOld)
|
||||
public async Task<Episode> Edit(Episode edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -149,6 +149,7 @@ namespace Kyoo.Controllers
|
||||
|
||||
await Validate(old);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
private async Task Validate(Episode obj)
|
||||
@ -159,7 +160,7 @@ namespace Kyoo.Controllers
|
||||
if (obj.ExternalIDs != null)
|
||||
{
|
||||
foreach (MetadataID link in obj.ExternalIDs)
|
||||
link.ProviderID = await _providers.CreateIfNotExists(link.Provider);
|
||||
link.Provider = await _providers.CreateIfNotExists(link.Provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Genres.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Genre obj)
|
||||
public async Task<Genre> Create(Genre obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -74,17 +74,17 @@ namespace Kyoo.Controllers
|
||||
throw;
|
||||
}
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(Genre obj)
|
||||
public async Task<Genre> CreateIfNotExists(Genre obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
Genre old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -94,11 +94,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(Genre edited, bool resetOld)
|
||||
public async Task<Genre> Edit(Genre edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -112,6 +112,7 @@ namespace Kyoo.Controllers
|
||||
Utility.Nullify(old);
|
||||
Utility.Merge(old, edited);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
public async Task Delete(int id)
|
||||
|
@ -56,7 +56,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Libraries.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Library obj)
|
||||
public async Task<Library> Create(Library obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -79,17 +79,17 @@ namespace Kyoo.Controllers
|
||||
throw;
|
||||
}
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(Library obj)
|
||||
public async Task<Library> CreateIfNotExists(Library obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
Library old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -99,11 +99,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(Library edited, bool resetOld)
|
||||
public async Task<Library> Edit(Library edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -118,13 +118,14 @@ namespace Kyoo.Controllers
|
||||
Utility.Merge(old, edited);
|
||||
await Validate(old);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
private async Task Validate(Library obj)
|
||||
{
|
||||
if (obj.ProviderLinks != null)
|
||||
foreach (ProviderLink link in obj.ProviderLinks)
|
||||
link.ProviderID = await _providers.CreateIfNotExists(link.Provider);
|
||||
link.Provider = await _providers.CreateIfNotExists(link.Provider);
|
||||
}
|
||||
|
||||
public async Task Delete(int id)
|
||||
|
@ -55,7 +55,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Peoples.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(People obj)
|
||||
public async Task<People> Create(People obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -78,17 +78,17 @@ namespace Kyoo.Controllers
|
||||
throw;
|
||||
}
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(People obj)
|
||||
public async Task<People> CreateIfNotExists(People obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
People old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -98,11 +98,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(People edited, bool resetOld)
|
||||
public async Task<People> Edit(People edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -117,13 +117,14 @@ namespace Kyoo.Controllers
|
||||
Utility.Merge(old, edited);
|
||||
await Validate(old);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
private async Task Validate(People obj)
|
||||
{
|
||||
if (obj.ExternalIDs != null)
|
||||
foreach (MetadataID link in obj.ExternalIDs)
|
||||
link.ProviderID = await _providers.CreateIfNotExists(link.Provider);
|
||||
link.Provider = await _providers.CreateIfNotExists(link.Provider);
|
||||
}
|
||||
|
||||
public async Task Delete(int id)
|
||||
|
@ -54,7 +54,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Providers.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(ProviderID obj)
|
||||
public async Task<ProviderID> Create(ProviderID obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -73,17 +73,17 @@ namespace Kyoo.Controllers
|
||||
throw;
|
||||
}
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(ProviderID obj)
|
||||
public async Task<ProviderID> CreateIfNotExists(ProviderID obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
ProviderID old = await Get(obj.Name);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -93,11 +93,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Name);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(ProviderID edited, bool resetOld)
|
||||
public async Task<ProviderID> Edit(ProviderID edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -111,6 +111,7 @@ namespace Kyoo.Controllers
|
||||
Utility.Nullify(old);
|
||||
Utility.Merge(old, edited);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
public async Task Delete(int id)
|
||||
|
@ -70,7 +70,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Seasons.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Season obj)
|
||||
public async Task<Season> Create(Season obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -93,17 +93,17 @@ namespace Kyoo.Controllers
|
||||
throw;
|
||||
}
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(Season obj)
|
||||
public async Task<Season> CreateIfNotExists(Season obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
Season old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -113,11 +113,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(Season edited, bool resetOld)
|
||||
public async Task<Season> Edit(Season edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -133,6 +133,7 @@ namespace Kyoo.Controllers
|
||||
|
||||
await Validate(old);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
private async Task Validate(Season obj)
|
||||
@ -143,7 +144,7 @@ namespace Kyoo.Controllers
|
||||
if (obj.ExternalIDs != null)
|
||||
{
|
||||
foreach (MetadataID link in obj.ExternalIDs)
|
||||
link.ProviderID = await _providers.CreateIfNotExists(link.Provider);
|
||||
link.Provider = await _providers.CreateIfNotExists(link.Provider);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ namespace Kyoo.Controllers
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Show obj)
|
||||
public async Task<Show> Create(Show obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -127,17 +127,17 @@ namespace Kyoo.Controllers
|
||||
throw;
|
||||
}
|
||||
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(Show obj)
|
||||
public async Task<Show> CreateIfNotExists(Show obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
Show old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -147,11 +147,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(Show edited, bool resetOld)
|
||||
public async Task<Show> Edit(Show edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -166,24 +166,25 @@ namespace Kyoo.Controllers
|
||||
Utility.Merge(old, edited);
|
||||
await Validate(old);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
private async Task Validate(Show obj)
|
||||
{
|
||||
if (obj.Studio != null)
|
||||
obj.StudioID = await _studios.CreateIfNotExists(obj.Studio);
|
||||
obj.Studio = await _studios.CreateIfNotExists(obj.Studio);
|
||||
|
||||
if (obj.GenreLinks != null)
|
||||
foreach (GenreLink link in obj.GenreLinks)
|
||||
link.GenreID = await _genres.CreateIfNotExists(link.Genre);
|
||||
link.Genre = await _genres.CreateIfNotExists(link.Genre);
|
||||
|
||||
if (obj.People != null)
|
||||
foreach (PeopleLink link in obj.People)
|
||||
link.PeopleID = await _people.CreateIfNotExists(link.People);
|
||||
link.People = await _people.CreateIfNotExists(link.People);
|
||||
|
||||
if (obj.ExternalIDs != null)
|
||||
foreach (MetadataID link in obj.ExternalIDs)
|
||||
link.ProviderID = await _providers.CreateIfNotExists(link.Provider);
|
||||
link.Provider = await _providers.CreateIfNotExists(link.Provider);
|
||||
}
|
||||
|
||||
public async Task AddShowLink(int showID, int? libraryID, int? collectionID)
|
||||
|
@ -54,7 +54,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Studios.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Studio obj)
|
||||
public async Task<Studio> Create(Studio obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -72,17 +72,17 @@ namespace Kyoo.Controllers
|
||||
throw new DuplicatedItemException($"Trying to insert a duplicated studio (slug {obj.Slug} already exists).");
|
||||
throw;
|
||||
}
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public async Task<int> CreateIfNotExists(Studio obj)
|
||||
public async Task<Studio> CreateIfNotExists(Studio obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
Studio old = await Get(obj.Slug);
|
||||
if (old != null)
|
||||
return old.ID;
|
||||
return old;
|
||||
try
|
||||
{
|
||||
return await Create(obj);
|
||||
@ -92,11 +92,11 @@ namespace Kyoo.Controllers
|
||||
old = await Get(obj.Slug);
|
||||
if (old == null)
|
||||
throw new SystemException("Unknown database state.");
|
||||
return old.ID;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Edit(Studio edited, bool resetOld)
|
||||
public async Task<Studio> Edit(Studio edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -110,6 +110,7 @@ namespace Kyoo.Controllers
|
||||
Utility.Nullify(old);
|
||||
Utility.Merge(old, edited);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
public async Task Delete(int id)
|
||||
|
@ -57,7 +57,7 @@ namespace Kyoo.Controllers
|
||||
return await _database.Tracks.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<int> Create(Track obj)
|
||||
public async Task<Track> Create(Track obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -78,15 +78,15 @@ namespace Kyoo.Controllers
|
||||
throw new DuplicatedItemException($"Trying to insert a duplicated track (slug {obj.Slug} already exists).");
|
||||
throw;
|
||||
}
|
||||
return obj.ID;
|
||||
return obj;
|
||||
}
|
||||
|
||||
public Task<int> CreateIfNotExists(Track obj)
|
||||
public Task<Track> CreateIfNotExists(Track obj)
|
||||
{
|
||||
return Create(obj);
|
||||
}
|
||||
|
||||
public async Task Edit(Track edited, bool resetOld)
|
||||
public async Task<Track> Edit(Track edited, bool resetOld)
|
||||
{
|
||||
if (edited == null)
|
||||
throw new ArgumentNullException(nameof(edited));
|
||||
@ -100,6 +100,7 @@ namespace Kyoo.Controllers
|
||||
Utility.Nullify(old);
|
||||
Utility.Merge(old, edited);
|
||||
await _database.SaveChangesAsync();
|
||||
return old;
|
||||
}
|
||||
|
||||
public async Task Delete(int id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user