diff --git a/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs
index a217fc85..723c21a6 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs
@@ -31,46 +31,20 @@ namespace Kyoo.Core.Controllers;
///
/// A local repository to handle collections
///
-public class CollectionRepository : LocalRepository
+public class CollectionRepository(DatabaseContext database) : LocalRepository(database)
{
- ///
- /// The database handle
- ///
- private readonly DatabaseContext _database;
-
- ///
- /// Create a new .
- ///
- /// The database handle to use
- /// The thumbnail manager used to store images.
- public CollectionRepository(DatabaseContext database, IThumbnailsManager thumbs)
- : base(database, thumbs)
- {
- _database = database;
- }
-
///
public override async Task> Search(
string query,
Include? include = default
)
{
- return await AddIncludes(_database.Collections, include)
+ return await AddIncludes(Database.Collections, include)
.Where(x => EF.Functions.ILike(x.Name + " " + x.Slug, $"%{query}%"))
.Take(20)
.ToListAsync();
}
- ///
- public override async Task Create(Collection obj)
- {
- await base.Create(obj);
- _database.Entry(obj).State = EntityState.Added;
- await _database.SaveChangesAsync(() => Get(obj.Slug));
- await IRepository.OnResourceCreated(obj);
- return obj;
- }
-
///
protected override async Task Validate(Collection resource)
{
@@ -82,21 +56,13 @@ public class CollectionRepository : LocalRepository
public async Task AddMovie(Guid id, Guid movieId)
{
- _database.AddLinks(id, movieId);
- await _database.SaveChangesAsync();
+ Database.AddLinks(id, movieId);
+ await Database.SaveChangesAsync();
}
public async Task AddShow(Guid id, Guid showId)
{
- _database.AddLinks(id, showId);
- await _database.SaveChangesAsync();
- }
-
- ///
- public override async Task Delete(Collection obj)
- {
- _database.Entry(obj).State = EntityState.Deleted;
- await _database.SaveChangesAsync();
- await base.Delete(obj);
+ Database.AddLinks(id, showId);
+ await Database.SaveChangesAsync();
}
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs
index b89b3204..d6a8c9ef 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs
@@ -32,11 +32,8 @@ namespace Kyoo.Core.Controllers;
///
/// A local repository to handle episodes.
///
-public class EpisodeRepository(
- DatabaseContext database,
- IRepository shows,
- IThumbnailsManager thumbs
-) : LocalRepository(database, thumbs)
+public class EpisodeRepository(DatabaseContext database, IRepository shows)
+ : LocalRepository(database)
{
static EpisodeRepository()
{
@@ -64,34 +61,18 @@ public class EpisodeRepository(
Include? include = default
)
{
- return await AddIncludes(database.Episodes, include)
+ return await AddIncludes(Database.Episodes, include)
.Where(x => EF.Functions.ILike(x.Name!, $"%{query}%"))
.Take(20)
.ToListAsync();
}
- protected override Task GetDuplicated(Episode item)
- {
- if (item is { SeasonNumber: not null, EpisodeNumber: not null })
- return database.Episodes.FirstOrDefaultAsync(x =>
- x.ShowId == item.ShowId
- && x.SeasonNumber == item.SeasonNumber
- && x.EpisodeNumber == item.EpisodeNumber
- );
- return database.Episodes.FirstOrDefaultAsync(x =>
- x.ShowId == item.ShowId && x.AbsoluteNumber == item.AbsoluteNumber
- );
- }
-
///
public override async Task Create(Episode obj)
{
+ // Set it for the OnResourceCreated event and the return value.
obj.ShowSlug = obj.Show?.Slug ?? (await shows.Get(obj.ShowId)).Slug;
- await base.Create(obj);
- database.Entry(obj).State = EntityState.Added;
- await database.SaveChangesAsync(() => GetDuplicated(obj));
- await IRepository.OnResourceCreated(obj);
- return obj;
+ return await base.Create(obj);
}
///
@@ -111,7 +92,7 @@ public class EpisodeRepository(
}
if (resource.SeasonId == null && resource.SeasonNumber != null)
{
- resource.Season = await database.Seasons.FirstOrDefaultAsync(x =>
+ resource.Season = await Database.Seasons.FirstOrDefaultAsync(x =>
x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
);
}
@@ -120,14 +101,40 @@ public class EpisodeRepository(
///
public override async Task Delete(Episode obj)
{
- int epCount = await database
+ int epCount = await Database
.Episodes.Where(x => x.ShowId == obj.ShowId)
.Take(2)
.CountAsync();
- database.Entry(obj).State = EntityState.Deleted;
- await database.SaveChangesAsync();
- await base.Delete(obj);
if (epCount == 1)
await shows.Delete(obj.ShowId);
+ else
+ await base.Delete(obj);
+ }
+
+ ///
+ public override async Task DeleteAll(Filter filter)
+ {
+ ICollection items = await GetAll(filter);
+ Guid[] ids = items.Select(x => x.Id).ToArray();
+
+ await Database.Set().Where(x => ids.Contains(x.Id)).ExecuteDeleteAsync();
+ foreach (Episode resource in items)
+ await IRepository.OnResourceDeleted(resource);
+
+ Guid[] showIds = await Database
+ .Set()
+ .Where(filter.ToEfLambda())
+ .Select(x => x.Show!)
+ .Where(x => !x.Episodes!.Any())
+ .Select(x => x.Id)
+ .ToArrayAsync();
+
+ if (!showIds.Any())
+ return;
+
+ Filter[] showFilters = showIds
+ .Select(x => new Filter.Eq(nameof(Show.Id), x))
+ .ToArray();
+ await shows.DeleteAll(Filter.Or(showFilters)!);
}
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/LocalRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/LocalRepository.cs
index c0e56b7f..6b5c5026 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/LocalRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/LocalRepository.cs
@@ -29,38 +29,14 @@ using Kyoo.Abstractions.Models.Attributes;
using Kyoo.Abstractions.Models.Exceptions;
using Kyoo.Abstractions.Models.Utils;
using Kyoo.Postgresql;
-using Kyoo.Utils;
using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers;
-///
-/// A base class to create repositories using Entity Framework.
-///
-/// The type of this repository
-public abstract class LocalRepository : IRepository
+public abstract class LocalRepository(DatabaseContext database) : IRepository
where T : class, IResource, IQuery
{
- ///
- /// The Entity Framework's Database handle.
- ///
- protected DbContext Database { get; }
-
- ///
- /// The thumbnail manager used to store images.
- ///
- private readonly IThumbnailsManager _thumbs;
-
- ///
- /// Create a new base with the given database handle.
- ///
- /// A database connection to load resources of type
- /// The thumbnail manager used to store images.
- protected LocalRepository(DbContext database, IThumbnailsManager thumbs)
- {
- Database = database;
- _thumbs = thumbs;
- }
+ public DatabaseContext Database => database;
///
public Type RepositoryType => typeof(T);
@@ -127,12 +103,6 @@ public abstract class LocalRepository : IRepository
return query;
}
- ///
- /// Get a resource from it's ID and make the instance track it.
- ///
- /// The ID of the resource
- /// If the item is not found
- /// The tracked resource with the given ID
protected virtual async Task GetWithTracking(Guid id)
{
T? ret = await Database.Set().AsTracking().FirstOrDefaultAsync(x => x.Id == id);
@@ -174,11 +144,6 @@ public abstract class LocalRepository : IRepository
return ret;
}
- protected virtual Task GetDuplicated(T item)
- {
- return GetOrDefault(item.Slug);
- }
-
///
public virtual Task GetOrDefault(Guid id, Include? include = default)
{
@@ -303,26 +268,9 @@ public abstract class LocalRepository : IRepository
public virtual async Task Create(T obj)
{
await Validate(obj);
- if (obj is IThumbnails thumbs)
- {
- try
- {
- await _thumbs.DownloadImages(thumbs);
- }
- catch (DuplicatedItemException e) when (e.Existing is null)
- {
- throw new DuplicatedItemException(await GetDuplicated(obj));
- }
- if (thumbs.Poster != null)
- Database.Entry(thumbs).Reference(x => x.Poster).TargetEntry!.State =
- EntityState.Added;
- if (thumbs.Thumbnail != null)
- Database.Entry(thumbs).Reference(x => x.Thumbnail).TargetEntry!.State =
- EntityState.Added;
- if (thumbs.Logo != null)
- Database.Entry(thumbs).Reference(x => x.Logo).TargetEntry!.State =
- EntityState.Added;
- }
+ Database.Entry(obj).State = EntityState.Added;
+ await Database.SaveChangesAsync(() => Get(obj.Slug));
+ await IRepository.OnResourceCreated(obj);
return obj;
}
@@ -346,27 +294,11 @@ public abstract class LocalRepository : IRepository
///
public virtual async Task Edit(T edited)
{
- bool lazyLoading = Database.ChangeTracker.LazyLoadingEnabled;
- Database.ChangeTracker.LazyLoadingEnabled = false;
- try
- {
- T old = await GetWithTracking(edited.Id);
-
- Merger.Complete(
- old,
- edited,
- x => x.GetCustomAttribute() == null
- );
- await EditRelations(old, edited);
- await Database.SaveChangesAsync();
- await IRepository.OnResourceEdited(old);
- return old;
- }
- finally
- {
- Database.ChangeTracker.LazyLoadingEnabled = lazyLoading;
- Database.ChangeTracker.Clear();
- }
+ await Validate(edited);
+ Database.Entry(edited).State = EntityState.Modified;
+ await Database.SaveChangesAsync();
+ await IRepository.OnResourceEdited(edited);
+ return edited;
}
///
@@ -391,39 +323,9 @@ public abstract class LocalRepository : IRepository
}
}
- ///
- /// An overridable method to edit relation of a resource.
- ///
- ///
- /// The non edited resource
- ///
- ///
- /// The new version of .
- /// This item will be saved on the database and replace
- ///
- /// A representing the asynchronous operation.
- protected virtual Task EditRelations(T resource, T changed)
- {
- if (resource is IThumbnails thumbs && changed is IThumbnails chng)
- {
- Database.Entry(thumbs).Reference(x => x.Poster).IsModified =
- thumbs.Poster != chng.Poster;
- Database.Entry(thumbs).Reference(x => x.Thumbnail).IsModified =
- thumbs.Thumbnail != chng.Thumbnail;
- Database.Entry(thumbs).Reference(x => x.Logo).IsModified = thumbs.Logo != chng.Logo;
- }
- return Validate(resource);
- }
-
- ///
- /// A method called just before saving a new resource to the database.
- /// It is also called on the default implementation of
- ///
- /// The resource that will be saved
///
/// You can throw this if the resource is illegal and should not be saved.
///
- /// A representing the asynchronous operation.
protected virtual Task Validate(T resource)
{
if (
@@ -433,25 +335,8 @@ public abstract class LocalRepository : IRepository
return Task.CompletedTask;
if (string.IsNullOrEmpty(resource.Slug))
throw new ArgumentException("Resource can't have null as a slug.");
- if (int.TryParse(resource.Slug, out int _) || resource.Slug == "random")
- {
- try
- {
- MethodInfo? setter = typeof(T).GetProperty(nameof(resource.Slug))!.GetSetMethod();
- if (setter != null)
- setter.Invoke(resource, new object[] { resource.Slug + '!' });
- else
- throw new ArgumentException(
- "Resources slug can't be number only or the literal \"random\"."
- );
- }
- catch
- {
- throw new ArgumentException(
- "Resources slug can't be number only or the literal \"random\"."
- );
- }
- }
+ if (resource.Slug == "random")
+ throw new ArgumentException("Resources slug can't be the literal \"random\".");
return Task.CompletedTask;
}
@@ -470,18 +355,20 @@ public abstract class LocalRepository : IRepository
}
///
- public virtual Task Delete(T obj)
+ public virtual async Task Delete(T obj)
{
- IRepository.OnResourceDeleted(obj);
- if (obj is IThumbnails thumbs)
- return _thumbs.DeleteImages(thumbs);
- return Task.CompletedTask;
+ await Database.Set().Where(x => x.Id == obj.Id).ExecuteDeleteAsync();
+ await IRepository.OnResourceDeleted(obj);
}
///
- public async Task DeleteAll(Filter filter)
+ public virtual async Task DeleteAll(Filter filter)
{
- foreach (T resource in await GetAll(filter))
- await Delete(resource);
+ ICollection items = await GetAll(filter);
+ Guid[] ids = items.Select(x => x.Id).ToArray();
+ await Database.Set().Where(x => ids.Contains(x.Id)).ExecuteDeleteAsync();
+
+ foreach (T resource in items)
+ await IRepository.OnResourceDeleted(resource);
}
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/MovieRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/MovieRepository.cs
index 602f8e8a..d9821252 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/MovieRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/MovieRepository.cs
@@ -27,82 +27,29 @@ using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers;
-///
-/// A local repository to handle shows
-///
-public class MovieRepository : LocalRepository
+public class MovieRepository(DatabaseContext database, IRepository studios)
+ : LocalRepository(database)
{
- ///
- /// The database handle
- ///
- private readonly DatabaseContext _database;
-
- ///
- /// A studio repository to handle creation/validation of related studios.
- ///
- private readonly IRepository _studios;
-
- public MovieRepository(
- DatabaseContext database,
- IRepository studios,
- IThumbnailsManager thumbs
- )
- : base(database, thumbs)
- {
- _database = database;
- _studios = studios;
- }
-
///
public override async Task> Search(
string query,
Include? include = default
)
{
- return await AddIncludes(_database.Movies, include)
+ return await AddIncludes(Database.Movies, include)
.Where(x => EF.Functions.ILike(x.Name + " " + x.Slug, $"%{query}%"))
.Take(20)
.ToListAsync();
}
- ///
- public override async Task Create(Movie obj)
- {
- await base.Create(obj);
- _database.Entry(obj).State = EntityState.Added;
- await _database.SaveChangesAsync(() => Get(obj.Slug));
- await IRepository.OnResourceCreated(obj);
- return obj;
- }
-
///
protected override async Task Validate(Movie resource)
{
await base.Validate(resource);
if (resource.Studio != null)
{
- resource.Studio = await _studios.CreateIfNotExists(resource.Studio);
+ resource.Studio = await studios.CreateIfNotExists(resource.Studio);
resource.StudioId = resource.Studio.Id;
}
}
-
- ///
- protected override async Task EditRelations(Movie resource, Movie changed)
- {
- await Validate(changed);
-
- if (changed.Studio != null || changed.StudioId == null)
- {
- await Database.Entry(resource).Reference(x => x.Studio).LoadAsync();
- resource.Studio = changed.Studio;
- }
- }
-
- ///
- public override async Task Delete(Movie obj)
- {
- _database.Remove(obj);
- await _database.SaveChangesAsync();
- await base.Delete(obj);
- }
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs
index 18f53e96..5a31a21a 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs
@@ -31,16 +31,8 @@ using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Core.Controllers;
-///
-/// A local repository to handle seasons.
-///
-public class SeasonRepository : LocalRepository
+public class SeasonRepository(DatabaseContext database) : LocalRepository(database)
{
- ///
- /// The database handle
- ///
- private readonly DatabaseContext _database;
-
static SeasonRepository()
{
// Edit seasons slugs when the show's slug changes.
@@ -61,31 +53,13 @@ public class SeasonRepository : LocalRepository
};
}
- ///
- /// Create a new .
- ///
- /// The database handle that will be used
- /// The thumbnail manager used to store images.
- public SeasonRepository(DatabaseContext database, IThumbnailsManager thumbs)
- : base(database, thumbs)
- {
- _database = database;
- }
-
- protected override Task GetDuplicated(Season item)
- {
- return _database.Seasons.FirstOrDefaultAsync(x =>
- x.ShowId == item.ShowId && x.SeasonNumber == item.SeasonNumber
- );
- }
-
///
public override async Task> Search(
string query,
Include? include = default
)
{
- return await AddIncludes(_database.Seasons, include)
+ return await AddIncludes(Database.Seasons, include)
.Where(x => EF.Functions.ILike(x.Name!, $"%{query}%"))
.Take(20)
.ToListAsync();
@@ -94,14 +68,11 @@ public class SeasonRepository : LocalRepository
///
public override async Task Create(Season obj)
{
- await base.Create(obj);
+ // Set it for the OnResourceCreated event and the return value.
obj.ShowSlug =
- (await _database.Shows.FirstOrDefaultAsync(x => x.Id == obj.ShowId))?.Slug
+ (await Database.Shows.FirstOrDefaultAsync(x => x.Id == obj.ShowId))?.Slug
?? throw new ItemNotFoundException($"No show found with ID {obj.ShowId}");
- _database.Entry(obj).State = EntityState.Added;
- await _database.SaveChangesAsync(() => GetDuplicated(obj));
- await IRepository.OnResourceCreated(obj);
- return obj;
+ return await base.Create(obj);
}
///
@@ -120,12 +91,4 @@ public class SeasonRepository : LocalRepository
resource.ShowId = resource.Show.Id;
}
}
-
- ///
- public override async Task Delete(Season obj)
- {
- _database.Remove(obj);
- await _database.SaveChangesAsync();
- await base.Delete(obj);
- }
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/ShowRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/ShowRepository.cs
index 2253da0f..79f826aa 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/ShowRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/ShowRepository.cs
@@ -23,87 +23,33 @@ using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Utils;
using Kyoo.Postgresql;
-using Kyoo.Utils;
using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers;
-///
-/// A local repository to handle shows
-///
-public class ShowRepository : LocalRepository
+public class ShowRepository(DatabaseContext database, IRepository studios)
+ : LocalRepository(database)
{
- ///
- /// The database handle
- ///
- private readonly DatabaseContext _database;
-
- ///
- /// A studio repository to handle creation/validation of related studios.
- ///
- private readonly IRepository _studios;
-
- public ShowRepository(
- DatabaseContext database,
- IRepository studios,
- IThumbnailsManager thumbs
- )
- : base(database, thumbs)
- {
- _database = database;
- _studios = studios;
- }
-
///
public override async Task> Search(
string query,
Include? include = default
)
{
- return await AddIncludes(_database.Shows, include)
+ return await AddIncludes(Database.Shows, include)
.Where(x => EF.Functions.ILike(x.Name + " " + x.Slug, $"%{query}%"))
.Take(20)
.ToListAsync();
}
- ///
- public override async Task Create(Show obj)
- {
- await base.Create(obj);
- _database.Entry(obj).State = EntityState.Added;
- await _database.SaveChangesAsync(() => Get(obj.Slug));
- await IRepository.OnResourceCreated(obj);
- return obj;
- }
-
///
protected override async Task Validate(Show resource)
{
await base.Validate(resource);
if (resource.Studio != null)
{
- resource.Studio = await _studios.CreateIfNotExists(resource.Studio);
+ resource.Studio = await studios.CreateIfNotExists(resource.Studio);
resource.StudioId = resource.Studio.Id;
}
}
-
- ///
- protected override async Task EditRelations(Show resource, Show changed)
- {
- await Validate(changed);
-
- if (changed.Studio != null || changed.StudioId == null)
- {
- await Database.Entry(resource).Reference(x => x.Studio).LoadAsync();
- resource.Studio = changed.Studio;
- }
- }
-
- ///
- public override async Task Delete(Show obj)
- {
- _database.Remove(obj);
- await _database.SaveChangesAsync();
- await base.Delete(obj);
- }
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/StudioRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/StudioRepository.cs
index 7cdc1358..250a5a74 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/StudioRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/StudioRepository.cs
@@ -19,11 +19,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Utils;
using Kyoo.Postgresql;
-using Kyoo.Utils;
using Microsoft.EntityFrameworkCore;
namespace Kyoo.Core.Controllers;
@@ -31,51 +29,17 @@ namespace Kyoo.Core.Controllers;
///
/// A local repository to handle studios
///
-public class StudioRepository : LocalRepository
+public class StudioRepository(DatabaseContext database) : LocalRepository(database)
{
- ///
- /// The database handle
- ///
- private readonly DatabaseContext _database;
-
- ///
- /// Create a new .
- ///
- /// The database handle
- /// The thumbnail manager used to store images.
- public StudioRepository(DatabaseContext database, IThumbnailsManager thumbs)
- : base(database, thumbs)
- {
- _database = database;
- }
-
///
public override async Task> Search(
string query,
Include? include = default
)
{
- return await AddIncludes(_database.Studios, include)
+ return await AddIncludes(Database.Studios, include)
.Where(x => EF.Functions.ILike(x.Name, $"%{query}%"))
.Take(20)
.ToListAsync();
}
-
- ///
- public override async Task Create(Studio obj)
- {
- await base.Create(obj);
- _database.Entry(obj).State = EntityState.Added;
- await _database.SaveChangesAsync(() => Get(obj.Slug));
- await IRepository.OnResourceCreated(obj);
- return obj;
- }
-
- ///
- public override async Task Delete(Studio obj)
- {
- _database.Entry(obj).State = EntityState.Deleted;
- await _database.SaveChangesAsync();
- await base.Delete(obj);
- }
}
diff --git a/back/src/Kyoo.Core/Controllers/Repositories/UserRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/UserRepository.cs
index e4a62db9..81a2c188 100644
--- a/back/src/Kyoo.Core/Controllers/Repositories/UserRepository.cs
+++ b/back/src/Kyoo.Core/Controllers/Repositories/UserRepository.cs
@@ -40,9 +40,8 @@ public class UserRepository(
DatabaseContext database,
DbConnection db,
SqlVariableContext context,
- IThumbnailsManager thumbs,
PermissionOption options
-) : LocalRepository(database, thumbs), IUserRepository
+) : LocalRepository(database), IUserRepository
{
///
public override async Task> Search(
@@ -50,7 +49,7 @@ public class UserRepository(
Include? include = default
)
{
- return await AddIncludes(database.Users, include)
+ return await AddIncludes(Database.Users, include)
.Where(x => EF.Functions.ILike(x.Username, $"%{query}%"))
.Take(20)
.ToListAsync();
@@ -60,26 +59,14 @@ public class UserRepository(
public override async Task Create(User obj)
{
// If no users exists, the new one will be an admin. Give it every permissions.
- if (!await database.Users.AnyAsync())
+ if (!await Database.Users.AnyAsync())
obj.Permissions = PermissionOption.Admin;
else if (!options.RequireVerification)
obj.Permissions = options.NewUser;
else
obj.Permissions = Array.Empty();
- await base.Create(obj);
- database.Entry(obj).State = EntityState.Added;
- await database.SaveChangesAsync(() => Get(obj.Slug));
- await IRepository.OnResourceCreated(obj);
- return obj;
- }
-
- ///
- public override async Task Delete(User obj)
- {
- database.Entry(obj).State = EntityState.Deleted;
- await database.SaveChangesAsync();
- await base.Delete(obj);
+ return await base.Create(obj);
}
public Task GetByExternalId(string provider, string id)
@@ -109,8 +96,8 @@ public class UserRepository(
User user = await GetWithTracking(userId);
user.ExternalId[provider] = token;
// without that, the change tracker does not find the modification. /shrug
- database.Entry(user).Property(x => x.ExternalId).IsModified = true;
- await database.SaveChangesAsync();
+ Database.Entry(user).Property(x => x.ExternalId).IsModified = true;
+ await Database.SaveChangesAsync();
return user;
}
@@ -119,8 +106,8 @@ public class UserRepository(
User user = await GetWithTracking(userId);
user.ExternalId.Remove(provider);
// without that, the change tracker does not find the modification. /shrug
- database.Entry(user).Property(x => x.ExternalId).IsModified = true;
- await database.SaveChangesAsync();
+ Database.Entry(user).Property(x => x.ExternalId).IsModified = true;
+ await Database.SaveChangesAsync();
return user;
}
}
diff --git a/back/src/Kyoo.Core/Extensions/ServiceExtensions.cs b/back/src/Kyoo.Core/Extensions/ServiceExtensions.cs
index 2c92fb56..9bed18bf 100644
--- a/back/src/Kyoo.Core/Extensions/ServiceExtensions.cs
+++ b/back/src/Kyoo.Core/Extensions/ServiceExtensions.cs
@@ -16,9 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
-using System;
using System.Linq;
-using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;
using AspNetCore.Proxy;
diff --git a/back/src/Kyoo.Meilisearch/MeilisearchModule.cs b/back/src/Kyoo.Meilisearch/MeilisearchModule.cs
index bc09420e..f2e971b4 100644
--- a/back/src/Kyoo.Meilisearch/MeilisearchModule.cs
+++ b/back/src/Kyoo.Meilisearch/MeilisearchModule.cs
@@ -16,9 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with Kyoo. If not, see .
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Meilisearch;