mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Replaces ErrorOr library with a custom implementation.
This commit is contained in:
1 parent
8fe90a4dde
commit
3b772d68ca
436 files changed
+4234
-3922
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
@@ -35,8 +35,8 @@ internal sealed class PermissionRepository : IPermissionRepository
|
||||
/// </summary>
|
||||
/// <param name="permission">The authorization permission to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(PermissionEntity permission, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertAsync(PermissionEntity permission, CancellationToken cancellationToken)
|
||||
{
|
||||
bool permissionExists = await _luminaDbContext.Permissions.AnyAsync(repositoryPermission => repositoryPermission.Id == permission.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (permissionExists)
|
||||
@@ -50,8 +50,8 @@ internal sealed class PermissionRepository : IPermissionRepository
|
||||
/// Gets all autorization permissions.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="PermissionEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<PermissionEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="PermissionEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<PermissionEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Permissions.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -61,8 +61,8 @@ internal sealed class PermissionRepository : IPermissionRepository
|
||||
/// </summary>
|
||||
/// <param name="ids">The list of Ids of the permissions to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="PermissionEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<PermissionEntity>>> GetByIdsAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="PermissionEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<PermissionEntity>>> GetByIdsAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Permissions.Where(permission => ids.Contains(permission.Id)).ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -30,10 +30,10 @@ internal sealed class RolePermissionRepository : IRolePermissionRepository
|
||||
/// </summary>
|
||||
/// <param name="rolePermission">The authorization role permission to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<ErrorOr<Created>> InsertAsync(RolePermissionEntity rolePermission, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<Result<Created>> InsertAsync(RolePermissionEntity rolePermission, CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.RolePermissions.Add(rolePermission);
|
||||
return Task.FromResult(ErrorOrFactory.From(Result.Created));
|
||||
return Task.FromResult(Result.From(Result.Created));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
@@ -34,8 +34,8 @@ internal sealed class RoleRepository : IRoleRepository
|
||||
/// </summary>
|
||||
/// <param name="role">The authorization role to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(RoleEntity role, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertAsync(RoleEntity role, CancellationToken cancellationToken)
|
||||
{
|
||||
bool roleExists = await _luminaDbContext.Roles.AnyAsync(repositoryRole => repositoryRole.Id == role.Id || repositoryRole.RoleName == role.RoleName, cancellationToken).ConfigureAwait(false);
|
||||
if (roleExists)
|
||||
@@ -49,8 +49,8 @@ internal sealed class RoleRepository : IRoleRepository
|
||||
/// Gets all autorization roles.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="RoleEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<RoleEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="RoleEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<RoleEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Roles.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -60,8 +60,8 @@ internal sealed class RoleRepository : IRoleRepository
|
||||
/// </summary>
|
||||
/// <param name="roleType">The type of role to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="RoleEntity"/> if found, or an error.</returns>
|
||||
public async Task<ErrorOr<RoleEntity?>> GetByNameAsync(string roleType, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="RoleEntity"/> if found, or an error.</returns>
|
||||
public async Task<Result<RoleEntity?>> GetByNameAsync(string roleType, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Roles
|
||||
.Include(role => role.RolePermissions)
|
||||
@@ -75,8 +75,8 @@ internal sealed class RoleRepository : IRoleRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the authorization role to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="RoleEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<RoleEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="RoleEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<Result<RoleEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Roles
|
||||
.Include(role => role.RolePermissions)
|
||||
@@ -90,8 +90,8 @@ internal sealed class RoleRepository : IRoleRepository
|
||||
/// </summary>
|
||||
/// <param name="data">The role to update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateAsync(RoleEntity data, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateAsync(RoleEntity data, CancellationToken cancellationToken)
|
||||
{
|
||||
// check if a role with the requested Id exists, and retrieve it
|
||||
RoleEntity? foundRole = await _luminaDbContext.Roles
|
||||
@@ -114,8 +114,8 @@ internal sealed class RoleRepository : IRoleRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the role to be deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Deleted>> DeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Deleted>> DeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
// check if a role with the requested Id exists, and retrieve it
|
||||
RoleEntity? foundRole = await _luminaDbContext.Roles
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -30,10 +30,10 @@ internal sealed class UserRoleRepository : IUserRoleRepository
|
||||
/// </summary>
|
||||
/// <param name="userRole">The authorization user role to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<ErrorOr<Created>> InsertAsync(UserRoleEntity userRole, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<Result<Created>> InsertAsync(UserRoleEntity userRole, CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.UserRoles.Add(userRole);
|
||||
return Task.FromResult(ErrorOrFactory.From(Result.Created));
|
||||
return Task.FromResult(Result.From(Result.Created));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,8 +37,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// </summary>
|
||||
/// <param name="book">The book to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(BookEntity book, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertAsync(BookEntity book, CancellationToken cancellationToken)
|
||||
{
|
||||
bool bookExists = await _luminaDbContext.Books.AnyAsync(repositoryBook => repositoryBook.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (bookExists)
|
||||
@@ -66,8 +66,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the book to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="BookEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<BookEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="BookEntity"/>, or an error.</returns>
|
||||
public async Task<Result<BookEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books
|
||||
.Include(book => book.Tags)
|
||||
@@ -80,8 +80,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// Gets all books.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<BookEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<BookEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books
|
||||
.Include(book => book.Tags)
|
||||
@@ -95,8 +95,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<BookEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<BookEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books
|
||||
.Include(book => book.Tags)
|
||||
@@ -112,8 +112,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// <param name="libraryId">The Id of the media library whose book is retrieved.</param>
|
||||
/// <param name="path">The file system path of the book to be retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the <see cref="BookEntity"/> stored at the provided path, or an error.</returns>
|
||||
public async Task<ErrorOr<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="BookEntity"/> stored at the provided path, or an error.</returns>
|
||||
public async Task<Result<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books
|
||||
.Include(book => book.Tags)
|
||||
@@ -130,8 +130,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// <param name="lastPath">The path of the last retrieved book, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
|
||||
/// <param name="pageSize">The maximum number of books to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a page of books needing their metadata enriched, or an error.</returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<BookEntity>>> GetBooksNeedingMetadataAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a page of books needing their metadata enriched, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<BookEntity>>> GetBooksNeedingMetadataAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books
|
||||
.Include(book => book.Tags)
|
||||
@@ -150,8 +150,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are counted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the number of books needing their metadata enriched, or an error.</returns>
|
||||
public async Task<ErrorOr<int>> GetBooksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the number of books needing their metadata enriched, or an error.</returns>
|
||||
public async Task<Result<int>> GetBooksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books
|
||||
.CountAsync(book => book.LibraryId == libraryId && book.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false);
|
||||
@@ -162,8 +162,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// </summary>
|
||||
/// <param name="data">The book to update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateAsync(BookEntity data, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateAsync(BookEntity data, CancellationToken cancellationToken)
|
||||
{
|
||||
BookEntity? foundBook = await _luminaDbContext.Books
|
||||
.Include(book => book.Tags)
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Dapper;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -39,8 +39,8 @@ internal sealed class DirectoryScanFingerprintRepository : IDirectoryScanFingerp
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The unique identifier of the library for which to get the directory scan fingerprints.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a path mapped dictionary of directory scan fingerprints, or an error.</returns>
|
||||
public async Task<ErrorOr<Dictionary<string, DirectoryScanFingerprintEntity>>> GetMappedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a path mapped dictionary of directory scan fingerprints, or an error.</returns>
|
||||
public async Task<Result<Dictionary<string, DirectoryScanFingerprintEntity>>> GetMappedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
const string GET_FINGERPRINTS_SQL = """
|
||||
@@ -60,8 +60,8 @@ internal sealed class DirectoryScanFingerprintRepository : IDirectoryScanFingerp
|
||||
/// </summary>
|
||||
/// <param name="entities">The directory scan fingerprints to insert or update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpsertRangeAsync(IReadOnlyCollection<DirectoryScanFingerprintEntity> entities, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpsertRangeAsync(IReadOnlyCollection<DirectoryScanFingerprintEntity> entities, CancellationToken cancellationToken)
|
||||
{
|
||||
// nothing to upsert for an empty collection
|
||||
if (entities.Count == 0)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -35,8 +35,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// </summary>
|
||||
/// <param name="library">The library to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(LibraryEntity library, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertAsync(LibraryEntity library, CancellationToken cancellationToken)
|
||||
{
|
||||
bool libraryExists = await _luminaDbContext.Libraries.AnyAsync(repositoryLibrary => repositoryLibrary.Id == library.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (libraryExists)
|
||||
@@ -51,8 +51,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the library to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="LibraryEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<LibraryEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="LibraryEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<Result<LibraryEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Libraries
|
||||
.Include(library => library.ContentLocations)
|
||||
@@ -63,8 +63,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// Gets all media libraries that are marked as enabled, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryEntity>>> GetAllEnabledAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<LibraryEntity>>> GetAllEnabledAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Libraries
|
||||
.Include(library => library.ContentLocations)
|
||||
@@ -76,8 +76,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// Gets all media libraries that are marked as enabled and unlocked, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryEntity>>> GetAllEnabledAndUnlockedAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<LibraryEntity>>> GetAllEnabledAndUnlockedAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Libraries
|
||||
.Include(library => library.ContentLocations)
|
||||
@@ -89,8 +89,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// Gets all media libraries.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<LibraryEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Libraries
|
||||
.Include(library => library.ContentLocations)
|
||||
@@ -102,8 +102,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// </summary>
|
||||
/// <param name="data">The media library to update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateAsync(LibraryEntity data, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateAsync(LibraryEntity data, CancellationToken cancellationToken)
|
||||
{
|
||||
LibraryEntity? foundLibrary = await _luminaDbContext.Libraries
|
||||
.Include(library => library.ContentLocations)
|
||||
@@ -124,8 +124,8 @@ internal sealed class LibraryRepository : ILibraryRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the library to delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Deleted>> DeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Deleted>> DeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
LibraryEntity? library = await _luminaDbContext.Libraries
|
||||
.Include(library => library.ContentLocations)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -36,8 +36,8 @@ internal sealed class LibraryScanRepository : ILibraryScanRepository
|
||||
/// </summary>
|
||||
/// <param name="libraryScan">The library scan to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(LibraryScanEntity libraryScan, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertAsync(LibraryScanEntity libraryScan, CancellationToken cancellationToken)
|
||||
{
|
||||
bool libraryScanExists = await _luminaDbContext.LibraryScans.AnyAsync(
|
||||
repositoryScanLibrary => repositoryScanLibrary.Id == libraryScan.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
@@ -53,8 +53,8 @@ internal sealed class LibraryScanRepository : ILibraryScanRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the library scan to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="LibraryScanEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<LibraryScanEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="LibraryScanEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<Result<LibraryScanEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScans
|
||||
.Include(libraryScan => libraryScan.Library)
|
||||
@@ -66,8 +66,8 @@ internal sealed class LibraryScanRepository : ILibraryScanRepository
|
||||
/// Gets the media library scans that belong to a media library identified by <paramref name="libraryId"/>, for the previous month, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryScanEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryScanEntity>>> GetPastMonthScansByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryScanEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<LibraryScanEntity>>> GetPastMonthScansByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScans
|
||||
.Include(library => library.Library)
|
||||
@@ -79,8 +79,8 @@ internal sealed class LibraryScanRepository : ILibraryScanRepository
|
||||
/// Gets the media library scans that have a <see cref="LibraryScanJobStatus.Running"/> status, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryScanEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryScanEntity>>> GetRunningScansAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryScanEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<LibraryScanEntity>>> GetRunningScansAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScans
|
||||
.Include(library => library.Library)
|
||||
@@ -93,8 +93,8 @@ internal sealed class LibraryScanRepository : ILibraryScanRepository
|
||||
/// </summary>
|
||||
/// <param name="data">The media library scan to update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateAsync(LibraryScanEntity data, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateAsync(LibraryScanEntity data, CancellationToken cancellationToken)
|
||||
{
|
||||
LibraryScanEntity? foundLibraryScan = await _luminaDbContext.LibraryScans
|
||||
.Include(libraryScan => libraryScan.Library)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -30,10 +30,10 @@ internal sealed class LibraryScanResultRepository : ILibraryScanResultRepository
|
||||
/// </summary>
|
||||
/// <param name="libraryScan">The library scan result to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<ErrorOr<Created>> InsertAsync(LibraryScanResultEntity libraryScan, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<Result<Created>> InsertAsync(LibraryScanResultEntity libraryScan, CancellationToken cancellationToken)
|
||||
{
|
||||
_luminaDbContext.LibraryScanResults.Add(libraryScan);
|
||||
return Task.FromResult(ErrorOrFactory.From(Result.Created));
|
||||
return Task.FromResult(Result.From(Result.Created));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Dapper;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.Data.Sqlite;
|
||||
@@ -42,8 +42,8 @@ internal sealed class LibraryScanSnapshotRepository : ILibraryScanSnapshotReposi
|
||||
/// <param name="libraryId">The unique identifier of the library for which to get the deleted media library scan snapshot item paths.</param>
|
||||
/// <param name="scanId">The unique identifier of the media library scan for which to determine the deleted media library scan snapshot item paths.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of deleted media library scan snapshot item paths, or an error.</returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<string>>> GetDeletedPathsAsync(Guid libraryId, Guid scanId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of deleted media library scan snapshot item paths, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<string>>> GetDeletedPathsAsync(Guid libraryId, Guid scanId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
const string GET_DELETED_PATHS_SQL = """
|
||||
@@ -69,8 +69,8 @@ internal sealed class LibraryScanSnapshotRepository : ILibraryScanSnapshotReposi
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The unique identifier of the library whose media library scan snapshot item paths are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of media library scan snapshot item paths, or an error.</returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<string>>> GetPathsAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of media library scan snapshot item paths, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<string>>> GetPathsAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
const string GET_PATHS_SQL = """
|
||||
@@ -94,8 +94,8 @@ internal sealed class LibraryScanSnapshotRepository : ILibraryScanSnapshotReposi
|
||||
/// <param name="scanId">The unique identifier of the media library scan whose results are applied.</param>
|
||||
/// <param name="userId">The unique identifier of the user that initiated the media library scan, used for audit purposes.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> ApplySnapshotSwapAsync(Guid libraryId, Guid scanId, Guid userId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> ApplySnapshotSwapAsync(Guid libraryId, Guid scanId, Guid userId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
await using DbTransaction transaction = await connection.BeginTransactionAsync(cancellationToken);
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Dapper;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
|
||||
@@ -40,8 +40,8 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR
|
||||
/// </summary>
|
||||
/// <param name="entities">The media library scan staging results to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertRangeAsync(IReadOnlyCollection<LibraryScanStagingResultsEntity> entities, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertRangeAsync(IReadOnlyCollection<LibraryScanStagingResultsEntity> entities, CancellationToken cancellationToken)
|
||||
{
|
||||
// nothing to insert for an empty collection
|
||||
if (entities.Count == 0)
|
||||
@@ -69,8 +69,8 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR
|
||||
/// <param name="scanId">The unique identifier of the media library scan whose staging results are marked.</param>
|
||||
/// <param name="libraryId">The unique identifier of the library whose media library scan snapshot is compared against.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> MarkChangesAgainstSnapshotAsync(Guid scanId, Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> MarkChangesAgainstSnapshotAsync(Guid scanId, Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
// compare the discovered file system items against the media library scan snapshot of the previous scan, entirely in the database, so that the snapshot never needs to be loaded into memory:
|
||||
@@ -102,8 +102,8 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR
|
||||
/// </summary>
|
||||
/// <param name="scanId">The unique identifier of the media library scan whose staging results are counted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the number of staging results that need hashing, or an error.</returns>
|
||||
public async Task<ErrorOr<int>> GetFilesToHashCountAsync(Guid scanId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the number of staging results that need hashing, or an error.</returns>
|
||||
public async Task<Result<int>> GetFilesToHashCountAsync(Guid scanId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
const string GET_FILES_TO_HASH_COUNT_SQL = """
|
||||
@@ -125,8 +125,8 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR
|
||||
/// <param name="lastPath">The path of the last retrieved file system item, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
|
||||
/// <param name="pageSize">The maximum number of staging results to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a page of staging results that need hashing, or an error.</returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<HashedFileSystemFileDto>>> GetFilesToHashPageAsync(Guid scanId, string? lastPath, int pageSize, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a page of staging results that need hashing, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<HashedFileSystemFileDto>>> GetFilesToHashPageAsync(Guid scanId, string? lastPath, int pageSize, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
const string GET_FILES_TO_HASH_SQL = """
|
||||
@@ -151,8 +151,8 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR
|
||||
/// <param name="scanId">The unique identifier of the media library scan whose staging results are updated.</param>
|
||||
/// <param name="hashedFiles">The file system items whose content hashes are updated.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateFileHashesAsync(Guid scanId, IReadOnlyCollection<HashedFileSystemFileDto> hashedFiles, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateFileHashesAsync(Guid scanId, IReadOnlyCollection<HashedFileSystemFileDto> hashedFiles, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
await using DbTransaction transaction = await connection.BeginTransactionAsync(cancellationToken);
|
||||
@@ -179,8 +179,8 @@ internal sealed class LibraryScanStagingResultsRepository : ILibraryScanStagingR
|
||||
/// </summary>
|
||||
/// <param name="scanId">The unique identifier of the media library scan whose staging results are cleared.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Success>> ClearForScanAsync(Guid scanId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Success>> ClearForScanAsync(Guid scanId, CancellationToken cancellationToken)
|
||||
{
|
||||
await using SqliteConnection connection = await OpenConnectionAsync(cancellationToken).ConfigureAwait(false);
|
||||
const string CLEAR_SQL = "DELETE FROM LibraryScanStagingResults WHERE LibraryScanId = @scanId;";
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -34,8 +34,8 @@ internal sealed class LibraryMetadataProviderConfigurationRepository : ILibraryM
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose metadata provider configurations are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderConfigurationEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderConfigurationEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryMetadataProviderConfigurations
|
||||
.Where(configuration => configuration.LibraryId == libraryId)
|
||||
@@ -48,8 +48,8 @@ internal sealed class LibraryMetadataProviderConfigurationRepository : ILibraryM
|
||||
/// <param name="libraryId">The Id of the media library whose metadata provider configuration is retrieved.</param>
|
||||
/// <param name="pluginId">The Id of the plugin whose metadata provider configuration is retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the <see cref="LibraryMetadataProviderConfigurationEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<LibraryMetadataProviderConfigurationEntity?>> GetByLibraryAndPluginIdAsync(Guid libraryId, Guid pluginId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="LibraryMetadataProviderConfigurationEntity"/>, or an error.</returns>
|
||||
public async Task<Result<LibraryMetadataProviderConfigurationEntity?>> GetByLibraryAndPluginIdAsync(Guid libraryId, Guid pluginId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryMetadataProviderConfigurations
|
||||
.FirstOrDefaultAsync(configuration => configuration.LibraryId == libraryId && configuration.PluginId == pluginId, cancellationToken).ConfigureAwait(false);
|
||||
@@ -60,8 +60,8 @@ internal sealed class LibraryMetadataProviderConfigurationRepository : ILibraryM
|
||||
/// </summary>
|
||||
/// <param name="configuration">The metadata provider configuration to insert or update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpsertAsync(LibraryMetadataProviderConfigurationEntity configuration, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpsertAsync(LibraryMetadataProviderConfigurationEntity configuration, CancellationToken cancellationToken)
|
||||
{
|
||||
LibraryMetadataProviderConfigurationEntity? existingConfiguration = await _luminaDbContext.LibraryMetadataProviderConfigurations
|
||||
.FirstOrDefaultAsync(repositoryConfiguration => repositoryConfiguration.LibraryId == configuration.LibraryId && repositoryConfiguration.PluginId == configuration.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -34,8 +34,8 @@ internal sealed class PluginRepository : IPluginRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the plugin to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="PluginEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<PluginEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="PluginEntity"/>, or an error.</returns>
|
||||
public async Task<Result<PluginEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Plugins
|
||||
.FirstOrDefaultAsync(plugin => plugin.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
@@ -45,8 +45,8 @@ internal sealed class PluginRepository : IPluginRepository
|
||||
/// Gets all the detected plugins.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="PluginEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<PluginEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="PluginEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<PluginEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Plugins
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -57,8 +57,8 @@ internal sealed class PluginRepository : IPluginRepository
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin to insert or update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpsertAsync(PluginEntity plugin, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpsertAsync(PluginEntity plugin, CancellationToken cancellationToken)
|
||||
{
|
||||
PluginEntity? existingPlugin = await _luminaDbContext.Plugins
|
||||
.FirstOrDefaultAsync(repositoryPlugin => repositoryPlugin.Id == plugin.Id, cancellationToken).ConfigureAwait(false);
|
||||
@@ -83,8 +83,8 @@ internal sealed class PluginRepository : IPluginRepository
|
||||
/// <param name="pluginId">The Id of the plugin whose settings are updated.</param>
|
||||
/// <param name="settingsJson">The serialized settings of the plugin.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateSettingsAsync(Guid pluginId, string? settingsJson, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateSettingsAsync(Guid pluginId, string? settingsJson, CancellationToken cancellationToken)
|
||||
{
|
||||
PluginEntity? existingPlugin = await _luminaDbContext.Plugins
|
||||
.FirstOrDefaultAsync(repositoryPlugin => repositoryPlugin.Id == pluginId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -35,8 +35,8 @@ internal sealed class UserRepository : IUserRepository
|
||||
/// </summary>
|
||||
/// <param name="user">The user to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(UserEntity user, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> InsertAsync(UserEntity user, CancellationToken cancellationToken)
|
||||
{
|
||||
bool userExists = await _luminaDbContext.Users.AnyAsync(repositoryUser => repositoryUser.Id == user.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (userExists)
|
||||
@@ -50,8 +50,8 @@ internal sealed class UserRepository : IUserRepository
|
||||
/// Gets all users.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="UserEntity"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<UserEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="UserEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IEnumerable<UserEntity>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Users.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
@@ -61,8 +61,8 @@ internal sealed class UserRepository : IUserRepository
|
||||
/// </summary>
|
||||
/// <param name="username">The username of the user to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="UserEntity"/> if found, or an error.</returns>
|
||||
public async Task<ErrorOr<UserEntity?>> GetByUsernameAsync(string username, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="UserEntity"/> if found, or an error.</returns>
|
||||
public async Task<Result<UserEntity?>> GetByUsernameAsync(string username, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Users
|
||||
.Include(user => user.Libraries)
|
||||
@@ -80,8 +80,8 @@ internal sealed class UserRepository : IUserRepository
|
||||
/// </summary>
|
||||
/// <param name="data">Ther user to update.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Updated>> UpdateAsync(UserEntity data, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> UpdateAsync(UserEntity data, CancellationToken cancellationToken)
|
||||
{
|
||||
UserEntity? foundUser = await _luminaDbContext.Users
|
||||
.Include(user => user.Libraries)
|
||||
@@ -135,8 +135,8 @@ internal sealed class UserRepository : IUserRepository
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the user to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="UserEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<UserEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="UserEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<Result<UserEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Users
|
||||
.Include(user => user.Libraries)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
@@ -41,8 +41,8 @@ public class DataSeedService : IDataSeedService
|
||||
/// </summary>
|
||||
/// <param name="adminId">The unique identifier of the admin admin user who will own these permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken)
|
||||
{
|
||||
IPermissionRepository permissionRepository = _unitOfWork.GetRepository<IPermissionRepository>();
|
||||
// create the default authorization permissions and add them to the repository.
|
||||
@@ -55,8 +55,8 @@ public class DataSeedService : IDataSeedService
|
||||
];
|
||||
foreach (PermissionEntity permission in defaultPermissions)
|
||||
{
|
||||
ErrorOr<Created> insertPermissionResult = await permissionRepository.InsertAsync(permission, cancellationToken).ConfigureAwait(false);
|
||||
if (insertPermissionResult.IsError)
|
||||
Result<Created> insertPermissionResult = await permissionRepository.InsertAsync(permission, cancellationToken).ConfigureAwait(false);
|
||||
if (insertPermissionResult.IsFailure)
|
||||
return insertPermissionResult.Errors;
|
||||
}
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -68,8 +68,8 @@ public class DataSeedService : IDataSeedService
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user for whom roles will be set.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken)
|
||||
{
|
||||
IRoleRepository roleRepository = _unitOfWork.GetRepository<IRoleRepository>();
|
||||
|
||||
@@ -80,8 +80,8 @@ public class DataSeedService : IDataSeedService
|
||||
];
|
||||
foreach (RoleEntity role in defaultRoles)
|
||||
{
|
||||
ErrorOr<Created> insertRoleResult = await roleRepository.InsertAsync(role, cancellationToken).ConfigureAwait(false);
|
||||
if (insertRoleResult.IsError)
|
||||
Result<Created> insertRoleResult = await roleRepository.InsertAsync(role, cancellationToken).ConfigureAwait(false);
|
||||
if (insertRoleResult.IsFailure)
|
||||
return insertRoleResult.Errors;
|
||||
}
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -93,24 +93,24 @@ public class DataSeedService : IDataSeedService
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user to receive admin role permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken)
|
||||
{
|
||||
IRolePermissionRepository rolePermissionRepository = _unitOfWork.GetRepository<IRolePermissionRepository>();
|
||||
IRoleRepository roleRepository = _unitOfWork.GetRepository<IRoleRepository>();
|
||||
IPermissionRepository permissionRepository = _unitOfWork.GetRepository<IPermissionRepository>();
|
||||
|
||||
// get the admin role
|
||||
ErrorOr<RoleEntity?> getAdminRoleResult = await roleRepository.GetByNameAsync("Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (getAdminRoleResult.IsError)
|
||||
Result<RoleEntity?> getAdminRoleResult = await roleRepository.GetByNameAsync("Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (getAdminRoleResult.IsFailure)
|
||||
return getAdminRoleResult.Errors;
|
||||
|
||||
if (getAdminRoleResult.Value is null)
|
||||
return Errors.Authorization.AdminAccountNotFound;
|
||||
|
||||
// get all permissions
|
||||
ErrorOr<IEnumerable<PermissionEntity>> getPermissionsResult = await permissionRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getPermissionsResult.IsError)
|
||||
Result<IEnumerable<PermissionEntity>> getPermissionsResult = await permissionRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getPermissionsResult.IsFailure)
|
||||
return getPermissionsResult.Errors;
|
||||
|
||||
// add each permission to the admin role
|
||||
@@ -125,8 +125,8 @@ public class DataSeedService : IDataSeedService
|
||||
CreatedBy = userId,
|
||||
CreatedOnUtc = _dateTimeProvider.UtcNow
|
||||
};
|
||||
ErrorOr<Created> insertRolePermissionResult = await rolePermissionRepository.InsertAsync(rolePermissionEntity, cancellationToken).ConfigureAwait(false);
|
||||
if (insertRolePermissionResult.IsError)
|
||||
Result<Created> insertRolePermissionResult = await rolePermissionRepository.InsertAsync(rolePermissionEntity, cancellationToken).ConfigureAwait(false);
|
||||
if (insertRolePermissionResult.IsFailure)
|
||||
return insertRolePermissionResult.Errors;
|
||||
}
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -138,8 +138,8 @@ public class DataSeedService : IDataSeedService
|
||||
/// </summary>
|
||||
/// <param name="userId">The unique identifier of the admin user to receive the admin role.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken)
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken)
|
||||
{
|
||||
IUserRoleRepository userRoleRepository = _unitOfWork.GetRepository<IUserRoleRepository>();
|
||||
IRoleRepository roleRepository = _unitOfWork.GetRepository<IRoleRepository>();
|
||||
@@ -147,16 +147,16 @@ public class DataSeedService : IDataSeedService
|
||||
|
||||
|
||||
// get the admin role
|
||||
ErrorOr<RoleEntity?> getAdminRoleResult = await roleRepository.GetByNameAsync("Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (getAdminRoleResult.IsError)
|
||||
Result<RoleEntity?> getAdminRoleResult = await roleRepository.GetByNameAsync("Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (getAdminRoleResult.IsFailure)
|
||||
return getAdminRoleResult.Errors;
|
||||
|
||||
if (getAdminRoleResult.Value is null)
|
||||
return Errors.Authorization.AdminRoleNotFound;
|
||||
|
||||
// get admin user
|
||||
ErrorOr<UserEntity?> getUserResult = await userRepository.GetByIdAsync(userId, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await userRepository.GetByIdAsync(userId, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
|
||||
if (getUserResult.Value is null)
|
||||
@@ -172,8 +172,8 @@ public class DataSeedService : IDataSeedService
|
||||
User = getUserResult.Value,
|
||||
UserId = getUserResult.Value.Id
|
||||
};
|
||||
ErrorOr<Created> insertUserRoleResult = await userRoleRepository.InsertAsync(userRole, cancellationToken).ConfigureAwait(false);
|
||||
if (insertUserRoleResult.IsError)
|
||||
Result<Created> insertUserRoleResult = await userRoleRepository.InsertAsync(userRole, cancellationToken).ConfigureAwait(false);
|
||||
if (insertUserRoleResult.IsFailure)
|
||||
return insertUserRoleResult.Errors;
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Reference in new issue
Block a user