Replaces ErrorOr library with a custom implementation.

This commit is contained in:
BinaryAlley committed 2026-08-14 03:04:28 -07:00
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.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -23,6 +23,6 @@ public interface IPermissionRepository : IRepository<PermissionEntity>,
/// </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>
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>
Task<Result<IEnumerable<PermissionEntity>>> GetByIdsAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken);
}
@@ -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.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -25,6 +25,6 @@ public interface IRoleRepository : IRepository<RoleEntity>,
/// </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>
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>
Task<Result<RoleEntity?>> GetByNameAsync(string roleType, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
@@ -25,8 +25,8 @@ public interface IBookRepository : IRepository<BookEntity>,
/// </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>
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>
Task<Result<IEnumerable<BookEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets the book of the media library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
@@ -34,8 +34,8 @@ public interface IBookRepository : IRepository<BookEntity>,
/// <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>
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>
Task<Result<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
/// <summary>
/// Gets a page of the books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet,
@@ -45,14 +45,14 @@ public interface IBookRepository : IRepository<BookEntity>,
/// <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>
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>
Task<Result<IReadOnlyList<BookEntity>>> GetBooksNeedingMetadataAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet.
/// </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>
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>
Task<Result<int>> GetBooksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System.Threading.Tasks;
#endregion
@@ -13,6 +13,6 @@ public interface IDeleteAllRepositoryAction
/// <summary>
/// Deletes all entities from the storage medium.
/// </summary>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
Task<ErrorOr<Deleted>> DeleteAllAsync();
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Deleted>> DeleteAllAsync();
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -17,6 +17,6 @@ public interface IDeleteByIdRepositoryAction<TId> where TId : notnull
/// </summary>
/// <param name="id">The id of the element 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>
Task<ErrorOr<Deleted>> DeleteByIdAsync(TId id, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Deleted>> DeleteByIdAsync(TId id, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Collections.Generic;
using System.Threading;
@@ -18,6 +18,6 @@ public interface IGetAllRepositoryAction<TModel> where TModel : IStorageEntity
/// Gets all data of type <typeparamref name="TModel"/> 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 <typeparamref name="TModel"/>, or an error.</returns>
Task<ErrorOr<IEnumerable<TModel>>> GetAllAsync(CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <typeparamref name="TModel"/>, or an error.</returns>
Task<Result<IEnumerable<TModel>>> GetAllAsync(CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
@@ -20,6 +20,6 @@ public interface IGetByIdRepositoryAction<TModel, TId> where TModel : IStorageEn
/// </summary>
/// <param name="id">The id of the element 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 <typeparamref name="TModel"/> identified by <paramref name="id"/>, or an error.</returns>
Task<ErrorOr<TModel?>> GetByIdAsync(TId id, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> containing either a <typeparamref name="TModel"/> identified by <paramref name="id"/>, or an error.</returns>
Task<Result<TModel?>> GetByIdAsync(TId id, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Collections.Generic;
using System.Threading;
@@ -19,6 +19,6 @@ public interface IInsertRangeRepositoryAction<TModel> where TModel : IStorageEnt
/// </summary>
/// <param name="entities">The elements to be saved.</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>
Task<ErrorOr<Created>> InsertRangeAsync(IReadOnlyCollection<TModel> entities, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Created>> InsertRangeAsync(IReadOnlyCollection<TModel> entities, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
@@ -18,6 +18,6 @@ public interface IInsertRepositoryAction<TModel> where TModel : IStorageEntity
/// </summary>
/// <param name="data">The element to be saved.</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>
Task<ErrorOr<Created>> InsertAsync(TModel data, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Created>> InsertAsync(TModel data, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
@@ -18,6 +18,6 @@ public interface IUpdateRepositoryAction<TModel> where TModel : IStorageEntity
/// </summary>
/// <param name="data">The element that will be 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>
Task<ErrorOr<Updated>> UpdateAsync(TModel data, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> UpdateAsync(TModel data, CancellationToken cancellationToken);
}
@@ -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.Common.Base;
using System;
@@ -20,14 +20,14 @@ public interface IDirectoryScanFingerprintRepository : IRepository<DirectoryScan
/// </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>
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>
Task<Result<Dictionary<string, DirectoryScanFingerprintEntity>>> GetMappedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Inserts or updates the provided directory scan fingerprints in the storage medium.
/// </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>
Task<ErrorOr<Updated>> UpsertRangeAsync(IReadOnlyCollection<DirectoryScanFingerprintEntity> entities, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> UpsertRangeAsync(IReadOnlyCollection<DirectoryScanFingerprintEntity> entities, CancellationToken cancellationToken);
}
@@ -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.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -25,13 +25,13 @@ public interface ILibraryRepository : IRepository<LibraryEntity>,
/// 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>
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>
Task<Result<IEnumerable<LibraryEntity>>> GetAllEnabledAndUnlockedAsync(CancellationToken cancellationToken);
/// <summary>
/// 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>
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>
Task<Result<IEnumerable<LibraryEntity>>> GetAllEnabledAsync(CancellationToken cancellationToken);
}
@@ -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.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -24,13 +24,13 @@ public interface ILibraryScanRepository : IRepository<LibraryScanEntity>,
/// 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>
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>
Task<Result<IEnumerable<LibraryScanEntity>>> GetPastMonthScansByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets the media library scans 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>
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>
Task<Result<IEnumerable<LibraryScanEntity>>> GetRunningScansAsync(CancellationToken cancellationToken);
}
@@ -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.Common.Base;
using System;
@@ -21,16 +21,16 @@ public interface ILibraryScanSnapshotRepository : IRepository<LibraryScanSnapsho
/// <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>
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>
Task<Result<IReadOnlyList<string>>> GetDeletedPathsAsync(Guid libraryId, Guid scanId, CancellationToken cancellationToken);
/// <summary>
/// Gets the paths of all the media library scan snapshot items of the media library identified by <paramref name="libraryId"/>.
/// </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>
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>
Task<Result<IReadOnlyList<string>>> GetPathsAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Atomically applies the results of the current scan to the storage medium, by replacing the media library scan snapshot of the previous scan with the snapshot of the current scan.
@@ -41,6 +41,6 @@ public interface ILibraryScanSnapshotRepository : IRepository<LibraryScanSnapsho
/// <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>
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>
Task<Result<Updated>> ApplySnapshotSwapAsync(Guid libraryId, Guid scanId, Guid userId, CancellationToken cancellationToken);
}
@@ -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.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -25,16 +25,16 @@ public interface ILibraryScanStagingResultsRepository : IRepository<LibraryScanS
/// <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>
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>
Task<Result<Updated>> MarkChangesAgainstSnapshotAsync(Guid scanId, Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets the number of media library scan staging results of the current scan that need their content hashed.
/// </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>
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>
Task<Result<int>> GetFilesToHashCountAsync(Guid scanId, CancellationToken cancellationToken);
/// <summary>
/// Gets a page of the media library scan staging results that need their content hashed, ordered by path, using keyset pagination.
@@ -43,8 +43,8 @@ public interface ILibraryScanStagingResultsRepository : IRepository<LibraryScanS
/// <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>
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>
Task<Result<IReadOnlyList<HashedFileSystemFileDto>>> GetFilesToHashPageAsync(Guid scanId, string? lastPath, int pageSize, CancellationToken cancellationToken);
/// <summary>
/// Updates the content hashes of the provided media library scan staging results.
@@ -52,14 +52,14 @@ public interface ILibraryScanStagingResultsRepository : IRepository<LibraryScanS
/// <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>
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>
Task<Result<Updated>> UpdateFileHashesAsync(Guid scanId, IReadOnlyCollection<HashedFileSystemFileDto> hashedFiles, CancellationToken cancellationToken);
/// <summary>
/// Clears all the media library scan staging results of the provided media library scan from the storage medium.
/// </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>
Task<ErrorOr<Success>> ClearForScanAsync(Guid scanId, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Success>> ClearForScanAsync(Guid scanId, CancellationToken cancellationToken);
}
@@ -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.Common.Base;
using System;
@@ -20,8 +20,8 @@ public interface ILibraryMetadataProviderConfigurationRepository : IRepository<L
/// </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>
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>
Task<Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Gets the metadata provider configuration of the media library identified by <paramref name="libraryId"/> for the plugin identified by <paramref name="pluginId"/>.
@@ -29,14 +29,14 @@ public interface ILibraryMetadataProviderConfigurationRepository : IRepository<L
/// <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>
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>
Task<Result<LibraryMetadataProviderConfigurationEntity?>> GetByLibraryAndPluginIdAsync(Guid libraryId, Guid pluginId, CancellationToken cancellationToken);
/// <summary>
/// Inserts the provided <paramref name="configuration"/> into the storage medium, or updates it when it already exists.
/// </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>
Task<ErrorOr<Updated>> UpsertAsync(LibraryMetadataProviderConfigurationEntity configuration, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> UpsertAsync(LibraryMetadataProviderConfigurationEntity configuration, CancellationToken cancellationToken);
}
@@ -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.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -22,8 +22,8 @@ public interface IPluginRepository : IRepository<PluginEntity>,
/// </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>
Task<ErrorOr<Updated>> UpsertAsync(PluginEntity plugin, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> UpsertAsync(PluginEntity plugin, CancellationToken cancellationToken);
/// <summary>
/// Updates the settings of the plugin identified by <paramref name="pluginId"/>.
@@ -31,6 +31,6 @@ public interface IPluginRepository : IRepository<PluginEntity>,
/// <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>
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>
Task<Result<Updated>> UpdateSettingsAsync(Guid pluginId, string? settingsJson, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -24,6 +24,6 @@ public interface IUserRepository : IRepository<UserEntity>,
/// </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>
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>
Task<Result<UserEntity?>> GetByUsernameAsync(string username, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System;
using System.Threading;
using System.Threading.Tasks;
@@ -17,30 +17,30 @@ public interface 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>
Task<ErrorOr<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken);
/// <summary>
/// Sets up default authorization roles in the system.
/// </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>
Task<ErrorOr<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Assigns admin role permissions to the admin user.
/// </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>
Task<ErrorOr<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken);
/// <summary>
/// Assigns admin role to the admin user.
/// </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>
Task<ErrorOr<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Errors;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.Common.Base;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
@@ -47,6 +47,6 @@ public interface IAuthorizationService
/// </summary>
/// <param name="userId">The unique identifier of the user for whom to retrieve the authorization roles and permissions.</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="UserAuthorizationEntity"/>, or an error.</returns>
Task<ErrorOr<UserAuthorizationEntity>> GetUserAuthorizationAsync(Guid userId, CancellationToken cancellationToken);
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="UserAuthorizationEntity"/>, or an error.</returns>
Task<Result<UserAuthorizationEntity>> GetUserAuthorizationAsync(Guid userId, CancellationToken cancellationToken);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
@@ -18,9 +18,9 @@ public static class GenreDtoMapping
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
/// </returns>
public static ErrorOr<Genre> ToDomainEntity(this GenreDto dto)
public static Result<Genre> ToDomainEntity(this GenreDto dto)
{
return Genre.Create(
dto.Name
@@ -32,9 +32,9 @@ public static class GenreDtoMapping
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Genre>> ToDomainEntities(this IEnumerable<GenreDto> dtos)
public static IEnumerable<Result<Genre>> ToDomainEntities(this IEnumerable<GenreDto> dtos)
{
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -41,9 +41,9 @@ public static class GenreEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Genre"/>, or an error message.
/// </returns>
public static ErrorOr<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
public static Result<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
{
return Genre.Create(
repositoryEntity.Name ?? default
@@ -55,9 +55,9 @@ public static class GenreEntityMapping
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Genre>> ToDomainEntities(this IEnumerable<GenreEntity> repositoryEntities)
public static IEnumerable<Result<Genre>> ToDomainEntities(this IEnumerable<GenreEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
@@ -18,9 +18,9 @@ public static class TagDtoMapping
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
/// </returns>
public static ErrorOr<Tag> ToDomainEntity(this TagDto dto)
public static Result<Tag> ToDomainEntity(this TagDto dto)
{
return Tag.Create(
dto.Name
@@ -32,9 +32,9 @@ public static class TagDtoMapping
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Tag>> ToDomainEntities(this IEnumerable<TagDto> dtos)
public static IEnumerable<Result<Tag>> ToDomainEntities(this IEnumerable<TagDto> dtos)
{
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
@@ -41,9 +41,9 @@ public static class TagEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Tag"/>, or an error message.
/// </returns>
public static ErrorOr<Tag> ToDomainEntity(this TagEntity repositoryEntity)
public static Result<Tag> ToDomainEntity(this TagEntity repositoryEntity)
{
return Tag.Create(
repositoryEntity.Name ?? default
@@ -55,9 +55,9 @@ public static class TagEntityMapping
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Tag>> ToDomainEntities(this IEnumerable<TagEntity> repositoryEntities)
public static IEnumerable<Result<Tag>> ToDomainEntities(this IEnumerable<TagEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
@@ -17,7 +17,7 @@ public static class FileSystemTreeNodeResponseMapping
/// </summary>
/// <param name="response">The response to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<WindowsRootItem> ToWindowsRootItem(this FileSystemTreeNodeResponse response)
public static Result<WindowsRootItem> ToWindowsRootItem(this FileSystemTreeNodeResponse response)
{
return WindowsRootItem.Create(
response.Path,
@@ -31,7 +31,7 @@ public static class FileSystemTreeNodeResponseMapping
/// </summary>
/// <param name="_">The response to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<UnixRootItem> ToUnixRootItem(this FileSystemTreeNodeResponse _)
public static Result<UnixRootItem> ToUnixRootItem(this FileSystemTreeNodeResponse _)
{
return UnixRootItem.Create(
FileSystemItemStatus.Accessible
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
@@ -46,9 +46,9 @@ public static class LibraryEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Library"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Library"/>, or an error message.
/// </returns>
public static ErrorOr<Library> ToDomainEntity(this LibraryEntity repositoryEntity)
public static Result<Library> ToDomainEntity(this LibraryEntity repositoryEntity)
{
return Library.Create(
LibraryId.Create(repositoryEntity.Id),
@@ -71,9 +71,9 @@ public static class LibraryEntityMapping
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Library"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Library"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Library>> ToDomainEntities(this IEnumerable<LibraryEntity> repositoryEntities)
public static IEnumerable<Result<Library>> ToDomainEntities(this IEnumerable<LibraryEntity> repositoryEntities)
{
return repositoryEntities.Select(library => library.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
@@ -23,9 +23,9 @@ public static class LibraryScanEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a converted <see cref="LibraryScan"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a converted <see cref="LibraryScan"/>, or an error message.
/// </returns>
public static ErrorOr<LibraryScan> ToDomainEntity(this LibraryScanEntity repositoryEntity)
public static Result<LibraryScan> ToDomainEntity(this LibraryScanEntity repositoryEntity)
{
return LibraryScan.Create(
ScanId.Create(repositoryEntity.Id),
@@ -41,9 +41,9 @@ public static class LibraryScanEntityMapping
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="LibraryScan"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="LibraryScan"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<LibraryScan>> ToDomainEntities(this IEnumerable<LibraryScanEntity> repositoryEntities)
public static IEnumerable<Result<LibraryScan>> ToDomainEntities(this IEnumerable<LibraryScanEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
@@ -8,7 +8,7 @@ using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
@@ -31,31 +31,31 @@ public static class BookEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Book"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Book"/>, or an error message.
/// </returns>
public static ErrorOr<Book> ToDomainEntity(this BookEntity repositoryEntity)
public static Result<Book> ToDomainEntity(this BookEntity repositoryEntity)
{
IEnumerable<ErrorOr<Tag>> tagsResult = repositoryEntity.Tags.ToDomainEntities();
foreach (ErrorOr<Tag> tagResult in tagsResult)
if (tagResult.IsError)
IEnumerable<Result<Tag>> tagsResult = repositoryEntity.Tags.ToDomainEntities();
foreach (Result<Tag> tagResult in tagsResult)
if (tagResult.IsFailure)
return tagResult.Errors;
IEnumerable<ErrorOr<Genre>> genresResult = repositoryEntity.Genres.ToDomainEntities();
foreach (ErrorOr<Genre> genreResult in genresResult)
if (genreResult.IsError)
IEnumerable<Result<Genre>> genresResult = repositoryEntity.Genres.ToDomainEntities();
foreach (Result<Genre> genreResult in genresResult)
if (genreResult.IsFailure)
return genreResult.Errors;
IEnumerable<ErrorOr<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainEntities();
foreach (ErrorOr<Isbn> isbnResult in isbnsResult)
if (isbnResult.IsError)
IEnumerable<Result<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainEntities();
foreach (Result<Isbn> isbnResult in isbnsResult)
if (isbnResult.IsFailure)
return isbnResult.Errors;
IEnumerable<ErrorOr<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainEntities();
foreach (ErrorOr<BookRating> bookRatingResult in bookRatingsResult)
if (bookRatingResult.IsError)
IEnumerable<Result<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainEntities();
foreach (Result<BookRating> bookRatingResult in bookRatingsResult)
if (bookRatingResult.IsFailure)
return bookRatingResult.Errors;
ErrorOr<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Optional<DateOnly>.FromNullable(repositoryEntity.OriginalReleaseDate),
Optional<int>.FromNullable(repositoryEntity.OriginalReleaseYear),
Optional<DateOnly>.FromNullable(repositoryEntity.ReReleaseDate),
@@ -63,18 +63,18 @@ public static class BookEntityMapping
Optional<string>.FromNullable(repositoryEntity.ReleaseCountry),
Optional<string>.FromNullable(repositoryEntity.ReleaseVersion)
);
if (releaseInfoResult.IsError)
if (releaseInfoResult.IsFailure)
return releaseInfoResult.Errors;
Optional<LanguageInfo> languageInfo = Optional<LanguageInfo>.None();
if (repositoryEntity.LanguageCode is not null)
{
ErrorOr<LanguageInfo> languageInfoResult = LanguageInfo.Create(
Result<LanguageInfo> languageInfoResult = LanguageInfo.Create(
repositoryEntity.LanguageCode,
repositoryEntity.LanguageName,
Optional<string>.FromNullable(repositoryEntity.LanguageNativeName)
);
if (languageInfoResult.IsError)
if (languageInfoResult.IsFailure)
return languageInfoResult.Errors;
languageInfo = languageInfoResult.Value;
}
@@ -82,29 +82,29 @@ public static class BookEntityMapping
Optional<LanguageInfo> originalLanguageCode = Optional<LanguageInfo>.None();
if (repositoryEntity.OriginalLanguageCode is not null)
{
ErrorOr<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(
Result<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(
repositoryEntity.OriginalLanguageCode,
repositoryEntity.OriginalLanguageName!,
Optional<string>.FromNullable(repositoryEntity.OriginalLanguageNativeName)
);
if (originalLanguageInfoResult.IsError)
if (originalLanguageInfoResult.IsFailure)
return originalLanguageInfoResult.Errors;
originalLanguageCode = originalLanguageInfoResult.Value;
}
ErrorOr<WrittenContentMetadata> writtenContentMetadataResult = WrittenContentMetadata.Create(
Result<WrittenContentMetadata> writtenContentMetadataResult = WrittenContentMetadata.Create(
repositoryEntity.Title,
Optional<string>.FromNullable(repositoryEntity.OriginalTitle),
Optional<string>.FromNullable(repositoryEntity.Description),
releaseInfoResult.Value,
genresResult.Select(genre => genre.Value).ToList(),
tagsResult.Select(tag => tag.Value).ToList(),
[.. genresResult.Select(genre => genre.Value)],
[.. tagsResult.Select(tag => tag.Value)],
languageInfo,
originalLanguageCode,
Optional<string>.FromNullable(repositoryEntity.Publisher),
Optional<int>.FromNullable(repositoryEntity.PageCount)
);
if (writtenContentMetadataResult.IsError)
if (writtenContentMetadataResult.IsFailure)
return writtenContentMetadataResult.Errors;
Optional<BookFormat> bookFormat = Optional<BookFormat>.FromNullable(repositoryEntity.Format);
@@ -129,9 +129,9 @@ public static class BookEntityMapping
Optional<string>.FromNullable(repositoryEntity.AppleBooksId),
repositoryEntity.CreatedOnUtc,
Optional<DateTime>.FromNullable(repositoryEntity.UpdatedOnUtc),
isbnsResult.Select(isbn => isbn.Value).ToList(),
[.. isbnsResult.Select(isbn => isbn.Value)],
[],
bookRatingsResult.Select(bookRating => bookRating.Value).ToList());
[.. bookRatingsResult.Select(bookRating => bookRating.Value)]);
}
/// <summary>
@@ -140,9 +140,9 @@ public static class BookEntityMapping
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted domain entities.</returns>
/// <returns>
/// An colection of <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Book"/>, or error messages.
/// An colection of <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Book"/>, or error messages.
/// </returns>
public static IEnumerable<ErrorOr<Book>> ToDomainEntities(this IEnumerable<BookEntity> repositoryEntities)
public static IEnumerable<Result<Book>> ToDomainEntities(this IEnumerable<BookEntity> repositoryEntities)
{
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
@@ -26,15 +26,15 @@ public static class BookMetadataDtoMapping
/// <param name="metadata">The metadata to be applied.</param>
/// <param name="providerName">The name of the metadata provider that enriched the book.</param>
/// <param name="lastUpdateUtc">The date and time when the metadata was enriched.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
public static ErrorOr<Success> ApplyMetadata(this Book book, BookMetadataDto metadata, string providerName, DateTime lastUpdateUtc)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public static Result<Success> ApplyMetadata(this Book book, BookMetadataDto metadata, string providerName, DateTime lastUpdateUtc)
{
if (string.IsNullOrWhiteSpace(metadata.Title))
return Domain.SharedKernel.Common.Errors.Errors.Metadata.TitleCannotBeEmpty;
return Lumina.Domain.Common.Errors.Errors.Metadata.TitleCannotBeEmpty;
if (metadata.ReleaseInfo is null)
return Domain.SharedKernel.Common.Errors.Errors.Metadata.ReleaseInfoCannotBeNull;
return Lumina.Domain.Common.Errors.Errors.Metadata.ReleaseInfoCannotBeNull;
ErrorOr<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Optional<DateOnly>.FromNullable(metadata.ReleaseInfo.OriginalReleaseDate),
Optional<int>.FromNullable(metadata.ReleaseInfo.OriginalReleaseYear),
Optional<DateOnly>.FromNullable(metadata.ReleaseInfo.ReReleaseDate),
@@ -42,28 +42,28 @@ public static class BookMetadataDtoMapping
Optional<string>.FromNullable(metadata.ReleaseInfo.ReleaseCountry),
Optional<string>.FromNullable(metadata.ReleaseInfo.ReleaseVersion)
);
if (releaseInfoResult.IsError)
if (releaseInfoResult.IsFailure)
return releaseInfoResult.Errors;
List<ErrorOr<Genre>> domainGenresResult = metadata.Genres is not null
List<Result<Genre>> domainGenresResult = metadata.Genres is not null
? [.. metadata.Genres.Select(genre => Genre.Create(genre.Name))]
: [];
List<Error> genresErrors = [.. domainGenresResult.Where(genreResult => genreResult.IsError).SelectMany(genreResult => genreResult.Errors)];
List<Error> genresErrors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
if (genresErrors.Count != 0)
return genresErrors;
List<ErrorOr<Tag>> domainTagsResult = metadata.Tags is not null
List<Result<Tag>> domainTagsResult = metadata.Tags is not null
? [.. metadata.Tags.Select(tag => Tag.Create(tag.Name))]
: [];
List<Error> tagsErrors = [.. domainTagsResult.Where(tagResult => tagResult.IsError).SelectMany(tagResult => tagResult.Errors)];
List<Error> tagsErrors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
if (tagsErrors.Count != 0)
return tagsErrors;
Optional<LanguageInfo> languageInfo = Optional<LanguageInfo>.None();
if (metadata.Language is not null)
{
ErrorOr<LanguageInfo> languageInfoResult = LanguageInfo.Create(metadata.Language.LanguageCode, metadata.Language.LanguageName, Optional<string>.FromNullable(metadata.Language.NativeName));
if (languageInfoResult.IsError)
Result<LanguageInfo> languageInfoResult = LanguageInfo.Create(metadata.Language.LanguageCode, metadata.Language.LanguageName, Optional<string>.FromNullable(metadata.Language.NativeName));
if (languageInfoResult.IsFailure)
return languageInfoResult.Errors;
languageInfo = languageInfoResult.Value;
}
@@ -71,13 +71,13 @@ public static class BookMetadataDtoMapping
Optional<LanguageInfo> originalLanguageInfo = Optional<LanguageInfo>.None();
if (metadata.OriginalLanguage is not null)
{
ErrorOr<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(metadata.OriginalLanguage.LanguageCode, metadata.OriginalLanguage.LanguageName, Optional<string>.FromNullable(metadata.OriginalLanguage.NativeName));
if (originalLanguageInfoResult.IsError)
Result<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(metadata.OriginalLanguage.LanguageCode, metadata.OriginalLanguage.LanguageName, Optional<string>.FromNullable(metadata.OriginalLanguage.NativeName));
if (originalLanguageInfoResult.IsFailure)
return originalLanguageInfoResult.Errors;
originalLanguageInfo = originalLanguageInfoResult.Value;
}
ErrorOr<WrittenContentMetadata> writtenContentMetadataResult = WrittenContentMetadata.Create(
Result<WrittenContentMetadata> writtenContentMetadataResult = WrittenContentMetadata.Create(
metadata.Title,
Optional<string>.FromNullable(metadata.OriginalTitle),
Optional<string>.FromNullable(metadata.Description),
@@ -89,17 +89,17 @@ public static class BookMetadataDtoMapping
Optional<string>.FromNullable(metadata.Publisher),
Optional<int>.FromNullable(metadata.PageCount)
);
if (writtenContentMetadataResult.IsError)
if (writtenContentMetadataResult.IsFailure)
return writtenContentMetadataResult.Errors;
List<ErrorOr<Isbn>> domainIsbnsResult = metadata.Isbns is not null
List<Result<Isbn>> domainIsbnsResult = metadata.Isbns is not null
? [.. metadata.Isbns.Where(isbn => isbn.Value is not null && isbn.Format is not null).Select(isbn => Isbn.Create(isbn.Value, (IsbnFormat)(int)isbn.Format!.Value))]
: [];
List<Error> isbnsErrors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsError).SelectMany(isbnResult => isbnResult.Errors)];
List<Error> isbnsErrors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
if (isbnsErrors.Count != 0)
return isbnsErrors;
List<ErrorOr<BookRating>> domainRatingsResult = metadata.Ratings is not null
List<Result<BookRating>> domainRatingsResult = metadata.Ratings is not null
? [.. metadata.Ratings.Where(rating => rating.Value is not null && rating.MaxValue is not null).Select(rating => BookRating.Create(
rating.Value!.Value,
rating.MaxValue!.Value,
@@ -107,7 +107,7 @@ public static class BookMetadataDtoMapping
Optional<int>.FromNullable(rating.VoteCount)
))]
: [];
List<Error> ratingsErrors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsError).SelectMany(ratingResult => ratingResult.Errors)];
List<Error> ratingsErrors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
if (ratingsErrors.Count != 0)
return ratingsErrors;
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
@@ -20,9 +20,9 @@ public static class BookRatingDtoMapping
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
/// </returns>
public static ErrorOr<BookRating> ToDomainEntity(this BookRatingDto dto)
public static Result<BookRating> ToDomainEntity(this BookRatingDto dto)
{
return BookRating.Create(
dto.Value ?? default,
@@ -37,9 +37,9 @@ public static class BookRatingDtoMapping
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingDto> dtos)
public static IEnumerable<Result<BookRating>> ToDomainEntities(this IEnumerable<BookRatingDto> dtos)
{
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
@@ -46,9 +46,9 @@ public static class BookRatingEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="BookRating"/>, or an error message.
/// </returns>
public static ErrorOr<BookRating> ToDomainEntity(this BookRatingEntity repositoryEntity)
public static Result<BookRating> ToDomainEntity(this BookRatingEntity repositoryEntity)
{
return BookRating.Create(
repositoryEntity.Value ?? default,
@@ -63,9 +63,9 @@ public static class BookRatingEntityMapping
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
public static IEnumerable<Result<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
@@ -19,9 +19,9 @@ public static class IsbnDtoMapping
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
/// </returns>
public static ErrorOr<Isbn> ToDomainEntity(this IsbnDto dto)
public static Result<Isbn> ToDomainEntity(this IsbnDto dto)
{
return Isbn.Create(
dto.Value,
@@ -34,9 +34,9 @@ public static class IsbnDtoMapping
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnDto> dtos)
public static IEnumerable<Result<Isbn>> ToDomainEntities(this IEnumerable<IsbnDto> dtos)
{
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
@@ -42,9 +42,9 @@ public static class IsbnEntityMapping
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
/// </returns>
public static ErrorOr<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
public static Result<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
{
return Isbn.Create(
repositoryEntity.Value ?? default,
@@ -57,9 +57,9 @@ public static class IsbnEntityMapping
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
/// </returns>
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
public static IEnumerable<Result<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPer
/// <summary>
/// Handler for the query to retrieve the list of authorization permissions.
/// </summary>
public class GetPermissionsQueryHandler : IQueryHandler<GetPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>>
public class GetPermissionsQueryHandler : IQueryHandler<GetPermissionsQuery, Result<IEnumerable<PermissionResponse>>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -44,15 +44,15 @@ public class GetPermissionsQueryHandler : IQueryHandler<GetPermissionsQuery, Err
/// <param name="query">The request to be handled.</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="PermissionResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="PermissionResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<IEnumerable<PermissionResponse>>> HandleAsync(GetPermissionsQuery query, CancellationToken cancellationToken)
public async Task<Result<IEnumerable<PermissionResponse>>> HandleAsync(GetPermissionsQuery query, CancellationToken cancellationToken)
{
// only admins can see the list of authorization permissions
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
if (!isAdmin)
return Errors.Authorization.NotAuthorized;
ErrorOr<IEnumerable<PermissionEntity>> getPermissionsResult = await _permissionRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
return getPermissionsResult.Match(value => ErrorOrFactory.From(value.ToResponses()), errors => errors);
Result<IEnumerable<PermissionEntity>> getPermissionsResult = await _permissionRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
return getPermissionsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -21,7 +21,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
/// <summary>
/// Handler for the command to add an authorization role.
/// </summary>
public class AddRoleCommandHandler : ICommandHandler<AddRoleCommand, ErrorOr<RolePermissionsResponse>>
public class AddRoleCommandHandler : ICommandHandler<AddRoleCommand, Result<RolePermissionsResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
@@ -49,9 +49,9 @@ public class AddRoleCommandHandler : ICommandHandler<AddRoleCommand, ErrorOr<Rol
/// <param name="request">The request to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="RoleResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="RoleResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<RolePermissionsResponse>> HandleAsync(AddRoleCommand request, CancellationToken cancellationToken)
public async Task<Result<RolePermissionsResponse>> HandleAsync(AddRoleCommand request, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(request);
if (validationResult.Count > 0)
@@ -77,13 +77,13 @@ public class AddRoleCommandHandler : ICommandHandler<AddRoleCommand, ErrorOr<Rol
})]
};
// save the new role in the repository
ErrorOr<Created> insertRoleResult = await roleRepository.InsertAsync(newRole, cancellationToken).ConfigureAwait(false);
if (insertRoleResult.IsError)
Result<Created> insertRoleResult = await roleRepository.InsertAsync(newRole, cancellationToken).ConfigureAwait(false);
if (insertRoleResult.IsFailure)
return insertRoleResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// retrieve the newly saved authorization role from the persistence medium and return it
ErrorOr<RoleEntity?> getRoleResult = await roleRepository.GetByNameAsync(request.RoleName, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsError)
Result<RoleEntity?> getRoleResult = await roleRepository.GetByNameAsync(request.RoleName, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsFailure)
return getRoleResult.Errors;
if (getRoleResult.Value is null)
return Errors.Persistence.ErrorPersistingAuthorizationRole;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
/// <summary>
/// Handler for the command to delete an authorization role.
/// </summary>
public class DeleteRoleCommandHandler : ICommandHandler<DeleteRoleCommand, ErrorOr<Deleted>>
public class DeleteRoleCommandHandler : ICommandHandler<DeleteRoleCommand, Result<Deleted>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
@@ -49,8 +49,8 @@ public class DeleteRoleCommandHandler : ICommandHandler<DeleteRoleCommand, Error
/// </summary>
/// <param name="command">The request to be handled.</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>> HandleAsync(DeleteRoleCommand command, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Deleted>> HandleAsync(DeleteRoleCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -63,16 +63,16 @@ public class DeleteRoleCommandHandler : ICommandHandler<DeleteRoleCommand, Error
// check if a role with the requested Id exists
IRoleRepository roleRepository = _unitOfWork.GetRepository<IRoleRepository>();
ErrorOr<RoleEntity?> getExistingRoleResult = await roleRepository.GetByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (getExistingRoleResult.IsError)
Result<RoleEntity?> getExistingRoleResult = await roleRepository.GetByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (getExistingRoleResult.IsFailure)
return getExistingRoleResult.Errors;
else if (getExistingRoleResult.Value is null)
return Errors.Authorization.RoleNotFound;
else if (getExistingRoleResult.Value.RoleName == "Admin")
return Errors.Authorization.AdminRoleCannotBeDeleted;
// delete the role and its permissions
ErrorOr<Deleted> deleteRoleResult = await roleRepository.DeleteByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (deleteRoleResult.IsError)
Result<Deleted> deleteRoleResult = await roleRepository.DeleteByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (deleteRoleResult.IsFailure)
return deleteRoleResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
return deleteRoleResult.Value;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -21,7 +21,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
/// <summary>
/// Handler for the command to update an authorization role.
/// </summary>
public class UpdateRoleCommandHandler : ICommandHandler<UpdateRoleCommand, ErrorOr<RolePermissionsResponse>>
public class UpdateRoleCommandHandler : ICommandHandler<UpdateRoleCommand, Result<RolePermissionsResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
@@ -49,9 +49,9 @@ public class UpdateRoleCommandHandler : ICommandHandler<UpdateRoleCommand, Error
/// <param name="command">The request to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully updated <see cref="RoleResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully updated <see cref="RoleResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<RolePermissionsResponse>> HandleAsync(UpdateRoleCommand command, CancellationToken cancellationToken)
public async Task<Result<RolePermissionsResponse>> HandleAsync(UpdateRoleCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -78,13 +78,13 @@ public class UpdateRoleCommandHandler : ICommandHandler<UpdateRoleCommand, Error
}).ToList()
};
// save the updated role in the repository
ErrorOr<Updated> updateRoleResult = await roleRepository.UpdateAsync(newRole, cancellationToken).ConfigureAwait(false);
if (updateRoleResult.IsError)
Result<Updated> updateRoleResult = await roleRepository.UpdateAsync(newRole, cancellationToken).ConfigureAwait(false);
if (updateRoleResult.IsFailure)
return updateRoleResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// retrieve the updated authorization role from the persistence medium and return it
ErrorOr<RoleEntity?> getRoleResult = await roleRepository.GetByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsError)
Result<RoleEntity?> getRoleResult = await roleRepository.GetByIdAsync(command.RoleId, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsFailure)
return getRoleResult.Errors;
if (getRoleResult.Value is null)
return Errors.Persistence.ErrorPersistingAuthorizationRole;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -20,7 +20,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermi
/// <summary>
/// Handler for the query to retrieve the list of authorization permissions for a role.
/// </summary>
public class GetRolePermissionsQueryHandler : IQueryHandler<GetRolePermissionsQuery, ErrorOr<RolePermissionsResponse>>
public class GetRolePermissionsQueryHandler : IQueryHandler<GetRolePermissionsQuery, Result<RolePermissionsResponse>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -48,9 +48,9 @@ public class GetRolePermissionsQueryHandler : IQueryHandler<GetRolePermissionsQu
/// <param name="request">The request to be handled.</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="RoleResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="RoleResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<RolePermissionsResponse>> HandleAsync(GetRolePermissionsQuery request, CancellationToken cancellationToken)
public async Task<Result<RolePermissionsResponse>> HandleAsync(GetRolePermissionsQuery request, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(request);
if (validationResult.Count > 0)
@@ -61,8 +61,8 @@ public class GetRolePermissionsQueryHandler : IQueryHandler<GetRolePermissionsQu
if (!isAdmin)
return Errors.Authorization.NotAuthorized;
// get the role from the repository and return its role permissions
ErrorOr<RoleEntity?> getRoleResult = await _roleRepository.GetByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsError)
Result<RoleEntity?> getRoleResult = await _roleRepository.GetByIdAsync(request.RoleId, cancellationToken).ConfigureAwait(false);
if (getRoleResult.IsFailure)
return getRoleResult.Errors;
else if (getRoleResult.Value is null)
return Errors.Authorization.RoleNotFound;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
/// <summary>
/// Handler for the query to retrieve the list of authorization roles.
/// </summary>
public class GetRolesQueryHandler : IQueryHandler<GetRolesQuery, ErrorOr<IEnumerable<RoleResponse>>>
public class GetRolesQueryHandler : IQueryHandler<GetRolesQuery, Result<IEnumerable<RoleResponse>>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -44,15 +44,15 @@ public class GetRolesQueryHandler : IQueryHandler<GetRolesQuery, ErrorOr<IEnumer
/// <param name="query">The request to be handled.</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="RoleResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="RoleResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<IEnumerable<RoleResponse>>> HandleAsync(GetRolesQuery query, CancellationToken cancellationToken)
public async Task<Result<IEnumerable<RoleResponse>>> HandleAsync(GetRolesQuery query, CancellationToken cancellationToken)
{
// only admins can see the list of authorization roles
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
if (!isAdmin)
return Errors.Authorization.NotAuthorized;
ErrorOr<IEnumerable<RoleEntity>> getRolesResult = await _roleRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
return getRolesResult.Match(value => ErrorOrFactory.From(value.ToResponses()), errors => errors);
Result<IEnumerable<RoleEntity>> getRolesResult = await _roleRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
return getRolesResult.Match(value => Result.From(value.ToResponses()), errors => errors);
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
using Lumina.Application.Common.Infrastructure.Validation;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDi
/// <summary>
/// Handler for the query to get all directories.
/// </summary>
public class GetDirectoriesQueryHandler : IQueryHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<DirectoryResponse>>>
public class GetDirectoriesQueryHandler : IQueryHandler<GetDirectoriesQuery, Result<IEnumerable<DirectoryResponse>>>
{
private readonly IDirectoryService _directoryService;
private readonly IValidator<GetDirectoriesQuery> _validator;
@@ -38,15 +38,15 @@ public class GetDirectoriesQueryHandler : IQueryHandler<GetDirectoriesQuery, Err
/// <param name="query">The query containing the requested path.</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="DirectoryResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="DirectoryResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<IEnumerable<DirectoryResponse>>> HandleAsync(GetDirectoriesQuery query, CancellationToken cancellationToken)
public Task<Result<IEnumerable<DirectoryResponse>>> HandleAsync(GetDirectoriesQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<IEnumerable<DirectoryResponse>>>(validationResult);
return Task.FromResult<Result<IEnumerable<DirectoryResponse>>>(validationResult);
ErrorOr<IEnumerable<Directory>> getSubdirectoriesResult = _directoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements);
return Task.FromResult(getSubdirectoriesResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
Result<IEnumerable<Directory>> getSubdirectoriesResult = _directoryService.GetSubdirectories(query.Path!, query.IncludeHiddenElements);
return Task.FromResult(getSubdirectoriesResult.Match(values => Result.From(values.ToResponses()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
@@ -15,7 +15,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
/// <summary>
/// Handler for the query to get all drives.
/// </summary>
public class GetDrivesQueryHandler : IQueryHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
public class GetDrivesQueryHandler : IQueryHandler<GetDrivesQuery, Result<IEnumerable<FileSystemTreeNodeResponse>>>
{
private readonly IDriveService _driveService;
@@ -34,11 +34,11 @@ public class GetDrivesQueryHandler : IQueryHandler<GetDrivesQuery, ErrorOr<IEnum
/// <param name="query">The query containing the requested path.</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="FileSystemTreeNodeResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> HandleAsync(GetDrivesQuery query, CancellationToken cancellationToken)
public Task<Result<IEnumerable<FileSystemTreeNodeResponse>>> HandleAsync(GetDrivesQuery query, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<FileSystemItem>> getDrivesResult = _driveService.GetDrives();
return Task.FromResult(getDrivesResult.Match(values => ErrorOrFactory.From(values.ToTreeNodeResponses()), errors => errors));
Result<IEnumerable<FileSystemItem>> getDrivesResult = _driveService.GetDrives();
return Task.FromResult(getDrivesResult.Match(values => Result.From(values.ToTreeNodeResponses()), errors => errors));
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Application.Common.Infrastructure.Validation;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
/// <summary>
/// Handler for the query to get all files.
/// </summary>
public class GetFilesQueryHandler : IQueryHandler<GetFilesQuery, ErrorOr<IEnumerable<FileResponse>>>
public class GetFilesQueryHandler : IQueryHandler<GetFilesQuery, Result<IEnumerable<FileResponse>>>
{
private readonly IFileService _fileService;
private readonly IValidator<GetFilesQuery> _validator;
@@ -38,15 +38,15 @@ public class GetFilesQueryHandler : IQueryHandler<GetFilesQuery, ErrorOr<IEnumer
/// <param name="query">The query containing the requested path.</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="FileResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="FileResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<IEnumerable<FileResponse>>> HandleAsync(GetFilesQuery query, CancellationToken cancellationToken)
public Task<Result<IEnumerable<FileResponse>>> HandleAsync(GetFilesQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<IEnumerable<FileResponse>>>(validationResult);
return Task.FromResult<Result<IEnumerable<FileResponse>>>(validationResult);
ErrorOr<IEnumerable<File>> getFilesResult = _fileService.GetFiles(query.Path!, query.IncludeHiddenElements);
return Task.FromResult(getFilesResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
Result<IEnumerable<File>> getFilesResult = _fileService.GetFiles(query.Path!, query.IncludeHiddenElements);
return Task.FromResult(getFilesResult.Match(values => Result.From(values.ToResponses()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Application.Common.Infrastructure.Validation;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFile
/// <summary>
/// Handler for the query to get all files.
/// </summary>
public class GetTreeFilesQueryHandler : IQueryHandler<GetTreeFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
public class GetTreeFilesQueryHandler : IQueryHandler<GetTreeFilesQuery, Result<IEnumerable<FileSystemTreeNodeResponse>>>
{
private readonly IFileService _fileService;
private readonly IValidator<GetTreeFilesQuery> _validator;
@@ -38,15 +38,15 @@ public class GetTreeFilesQueryHandler : IQueryHandler<GetTreeFilesQuery, ErrorOr
/// <param name="query">The query containing the requested path.</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="FileSystemTreeNodeResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> HandleAsync(GetTreeFilesQuery query, CancellationToken cancellationToken)
public Task<Result<IEnumerable<FileSystemTreeNodeResponse>>> HandleAsync(GetTreeFilesQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(validationResult);
return Task.FromResult<Result<IEnumerable<FileSystemTreeNodeResponse>>>(validationResult);
ErrorOr<IEnumerable<File>> getFilesResult = _fileService.GetFiles(query.Path!, query.IncludeHiddenElements);
return Task.FromResult(getFilesResult.Match(values => ErrorOrFactory.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
Result<IEnumerable<File>> getFilesResult = _fileService.GetFiles(query.Path!, query.IncludeHiddenElements);
return Task.FromResult(getFilesResult.Match(values => Result.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
@@ -15,7 +15,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePat
/// <summary>
/// Handler for the command to split a file system path.
/// </summary>
public class CombinePathCommandHandler : ICommandHandler<CombinePathCommand, ErrorOr<PathSegmentResponse>>
public class CombinePathCommandHandler : ICommandHandler<CombinePathCommand, Result<PathSegmentResponse>>
{
private readonly IPathService _pathService;
private readonly IValidator<CombinePathCommand> _validator;
@@ -37,15 +37,15 @@ public class CombinePathCommandHandler : ICommandHandler<CombinePathCommand, Err
/// <param name="command">The command containing the requested 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 <see cref="PathSegmentResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a <see cref="PathSegmentResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<PathSegmentResponse>> HandleAsync(CombinePathCommand command, CancellationToken cancellationToken)
public Task<Result<PathSegmentResponse>> HandleAsync(CombinePathCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<PathSegmentResponse>>(validationResult);
return Task.FromResult<Result<PathSegmentResponse>>(validationResult);
ErrorOr<string> combinePathResult = _pathService.CombinePath(command.OriginalPath!, command.NewPath!);
return Task.FromResult(combinePathResult.Match(values => ErrorOrFactory.From(new PathSegmentResponse(combinePathResult.Value)), errors => errors));
Result<string> combinePathResult = _pathService.CombinePath(command.OriginalPath!, command.NewPath!);
return Task.FromResult(combinePathResult.Match(values => Result.From(new PathSegmentResponse(combinePathResult.Value)), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
/// <summary>
/// Handler for the command to split a file system path.
/// </summary>
public class SplitPathCommandHandler : ICommandHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>>
public class SplitPathCommandHandler : ICommandHandler<SplitPathCommand, Result<IEnumerable<PathSegmentResponse>>>
{
private readonly IPathService _pathService;
private readonly IValidator<SplitPathCommand> _validator;
@@ -38,15 +38,15 @@ public class SplitPathCommandHandler : ICommandHandler<SplitPathCommand, ErrorOr
/// <param name="command">The command containing the requested path.</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="PathSegmentResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="PathSegmentResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<IEnumerable<PathSegmentResponse>>> HandleAsync(SplitPathCommand command, CancellationToken cancellationToken)
public Task<Result<IEnumerable<PathSegmentResponse>>> HandleAsync(SplitPathCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<IEnumerable<PathSegmentResponse>>>(validationResult);
return Task.FromResult<Result<IEnumerable<PathSegmentResponse>>>(validationResult);
ErrorOr<IEnumerable<PathSegment>> parsePathResult = _pathService.ParsePath(command.Path!);
return Task.FromResult(parsePathResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
Result<IEnumerable<PathSegment>> parsePathResult = _pathService.ParsePath(command.Path!);
return Task.FromResult(parsePathResult.Match(values => Result.From(values.ToResponses()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
@@ -14,7 +14,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathEx
/// <summary>
/// Handler for the query to check the existence a file system path.
/// </summary>
public class CheckPathExistsQueryHandler : IQueryHandler<CheckPathExistsQuery, ErrorOr<PathExistsResponse>>
public class CheckPathExistsQueryHandler : IQueryHandler<CheckPathExistsQuery, Result<PathExistsResponse>>
{
private readonly IPathService _pathService;
private readonly IValidator<CheckPathExistsQuery> _validator;
@@ -36,14 +36,14 @@ public class CheckPathExistsQueryHandler : IQueryHandler<CheckPathExistsQuery, E
/// <param name="query">The query containing the request.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either <see langword="true"/> if the specified path exists, <see langword="false"/> if it doesn't, or an error message.
/// An <see cref="Result{TValue}"/> containing either <see langword="true"/> if the specified path exists, <see langword="false"/> if it doesn't, or an error message.
/// </returns>
public Task<ErrorOr<PathExistsResponse>> HandleAsync(CheckPathExistsQuery query, CancellationToken cancellationToken)
public Task<Result<PathExistsResponse>> HandleAsync(CheckPathExistsQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<PathExistsResponse>>(validationResult);
return Task.FromResult<Result<PathExistsResponse>>(validationResult);
return Task.FromResult(ErrorOrFactory.From(new PathExistsResponse(_pathService.Exists(query.Path!, query.IncludeHiddenElements))));
return Task.FromResult(Result.From(new PathExistsResponse(_pathService.Exists(query.Path!, query.IncludeHiddenElements))));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathPare
/// <summary>
/// Handler for the query to get the parent of a file system path.
/// </summary>
public class GetPathParentQueryHandler : IQueryHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>>
public class GetPathParentQueryHandler : IQueryHandler<GetPathParentQuery, Result<IEnumerable<PathSegmentResponse>>>
{
private readonly IPathService _pathService;
private readonly IValidator<GetPathParentQuery> _validator;
@@ -38,15 +38,15 @@ public class GetPathParentQueryHandler : IQueryHandler<GetPathParentQuery, Error
/// <param name="query">The query containing the requested path.</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="PathSegmentResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="PathSegmentResponse"/>, or an error message.
/// </returns>
public Task<ErrorOr<IEnumerable<PathSegmentResponse>>> HandleAsync(GetPathParentQuery query, CancellationToken cancellationToken)
public Task<Result<IEnumerable<PathSegmentResponse>>> HandleAsync(GetPathParentQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<IEnumerable<PathSegmentResponse>>>(validationResult);
return Task.FromResult<Result<IEnumerable<PathSegmentResponse>>>(validationResult);
ErrorOr<IEnumerable<PathSegment>> goUpOneLevelResult = _pathService.GoUpOneLevel(query.Path!);
return Task.FromResult(goUpOneLevelResult.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
Result<IEnumerable<PathSegment>> goUpOneLevelResult = _pathService.GoUpOneLevel(query.Path!);
return Task.FromResult(goUpOneLevelResult.Match(values => Result.From(values.ToResponses()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot
/// <summary>
/// Handler for the query to get the root of a file system path.
/// </summary>
public class GetPathRootQueryHandler : IQueryHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>>
public class GetPathRootQueryHandler : IQueryHandler<GetPathRootQuery, Result<PathSegmentResponse>>
{
private readonly IPathService _pathService;
private readonly IValidator<GetPathRootQuery> _validator;
@@ -37,14 +37,14 @@ public class GetPathRootQueryHandler : IQueryHandler<GetPathRootQuery, ErrorOr<P
/// </summary>
/// <param name="query">The query containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the root of the specified path, or an error.</returns>
public Task<ErrorOr<PathSegmentResponse>> HandleAsync(GetPathRootQuery query, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> containing either the root of the specified path, or an error.</returns>
public Task<Result<PathSegmentResponse>> HandleAsync(GetPathRootQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<PathSegmentResponse>>(validationResult);
return Task.FromResult<Result<PathSegmentResponse>>(validationResult);
ErrorOr<PathSegment> getPathRootResult = _pathService.GetPathRoot(query.Path!);
return Task.FromResult(getPathRootResult.Match(values => ErrorOrFactory.From(values.ToResponse()), errors => errors));
Result<PathSegment> getPathRootResult = _pathService.GetPathRoot(query.Path!);
return Task.FromResult(getPathRootResult.Match(values => Result.From(values.ToResponse()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
@@ -14,7 +14,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePat
/// <summary>
/// Handler for the query to validate a file system path.
/// </summary>
public class ValidatePathQueryHandler : IQueryHandler<ValidatePathQuery, ErrorOr<PathValidResponse>>
public class ValidatePathQueryHandler : IQueryHandler<ValidatePathQuery, Result<PathValidResponse>>
{
private readonly IPathService _pathService;
private readonly IValidator<ValidatePathQuery> _validator;
@@ -36,14 +36,14 @@ public class ValidatePathQueryHandler : IQueryHandler<ValidatePathQuery, ErrorOr
/// <param name="query">The query containing the request.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either <see langword="true"/> if the specified path is valid, <see langword="false"/> if it isn't, or an error message.
/// An <see cref="Result{TValue}"/> containing either <see langword="true"/> if the specified path is valid, <see langword="false"/> if it isn't, or an error message.
/// </returns>
public Task<ErrorOr<PathValidResponse>> HandleAsync(ValidatePathQuery query, CancellationToken cancellationToken)
public Task<Result<PathValidResponse>> HandleAsync(ValidatePathQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return Task.FromResult<ErrorOr<PathValidResponse>>(validationResult);
return Task.FromResult<Result<PathValidResponse>>(validationResult);
return Task.FromResult(ErrorOrFactory.From(new PathValidResponse(_pathService.IsValidPath(query.Path!))));
return Task.FromResult(Result.From(new PathValidResponse(_pathService.IsValidPath(query.Path!))));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
using Lumina.Application.Common.Infrastructure.Validation;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThu
/// <summary>
/// Handler for the query to get the file thumbnail.
/// </summary>
public class GetThumbnailQueryHandler : IQueryHandler<GetThumbnailQuery, ErrorOr<ThumbnailResponse>>
public class GetThumbnailQueryHandler : IQueryHandler<GetThumbnailQuery, Result<ThumbnailResponse>>
{
private readonly IThumbnailService _thumbnailsService;
private readonly IValidator<GetThumbnailQuery> _validator;
@@ -37,14 +37,14 @@ public class GetThumbnailQueryHandler : IQueryHandler<GetThumbnailQuery, ErrorOr
/// </summary>
/// <param name="query">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> containing either a thumbnail, or an error.</returns>
public async Task<ErrorOr<ThumbnailResponse>> HandleAsync(GetThumbnailQuery query, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{T}"/> containing either a thumbnail, or an error.</returns>
public async Task<Result<ThumbnailResponse>> HandleAsync(GetThumbnailQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return validationResult;
ErrorOr<Thumbnail> getThumbnailResult = await _thumbnailsService.GetThumbnailAsync(query.Path!, query.Quality, cancellationToken);
return await ValueTask.FromResult(getThumbnailResult.Match(value => ErrorOrFactory.From(value.ToResponse()), errors => errors));
Result<Thumbnail> getThumbnailResult = await _thumbnailsService.GetThumbnailAsync(query.Path!, query.Quality, cancellationToken);
return await ValueTask.FromResult(getThumbnailResult.Match(value => Result.From(value.ToResponse()), errors => errors));
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
@@ -23,7 +23,7 @@ namespace Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApp
/// <summary>
/// Handler for the command to perform the initial application setup.
/// </summary>
public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCommand, ErrorOr<RegistrationResponse>>
public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCommand, Result<RegistrationResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IPasswordHashService _hashService;
@@ -71,9 +71,9 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
/// <param name="command">The request to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="RegistrationResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="RegistrationResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<RegistrationResponse>> HandleAsync(SetupApplicationCommand command, CancellationToken cancellationToken)
public async Task<Result<RegistrationResponse>> HandleAsync(SetupApplicationCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -81,8 +81,8 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
// check if any users already exists (admin account is only set once!)
IUserRepository userRepository = _unitOfWork.GetRepository<IUserRepository>();
ErrorOr<IEnumerable<UserEntity>> selectUsersResult = await userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
if (selectUsersResult.IsError)
Result<IEnumerable<UserEntity>> selectUsersResult = await userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
if (selectUsersResult.IsFailure)
return selectUsersResult.Errors;
else if (selectUsersResult.Value.Any())
return Errors.Authorization.AdminAccountAlreadyCreated;
@@ -112,26 +112,26 @@ public class SetupApplicationCommandHandler : ICommandHandler<SetupApplicationCo
user.TotpSecret = _cryptographyService.Encrypt(Convert.ToBase64String(secret));
}
// insert the user
ErrorOr<Created> insertUserResult = await userRepository.InsertAsync(user, cancellationToken).ConfigureAwait(false);
if (insertUserResult.IsError)
Result<Created> insertUserResult = await userRepository.InsertAsync(user, cancellationToken).ConfigureAwait(false);
if (insertUserResult.IsFailure)
return insertUserResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// set the default permissions, roles, roles permissions
ErrorOr<Created> setPermissionsResult = await _dataSeedService.SetDefaultAuthorizationPermissionsAsync(id, cancellationToken).ConfigureAwait(false);
if (setPermissionsResult.IsError)
Result<Created> setPermissionsResult = await _dataSeedService.SetDefaultAuthorizationPermissionsAsync(id, cancellationToken).ConfigureAwait(false);
if (setPermissionsResult.IsFailure)
return setPermissionsResult.Errors;
ErrorOr<Created> setRoleResult = await _dataSeedService.SetDefaultAuthorizationRolesAsync(id, cancellationToken).ConfigureAwait(false);
if (setRoleResult.IsError)
Result<Created> setRoleResult = await _dataSeedService.SetDefaultAuthorizationRolesAsync(id, cancellationToken).ConfigureAwait(false);
if (setRoleResult.IsFailure)
return setRoleResult.Errors;
ErrorOr<Created> setRolePermissionResult = await _dataSeedService.SetAdminRolePermissionsAsync(id, cancellationToken).ConfigureAwait(false);
if (setRolePermissionResult.IsError)
Result<Created> setRolePermissionResult = await _dataSeedService.SetAdminRolePermissionsAsync(id, cancellationToken).ConfigureAwait(false);
if (setRolePermissionResult.IsFailure)
return setRolePermissionResult.Errors;
ErrorOr<Created> setRoleToAdminResult = await _dataSeedService.SetAdminRoleToAdministratorAccount(id, cancellationToken).ConfigureAwait(false);
if (setRoleToAdminResult.IsError)
Result<Created> setRoleToAdminResult = await _dataSeedService.SetAdminRoleToAdministratorAccount(id, cancellationToken).ConfigureAwait(false);
if (setRoleToAdminResult.IsFailure)
return setRoleToAdminResult.Errors;
// TODO: insert the default admin profile preferences when they are implemented
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Users;
@@ -40,8 +40,8 @@ public class CheckInitializationQueryHandler : IQueryHandler<CheckInitialization
{
IUserRepository userRepository = _unitOfWork.GetRepository<IUserRepository>();
// if the repository reports an error, or there are no users, the application has not been initialized
ErrorOr<IEnumerable<UserEntity>> selectUsersResult = await userRepository.GetAllAsync(cancellationToken);
if (!selectUsersResult.IsError)
Result<IEnumerable<UserEntity>> selectUsersResult = await userRepository.GetAllAsync(cancellationToken);
if (!selectUsersResult.IsFailure)
return new InitializationResponse(selectUsersResult.Value.Any());
return new InitializationResponse(false);
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -23,7 +23,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
@@ -31,7 +31,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
/// <summary>
/// Handler for the command to add a media library.
/// </summary>
public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, ErrorOr<LibraryResponse>>
public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Result<LibraryResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -71,9 +71,9 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Error
/// <param name="command">The command to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<LibraryResponse>> HandleAsync(AddLibraryCommand command, CancellationToken cancellationToken)
public async Task<Result<LibraryResponse>> HandleAsync(AddLibraryCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -87,19 +87,19 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Error
// make sure the file is an actual supported image
if (command.CoverImage is not null)
{
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(command.CoverImage);
if (fileSystemPathIdResult.IsError)
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(command.CoverImage);
if (fileSystemPathIdResult.IsFailure)
return fileSystemPathIdResult.Errors;
ErrorOr<ImageType> imageCheckResult = await _environmentContext.FileTypeService.GetImageTypeAsync(fileSystemPathIdResult.Value, cancellationToken).ConfigureAwait(false);
if (imageCheckResult.IsError)
Result<ImageType> imageCheckResult = await _environmentContext.FileTypeService.GetImageTypeAsync(fileSystemPathIdResult.Value, cancellationToken).ConfigureAwait(false);
if (imageCheckResult.IsFailure)
return imageCheckResult.Errors;
if (imageCheckResult.Value == ImageType.None)
return DomainErrors.Library.CoverFileMustBeAnImage;
}
// create a domain library object
ErrorOr<Library> createLibraryResult = Library.Create(
Result<Library> createLibraryResult = Library.Create(
UserId.Create(_currentUserService.UserId!.Value),
command.Title!,
Enum.Parse<LibraryType>(command.LibraryType!),
@@ -113,7 +113,7 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Error
[]
);
if (createLibraryResult.IsError)
if (createLibraryResult.IsFailure)
return createLibraryResult.Errors;
// get a library repository
@@ -121,14 +121,14 @@ public class AddLibraryCommandHandler : ICommandHandler<AddLibraryCommand, Error
// convert the domain library entity to a repository library entity
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
// insert the repository entity and save changes
ErrorOr<Created> insertLibraryResult = await libraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (insertLibraryResult.IsError)
Result<Created> insertLibraryResult = await libraryRepository.InsertAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (insertLibraryResult.IsFailure)
return insertLibraryResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// retrieve the newly saved media library from the persistence medium and return it
ErrorOr<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
if (getCreatedLibraryResult.IsError)
Result<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
if (getCreatedLibraryResult.IsFailure)
return getCreatedLibraryResult.Errors;
if (getCreatedLibraryResult.Value is null)
return ApplicationErrors.Persistence.ErrorPersistingMediaLibrary;
@@ -2,7 +2,7 @@
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrari
/// <summary>
/// Handler for the command for canceling the scan of all media libraries.
/// </summary>
public class CancelLibrariesScanCommandHandler : ICommandHandler<CancelLibrariesScanCommand, ErrorOr<Success>>
public class CancelLibrariesScanCommandHandler : ICommandHandler<CancelLibrariesScanCommand, Result<Success>>
{
private readonly ICurrentUserService _currentUserService;
private readonly IAuthorizationService _authorizationService;
@@ -53,14 +53,14 @@ public class CancelLibrariesScanCommandHandler : ICommandHandler<CancelLibraries
/// </summary>
/// <param name="command">The command to be handled.</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>> HandleAsync(CancelLibrariesScanCommand command, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Success>> HandleAsync(CancelLibrariesScanCommand command, CancellationToken cancellationToken)
{
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// get the running library scans of the current user from the repository
ErrorOr<IEnumerable<LibraryScanEntity>> getRunningLibraryScansResult = await libraryScanRepository.GetRunningScansAsync(cancellationToken).ConfigureAwait(false);
if (getRunningLibraryScansResult.IsError)
Result<IEnumerable<LibraryScanEntity>> getRunningLibraryScansResult = await libraryScanRepository.GetRunningScansAsync(cancellationToken).ConfigureAwait(false);
if (getRunningLibraryScansResult.IsFailure)
return getRunningLibraryScansResult.Errors;
// filter the library scans to process
@@ -72,24 +72,24 @@ public class CancelLibrariesScanCommandHandler : ICommandHandler<CancelLibraries
authorizedLibraryScans.AddRange(getRunningLibraryScansResult.Value.Where(libraryScan => libraryScan.UserId == _currentUserService.UserId));
// convert persistence library scans to domain entities
IEnumerable<ErrorOr<LibraryScan>> libraryScansDomainResult = authorizedLibraryScans.ToDomainEntities();
IEnumerable<Result<LibraryScan>> libraryScansDomainResult = authorizedLibraryScans.ToDomainEntities();
List<IDomainEvent> domainEvents = [];
// for each library scan, perform the cancellation
foreach (ErrorOr<LibraryScan> libraryScanDomainResult in libraryScansDomainResult)
foreach (Result<LibraryScan> libraryScanDomainResult in libraryScansDomainResult)
{
if (libraryScanDomainResult.IsError)
if (libraryScanDomainResult.IsFailure)
return libraryScanDomainResult.Errors;
// cancel the media library scan
ErrorOr<Success> cancelScanResult = libraryScanDomainResult.Value.CancelScan();
if (cancelScanResult.IsError)
Result<Success> cancelScanResult = libraryScanDomainResult.Value.CancelScan();
if (cancelScanResult.IsFailure)
return cancelScanResult.Errors;
// update the status of the library scan in the repository
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsError)
Result<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsFailure)
return updateLibraryScanResult.Errors;
// collect all the domain events created during this library scan start
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -15,7 +15,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
@@ -23,7 +23,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrary
/// <summary>
/// Handler for the command for canceling the scan of a media library.
/// </summary>
public class CancelLibraryScanCommandHandler : ICommandHandler<CancelLibraryScanCommand, ErrorOr<Success>>
public class CancelLibraryScanCommandHandler : ICommandHandler<CancelLibraryScanCommand, Result<Success>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -58,8 +58,8 @@ public class CancelLibraryScanCommandHandler : ICommandHandler<CancelLibraryScan
/// </summary>
/// <param name="command">The command to be handled.</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>> HandleAsync(CancelLibraryScanCommand command, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Success>> HandleAsync(CancelLibraryScanCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -68,8 +68,8 @@ public class CancelLibraryScanCommandHandler : ICommandHandler<CancelLibraryScan
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// get the library scan from the repository
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsError)
Result<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(command.ScanId, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsFailure)
return getLibraryScansResult.Errors;
if (getLibraryScansResult.Value is null)
return DomainErrors.LibraryScanning.LibraryScanNotFound;
@@ -80,18 +80,18 @@ public class CancelLibraryScanCommandHandler : ICommandHandler<CancelLibraryScan
return ApplicationErrors.Authorization.NotAuthorized;
// convert the repository scan to a domain object
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsError)
Result<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
return libraryScanDomainResult.Errors;
// cancel the media library scan
ErrorOr<Success> cancelScanResult = libraryScanDomainResult.Value.CancelScan();
if (cancelScanResult.IsError)
Result<Success> cancelScanResult = libraryScanDomainResult.Value.CancelScan();
if (cancelScanResult.IsFailure)
return cancelScanResult.Errors;
// update the status of the library scan in the repository
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsError)
Result<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsFailure)
return updateLibraryScanResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -15,7 +15,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary;
@@ -23,7 +23,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary
/// <summary>
/// Handler for the command to delete a library by its Id.
/// </summary>
public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand, ErrorOr<Deleted>>
public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand, Result<Deleted>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -58,8 +58,8 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
/// </summary>
/// <param name="command">The command to be handled.</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>> HandleAsync(DeleteLibraryCommand command, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Deleted>> HandleAsync(DeleteLibraryCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -67,8 +67,8 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
// get the library with the specified id from the repository
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsError)
Result<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
return getLibraryResult.Errors;
else if (getLibraryResult.Value is null)
return DomainErrors.Library.LibraryNotFound;
@@ -79,13 +79,13 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
return ApplicationErrors.Authorization.NotAuthorized;
// create a domain library object
ErrorOr<Library> createLibraryResult = getLibraryResult.Value.ToDomainEntity();
if (createLibraryResult.IsError)
Result<Library> createLibraryResult = getLibraryResult.Value.ToDomainEntity();
if (createLibraryResult.IsFailure)
return createLibraryResult.Errors;
// delete the domain aggregate
ErrorOr<Deleted> deleteDomainLibraryResult = createLibraryResult.Value.Delete();
if (deleteDomainLibraryResult.IsError)
Result<Deleted> deleteDomainLibraryResult = createLibraryResult.Value.Delete();
if (deleteDomainLibraryResult.IsFailure)
return deleteDomainLibraryResult.Errors;
// queue any domain events
@@ -93,8 +93,8 @@ public class DeleteLibraryCommandHandler : ICommandHandler<DeleteLibraryCommand,
_domainEventsQueue.Enqueue(domainEvent);
// perform the deletion
ErrorOr<Deleted> deletePersistenceLibraryResult = await libraryRepository.DeleteByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (deletePersistenceLibraryResult.IsError)
Result<Deleted> deletePersistenceLibraryResult = await libraryRepository.DeleteByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (deletePersistenceLibraryResult.IsFailure)
return deletePersistenceLibraryResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -25,7 +25,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibraries
/// <summary>
/// Handler for the command for initiating the scan of all media libraries.
/// </summary>
public class ScanLibrariesCommandHandler : ICommandHandler<ScanLibrariesCommand, ErrorOr<IEnumerable<MediaLibraryScanResponse>>>
public class ScanLibrariesCommandHandler : ICommandHandler<ScanLibrariesCommand, Result<IEnumerable<MediaLibraryScanResponse>>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -56,19 +56,19 @@ public class ScanLibrariesCommandHandler : ICommandHandler<ScanLibrariesCommand,
/// </summary>
/// <param name="command">The command to be handled.</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<IEnumerable<MediaLibraryScanResponse>>> HandleAsync(ScanLibrariesCommand command, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<IEnumerable<MediaLibraryScanResponse>>> HandleAsync(ScanLibrariesCommand command, CancellationToken cancellationToken)
{
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// get all media libraries that are enabled and unlocked from the persistence medium
ErrorOr<IEnumerable<LibraryEntity>> getLibrariesResult = await libraryRepository.GetAllEnabledAndUnlockedAsync(cancellationToken).ConfigureAwait(false);
if (getLibrariesResult.IsError)
Result<IEnumerable<LibraryEntity>> getLibrariesResult = await libraryRepository.GetAllEnabledAndUnlockedAsync(cancellationToken).ConfigureAwait(false);
if (getLibrariesResult.IsFailure)
return getLibrariesResult.Errors;
// convert persistence libraries to domain entities
IEnumerable<ErrorOr<Library>> domainEntitiesResult = getLibrariesResult.Value.ToDomainEntities();
IEnumerable<Result<Library>> domainEntitiesResult = getLibrariesResult.Value.ToDomainEntities();
// if the current user is not an admin, they can only scan the libraries that belong to them
if (!await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
@@ -78,41 +78,41 @@ public class ScanLibrariesCommandHandler : ICommandHandler<ScanLibrariesCommand,
List<IDomainEvent> domainEvents = [];
// for each library, start the scan
foreach (ErrorOr<Library> domainLibraryResult in domainEntitiesResult)
foreach (Result<Library> domainLibraryResult in domainEntitiesResult)
{
if (domainLibraryResult.IsError)
if (domainLibraryResult.IsFailure)
return domainLibraryResult.Errors;
// get the past month's scans for this library
ErrorOr<IEnumerable<LibraryScanEntity>> pastLibraryScansResult =
Result<IEnumerable<LibraryScanEntity>> pastLibraryScansResult =
await libraryScanRepository.GetPastMonthScansByLibraryIdAsync(domainLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
if (pastLibraryScansResult.IsError)
if (pastLibraryScansResult.IsFailure)
return pastLibraryScansResult.Errors;
// convert the repository scans history to domain objects
IEnumerable<ErrorOr<LibraryScan>> pastLibraryScansDomainResult = pastLibraryScansResult.Value.ToDomainEntities();
foreach (ErrorOr<LibraryScan> pastLibraryScanDomainResult in pastLibraryScansDomainResult)
if (pastLibraryScanDomainResult.IsError)
IEnumerable<Result<LibraryScan>> pastLibraryScansDomainResult = pastLibraryScansResult.Value.ToDomainEntities();
foreach (Result<LibraryScan> pastLibraryScanDomainResult in pastLibraryScansDomainResult)
if (pastLibraryScanDomainResult.IsFailure)
return pastLibraryScanDomainResult.Errors;
// start the media library scan
ErrorOr<LibraryScan> libraryScanResult = LibraryScan.Create(
Result<LibraryScan> libraryScanResult = LibraryScan.Create(
LibraryId.Create(domainLibraryResult.Value.Id.Value),
UserId.Create(_currentUserService.UserId!.Value),
[.. pastLibraryScansDomainResult.Select(pastLibraryScanDomainResult => pastLibraryScanDomainResult.Value)]
);
if (libraryScanResult.IsError)
if (libraryScanResult.IsFailure)
return libraryScanResult.Errors;
ErrorOr<Success> startScanResult = libraryScanResult.Value.QueueScan();
Result<Success> startScanResult = libraryScanResult.Value.QueueScan();
// when the user demands a "scan all libraries" action, it would be annoying to receive an error if a library is already being scanned.
// instead, just don't start the scan on such a library, and start it on the others that can be started
if (startScanResult.IsError)
if (startScanResult.IsFailure)
continue;
// add the library scan to the persistence medium
ErrorOr<Created> insertLibraryScanResult = await libraryScanRepository.InsertAsync(libraryScanResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (insertLibraryScanResult.IsError)
Result<Created> insertLibraryScanResult = await libraryScanRepository.InsertAsync(libraryScanResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (insertLibraryScanResult.IsFailure)
return insertLibraryScanResult.Errors;
// collect all the domain events created during this library scan start
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -21,7 +21,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
@@ -29,7 +29,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
/// <summary>
/// Handler for the command for initiating the scan of a media library.
/// </summary>
public class ScanLibraryCommandHandler : ICommandHandler<ScanLibraryCommand, ErrorOr<MediaLibraryScanResponse>>
public class ScanLibraryCommandHandler : ICommandHandler<ScanLibraryCommand, Result<MediaLibraryScanResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -64,8 +64,8 @@ public class ScanLibraryCommandHandler : ICommandHandler<ScanLibraryCommand, Err
/// </summary>
/// <param name="command">The command to be handled.</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<MediaLibraryScanResponse>> HandleAsync(ScanLibraryCommand command, CancellationToken cancellationToken)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<MediaLibraryScanResponse>> HandleAsync(ScanLibraryCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -75,8 +75,8 @@ public class ScanLibraryCommandHandler : ICommandHandler<ScanLibraryCommand, Err
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// get the media library from the persistence medium
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsError)
Result<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
return getLibraryResult.Errors;
if (getLibraryResult.Value is null)
@@ -95,37 +95,37 @@ public class ScanLibraryCommandHandler : ICommandHandler<ScanLibraryCommand, Err
return DomainErrors.Library.CannotScanLockedLibrary;
// convert the persistence library to a domain entity
ErrorOr<Library> domainLibraryResult = getLibraryResult.Value.ToDomainEntity();
if (domainLibraryResult.IsError)
Result<Library> domainLibraryResult = getLibraryResult.Value.ToDomainEntity();
if (domainLibraryResult.IsFailure)
return domainLibraryResult.Errors;
// get the past month's scans for this library
ErrorOr<IEnumerable<LibraryScanEntity>> pastLibraryScansResult = await libraryScanRepository.GetPastMonthScansByLibraryIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (pastLibraryScansResult.IsError)
Result<IEnumerable<LibraryScanEntity>> pastLibraryScansResult = await libraryScanRepository.GetPastMonthScansByLibraryIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (pastLibraryScansResult.IsFailure)
return pastLibraryScansResult.Errors;
// convert the repository scans history to domain objects
IEnumerable<ErrorOr<LibraryScan>> pastLibraryScansDomainResult = pastLibraryScansResult.Value.ToDomainEntities();
foreach (ErrorOr<LibraryScan> pastLibraryScanDomainResult in pastLibraryScansDomainResult)
if (pastLibraryScanDomainResult.IsError)
IEnumerable<Result<LibraryScan>> pastLibraryScansDomainResult = pastLibraryScansResult.Value.ToDomainEntities();
foreach (Result<LibraryScan> pastLibraryScanDomainResult in pastLibraryScansDomainResult)
if (pastLibraryScanDomainResult.IsFailure)
return pastLibraryScanDomainResult.Errors;
// queue the media library scan
ErrorOr<LibraryScan> libraryScanResult = LibraryScan.Create(
Result<LibraryScan> libraryScanResult = LibraryScan.Create(
LibraryId.Create(command.Id),
UserId.Create(_currentUserService.UserId!.Value),
[.. pastLibraryScansDomainResult.Select(pastLibraryScanDomainResult => pastLibraryScanDomainResult.Value)]
);
if (libraryScanResult.IsError)
if (libraryScanResult.IsFailure)
return libraryScanResult.Errors;
ErrorOr<Success> queueScanResult = libraryScanResult.Value.QueueScan();
if (queueScanResult.IsError)
Result<Success> queueScanResult = libraryScanResult.Value.QueueScan();
if (queueScanResult.IsFailure)
return queueScanResult.Errors;
// add the library scan to the persistence medium
ErrorOr<Created> insertLibraryScanResult = await libraryScanRepository.InsertAsync(libraryScanResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (insertLibraryScanResult.IsError)
Result<Created> insertLibraryScanResult = await libraryScanRepository.InsertAsync(libraryScanResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (insertLibraryScanResult.IsFailure)
return insertLibraryScanResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -26,7 +26,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
@@ -34,7 +34,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
/// <summary>
/// Handler for the command to update a media library.
/// </summary>
public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand, ErrorOr<LibraryResponse>>
public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand, Result<LibraryResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -74,9 +74,9 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
/// <param name="command">The command to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully updated <see cref="LibraryResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully updated <see cref="LibraryResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<LibraryResponse>> HandleAsync(UpdateLibraryCommand command, CancellationToken cancellationToken)
public async Task<Result<LibraryResponse>> HandleAsync(UpdateLibraryCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -85,12 +85,12 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
// make sure the file is an actual supported image
if (command.CoverImage is not null)
{
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(command.CoverImage);
if (fileSystemPathIdResult.IsError)
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(command.CoverImage);
if (fileSystemPathIdResult.IsFailure)
return fileSystemPathIdResult.Errors;
ErrorOr<ImageType> imageCheckResult = await _environmentContext.FileTypeService.GetImageTypeAsync(fileSystemPathIdResult.Value, cancellationToken).ConfigureAwait(false);
if (imageCheckResult.IsError)
Result<ImageType> imageCheckResult = await _environmentContext.FileTypeService.GetImageTypeAsync(fileSystemPathIdResult.Value, cancellationToken).ConfigureAwait(false);
if (imageCheckResult.IsFailure)
return imageCheckResult.Errors;
if (imageCheckResult.Value == ImageType.None)
return DomainErrors.Library.CoverFileMustBeAnImage;
@@ -98,8 +98,8 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
// get a library repository and retrieve the library to update
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsError)
Result<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(command.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
return getLibraryResult.Errors;
else if (getLibraryResult.Value is null)
return DomainErrors.Library.LibraryNotFound;
@@ -111,7 +111,7 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
return ApplicationErrors.Authorization.NotAuthorized;
// create a domain library object
ErrorOr<Library> createLibraryResult = Library.Create(
Result<Library> createLibraryResult = Library.Create(
LibraryId.Create(command.Id),
UserId.Create(command.OwnerId),
command.Title!,
@@ -125,20 +125,20 @@ public class UpdateLibraryCommandHandler : ICommandHandler<UpdateLibraryCommand,
command.ShouldSkipUnchangedDirectoriesDuringScan,
getLibraryResult.Value.LibraryScans.Select(libraryScan => ScanId.Create(libraryScan.Id)).ToList()
);
if (createLibraryResult.IsError)
if (createLibraryResult.IsFailure)
return createLibraryResult.Errors;
// convert the domain library entity to a repository library entity
LibraryEntity persistenceLibrary = createLibraryResult.Value.ToRepositoryEntity();
// update the repository entity and save changes
ErrorOr<Updated> updateLibraryResult = await libraryRepository.UpdateAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (updateLibraryResult.IsError)
Result<Updated> updateLibraryResult = await libraryRepository.UpdateAsync(persistenceLibrary, cancellationToken).ConfigureAwait(false);
if (updateLibraryResult.IsFailure)
return updateLibraryResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
// retrieve the updated media library from the persistence medium and return it
ErrorOr<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
if (getCreatedLibraryResult.IsError)
Result<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
if (getCreatedLibraryResult.IsFailure)
return getCreatedLibraryResult.Errors;
if (getCreatedLibraryResult.Value is null)
return ApplicationErrors.Persistence.ErrorPersistingMediaLibrary;
@@ -2,7 +2,7 @@
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
@@ -45,16 +45,16 @@ public class LibraryDeletedDomainEventHandler : IDomainEventHandler<LibraryDelet
public ValueTask HandleAsync(LibraryDeletedDomainEvent domainEvent, CancellationToken cancellationToken)
{
// delete the media library directory in the internal location for media library files
ErrorOr<string> libraryPathResult = GetLibraryPath(domainEvent.Library.Id.Value);
if (libraryPathResult.IsError)
Result<string> libraryPathResult = GetLibraryPath(domainEvent.Library.Id.Value);
if (libraryPathResult.IsFailure)
throw new EventualConsistencyException(libraryPathResult.FirstError, libraryPathResult.Errors);
ErrorOr<FileSystemPathId> newLibraryPathIdResult = FileSystemPathId.Create(libraryPathResult.Value);
if (newLibraryPathIdResult.IsError)
Result<FileSystemPathId> newLibraryPathIdResult = FileSystemPathId.Create(libraryPathResult.Value);
if (newLibraryPathIdResult.IsFailure)
throw new EventualConsistencyException(newLibraryPathIdResult.FirstError, newLibraryPathIdResult.Errors);
ErrorOr<Deleted> deleteLibraryDirectoryResult = _environmentContext.DirectoryProviderService.DeleteDirectory(newLibraryPathIdResult.Value);
if (deleteLibraryDirectoryResult.IsError)
Result<Deleted> deleteLibraryDirectoryResult = _environmentContext.DirectoryProviderService.DeleteDirectory(newLibraryPathIdResult.Value);
if (deleteLibraryDirectoryResult.IsFailure)
throw new EventualConsistencyException(deleteLibraryDirectoryResult.FirstError, deleteLibraryDirectoryResult.Errors);
return ValueTask.CompletedTask;
@@ -65,23 +65,23 @@ public class LibraryDeletedDomainEventHandler : IDomainEventHandler<LibraryDelet
/// </summary>
/// <param name="libraryId">The id of the media library for which to regtrieve the file system path.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either the file system path of the media library, or an error message.
/// An <see cref="Result{TValue}"/> containing either the file system path of the media library, or an error message.
/// </returns>
private ErrorOr<string> GetLibraryPath(Guid libraryId)
private Result<string> GetLibraryPath(Guid libraryId)
{
// root directory for media
ErrorOr<string> rootPathResult = _pathService.CombinePath(AppContext.BaseDirectory, _mediaSettingsModel.RootDirectory);
if (rootPathResult.IsError)
Result<string> rootPathResult = _pathService.CombinePath(AppContext.BaseDirectory, _mediaSettingsModel.RootDirectory);
if (rootPathResult.IsFailure)
return rootPathResult.Errors;
// libraries directory
ErrorOr<string> librariesPathResult = _pathService.CombinePath(rootPathResult.Value, _mediaSettingsModel.LibrariesDirectory);
if (librariesPathResult.IsError)
Result<string> librariesPathResult = _pathService.CombinePath(rootPathResult.Value, _mediaSettingsModel.LibrariesDirectory);
if (librariesPathResult.IsFailure)
return librariesPathResult.Errors;
// this new particular library' directory
ErrorOr<string> libraryPathResult = _pathService.CombinePath(librariesPathResult.Value, libraryId.ToString());
if (libraryPathResult.IsError)
Result<string> libraryPathResult = _pathService.CombinePath(librariesPathResult.Value, libraryId.ToString());
if (libraryPathResult.IsFailure)
return libraryPathResult.Errors;
return libraryPathResult.Value;
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
@@ -61,22 +61,22 @@ public class LibrarySavedDomainEventHandler : IDomainEventHandler<LibrarySavedDo
if (domainEvent.Library.CoverImage is not null)
{
// attempt to copy the image from the original location provided by the user to the internal location for media library files
ErrorOr<string> saveCoverImageResult = await SaveCoverImageToMediaDirectoryAsync(domainEvent.Library.Id.Value, domainEvent.Library.CoverImage, cancellationToken).ConfigureAwait(false);
if (saveCoverImageResult.IsError)
Result<string> saveCoverImageResult = await SaveCoverImageToMediaDirectoryAsync(domainEvent.Library.Id.Value, domainEvent.Library.CoverImage, cancellationToken).ConfigureAwait(false);
if (saveCoverImageResult.IsFailure)
throw new EventualConsistencyException(saveCoverImageResult.FirstError, saveCoverImageResult.Errors);
domainEvent.Library.SetInternalLibraryCoverImagePath(saveCoverImageResult.Value);
// update the media library with the new cover location
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<Updated> updateLibraryResult = await libraryRepository.UpdateAsync(domainEvent.Library.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryResult.IsError)
Result<Updated> updateLibraryResult = await libraryRepository.UpdateAsync(domainEvent.Library.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryResult.IsFailure)
throw new EventualConsistencyException(updateLibraryResult.FirstError, updateLibraryResult.Errors);
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
else // no cover image is provided, delete any cover image that might exist in the internal location for media library files
{
ErrorOr<string> libraryPathResult = GetLibraryPath(domainEvent.Library.Id.Value);
if (libraryPathResult.IsError)
Result<string> libraryPathResult = GetLibraryPath(domainEvent.Library.Id.Value);
if (libraryPathResult.IsFailure)
throw new EventualConsistencyException(libraryPathResult.FirstError, libraryPathResult.Errors);
DeleteCoverImageFromMediaDirectory(libraryPathResult.Value);
}
@@ -87,23 +87,23 @@ public class LibrarySavedDomainEventHandler : IDomainEventHandler<LibrarySavedDo
/// </summary>
/// <param name="libraryId">The id of the media library for which to regtrieve the file system path.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either the file system path of the media library, or an error message.
/// An <see cref="Result{TValue}"/> containing either the file system path of the media library, or an error message.
/// </returns>
private ErrorOr<string> GetLibraryPath(Guid libraryId)
private Result<string> GetLibraryPath(Guid libraryId)
{
// root directory for media
ErrorOr<string> rootPathResult = _pathService.CombinePath(AppContext.BaseDirectory, _mediaSettingsModel.RootDirectory);
if (rootPathResult.IsError)
Result<string> rootPathResult = _pathService.CombinePath(AppContext.BaseDirectory, _mediaSettingsModel.RootDirectory);
if (rootPathResult.IsFailure)
return rootPathResult.Errors;
// libraries directory
ErrorOr<string> librariesPathResult = _pathService.CombinePath(rootPathResult.Value, _mediaSettingsModel.LibrariesDirectory);
if (librariesPathResult.IsError)
Result<string> librariesPathResult = _pathService.CombinePath(rootPathResult.Value, _mediaSettingsModel.LibrariesDirectory);
if (librariesPathResult.IsFailure)
return librariesPathResult.Errors;
// this new particular library' directory
ErrorOr<string> libraryPathResult = _pathService.CombinePath(librariesPathResult.Value, libraryId.ToString());
if (libraryPathResult.IsError)
Result<string> libraryPathResult = _pathService.CombinePath(librariesPathResult.Value, libraryId.ToString());
if (libraryPathResult.IsFailure)
return libraryPathResult.Errors;
return libraryPathResult.Value;
}
@@ -115,62 +115,62 @@ public class LibrarySavedDomainEventHandler : IDomainEventHandler<LibrarySavedDo
/// <param name="imagePath">The file path of the image file that will be copied to the media directory.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either the location of the new cover image, or an error message.
/// An <see cref="Result{TValue}"/> containing either the location of the new cover image, or an error message.
/// </returns>
private async Task<ErrorOr<string>> SaveCoverImageToMediaDirectoryAsync(Guid libraryId, string imagePath, CancellationToken cancellationToken)
private async Task<Result<string>> SaveCoverImageToMediaDirectoryAsync(Guid libraryId, string imagePath, CancellationToken cancellationToken)
{
ErrorOr<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(imagePath);
if (fileSystemPathIdResult.IsError)
Result<FileSystemPathId> fileSystemPathIdResult = FileSystemPathId.Create(imagePath);
if (fileSystemPathIdResult.IsFailure)
return fileSystemPathIdResult.Errors;
ErrorOr<bool> fileExistsResult = _environmentContext.FileProviderService.FileExists(fileSystemPathIdResult.Value);
if (fileExistsResult.IsError)
Result<bool> fileExistsResult = _environmentContext.FileProviderService.FileExists(fileSystemPathIdResult.Value);
if (fileExistsResult.IsFailure)
return fileExistsResult.Errors;
if (!fileExistsResult.Value)
return Errors.FileSystemManagement.FileNotFound;
// make sure the file is an actual supported image
ErrorOr<ImageType> imageCheckResult = await _environmentContext.FileTypeService.GetImageTypeAsync(fileSystemPathIdResult.Value, cancellationToken).ConfigureAwait(false);
if (imageCheckResult.IsError)
Result<ImageType> imageCheckResult = await _environmentContext.FileTypeService.GetImageTypeAsync(fileSystemPathIdResult.Value, cancellationToken).ConfigureAwait(false);
if (imageCheckResult.IsFailure)
return imageCheckResult.Errors;
if (imageCheckResult.Value == ImageType.None)
return Errors.Library.CoverFileMustBeAnImage;
// the provided cover image path exists and is a valid image, store it in the media directory
ErrorOr<string> rootPathResult = _pathService.CombinePath(AppContext.BaseDirectory, _mediaSettingsModel.RootDirectory); // root directory for media
if (rootPathResult.IsError)
Result<string> rootPathResult = _pathService.CombinePath(AppContext.BaseDirectory, _mediaSettingsModel.RootDirectory); // root directory for media
if (rootPathResult.IsFailure)
return rootPathResult.Errors;
ErrorOr<string> librariesPathResult = _pathService.CombinePath(rootPathResult.Value, _mediaSettingsModel.LibrariesDirectory); // libraries directory
if (librariesPathResult.IsError)
Result<string> librariesPathResult = _pathService.CombinePath(rootPathResult.Value, _mediaSettingsModel.LibrariesDirectory); // libraries directory
if (librariesPathResult.IsFailure)
return librariesPathResult.Errors;
ErrorOr<FileSystemPathId> rootPathIdResult = FileSystemPathId.Create(rootPathResult.Value);
if (rootPathIdResult.IsError)
Result<FileSystemPathId> rootPathIdResult = FileSystemPathId.Create(rootPathResult.Value);
if (rootPathIdResult.IsFailure)
return rootPathIdResult.Errors;
ErrorOr<FileSystemPathId> librariesPathIdResult = FileSystemPathId.Create(librariesPathResult.Value);
if (librariesPathIdResult.IsError)
Result<FileSystemPathId> librariesPathIdResult = FileSystemPathId.Create(librariesPathResult.Value);
if (librariesPathIdResult.IsFailure)
return librariesPathIdResult.Errors;
// create the path of the new library
ErrorOr<string> libraryPathResult = GetLibraryPath(libraryId);
if (libraryPathResult.IsError)
Result<string> libraryPathResult = GetLibraryPath(libraryId);
if (libraryPathResult.IsFailure)
return libraryPathResult.Errors;
ErrorOr<FileSystemPathId> newLibraryPathIdResult = FileSystemPathId.Create(libraryPathResult.Value);
if (newLibraryPathIdResult.IsError)
Result<FileSystemPathId> newLibraryPathIdResult = FileSystemPathId.Create(libraryPathResult.Value);
if (newLibraryPathIdResult.IsFailure)
return newLibraryPathIdResult.Errors;
// check if it doesn't already exist, and if so, create it
ErrorOr<bool> directoryExistsResult = _environmentContext.DirectoryProviderService.DirectoryExists(newLibraryPathIdResult.Value);
if (directoryExistsResult.IsError)
Result<bool> directoryExistsResult = _environmentContext.DirectoryProviderService.DirectoryExists(newLibraryPathIdResult.Value);
if (directoryExistsResult.IsFailure)
return directoryExistsResult.Errors;
if (!directoryExistsResult.Value)
{
ErrorOr<FileSystemPathId> createDirectoryResult = _environmentContext.DirectoryProviderService.CreateDirectory(librariesPathIdResult.Value, libraryId.ToString());
if (createDirectoryResult.IsError)
Result<FileSystemPathId> createDirectoryResult = _environmentContext.DirectoryProviderService.CreateDirectory(librariesPathIdResult.Value, libraryId.ToString());
if (createDirectoryResult.IsFailure)
return createDirectoryResult.Errors;
}
else
@@ -178,18 +178,18 @@ public class LibrarySavedDomainEventHandler : IDomainEventHandler<LibrarySavedDo
// delete previous library covers that might exist
DeleteCoverImageFromMediaDirectory(libraryPathResult.Value);
ErrorOr<Deleted> deleteExistingCoverImageResult = DeleteCoverImageFromMediaDirectory(libraryPathResult.Value);
if (deleteExistingCoverImageResult.IsError)
Result<Deleted> deleteExistingCoverImageResult = DeleteCoverImageFromMediaDirectory(libraryPathResult.Value);
if (deleteExistingCoverImageResult.IsFailure)
return deleteExistingCoverImageResult.Errors;
}
// copy the new cover file from the location provided by the user
ErrorOr<FileSystemPathId> copyFileResult = _environmentContext.FileProviderService.CopyFile(fileSystemPathIdResult.Value, newLibraryPathIdResult.Value, true);
if (copyFileResult.IsError)
Result<FileSystemPathId> copyFileResult = _environmentContext.FileProviderService.CopyFile(fileSystemPathIdResult.Value, newLibraryPathIdResult.Value, true);
if (copyFileResult.IsFailure)
return copyFileResult.Errors;
// rename the new cover file to the standard naming
ErrorOr<FileSystemPathId> renameFileResult = _environmentContext.FileProviderService.RenameFile(copyFileResult.Value, $"cover.{imageCheckResult.Value.ToString().ToLower()}");
if (renameFileResult.IsError)
Result<FileSystemPathId> renameFileResult = _environmentContext.FileProviderService.RenameFile(copyFileResult.Value, $"cover.{imageCheckResult.Value.ToString().ToLower()}");
if (renameFileResult.IsFailure)
return renameFileResult.Errors;
// get the internal relative path for the copied file
@@ -203,17 +203,17 @@ public class LibrarySavedDomainEventHandler : IDomainEventHandler<LibrarySavedDo
/// Deletes the cover image from the media directory.
/// </summary>
/// <param name="libraryPath">The path where the library content is located.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
private ErrorOr<Deleted> DeleteCoverImageFromMediaDirectory(string libraryPath)
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
private Result<Deleted> DeleteCoverImageFromMediaDirectory(string libraryPath)
{
ErrorOr<FileSystemPathId> newLibraryPathIdResult = FileSystemPathId.Create(libraryPath);
if (newLibraryPathIdResult.IsError)
Result<FileSystemPathId> newLibraryPathIdResult = FileSystemPathId.Create(libraryPath);
if (newLibraryPathIdResult.IsFailure)
return newLibraryPathIdResult.Errors;
// get existing files of this media library's directory, and delete previous cover files, if they are found
ErrorOr<IEnumerable<FileSystemPathId>> getExistingLibraryFilesResult = _environmentContext.FileProviderService.GetFilePaths(newLibraryPathIdResult.Value, true);
if (getExistingLibraryFilesResult.IsError)
Result<IEnumerable<FileSystemPathId>> getExistingLibraryFilesResult = _environmentContext.FileProviderService.GetFilePaths(newLibraryPathIdResult.Value, true);
if (getExistingLibraryFilesResult.IsFailure)
return getExistingLibraryFilesResult.Errors;
foreach (FileSystemPathId filePathId in getExistingLibraryFilesResult.Value)
@@ -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.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
@@ -59,20 +59,20 @@ public class LibraryScanCancelledDomainEventHandler : IDomainEventHandler<Librar
public async ValueTask HandleAsync(LibraryScanCancelledDomainEvent domainEvent, CancellationToken cancellationToken)
{
// get the library scan from the repository
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await _libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsError)
Result<LibraryScanEntity?> getLibraryScansResult = await _libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsFailure)
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
if (getLibraryScansResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository scan to a domain object
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsError)
Result<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
// cancel the media library scan
ErrorOr<Success> cancelScanResult = _mediaLibraryScanningService.CancelScan(libraryScanDomainResult.Value);
if (cancelScanResult.IsError)
Result<Success> cancelScanResult = _mediaLibraryScanningService.CancelScan(libraryScanDomainResult.Value);
if (cancelScanResult.IsFailure)
throw new EventualConsistencyException(cancelScanResult.FirstError, cancelScanResult.Errors);
// release the scan processing resources
@@ -80,8 +80,8 @@ public class LibraryScanCancelledDomainEventHandler : IDomainEventHandler<Librar
MediaLibraryScanCompositeId compositeId = MediaLibraryScanCompositeId.Create(domainEvent.ScanId, UserId.Create(getLibraryScansResult.Value.UserId));
_mediaLibrariesScanCancellationTracker.RemoveScan(compositeId);
_mediaLibrariesScanProgressTracker.RemoveScanProgress(compositeId);
ErrorOr<Success> clearStagingResult = await stagingResultsRepository.ClearForScanAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (clearStagingResult.IsError)
Result<Success> clearStagingResult = await stagingResultsRepository.ClearForScanAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (clearStagingResult.IsFailure)
throw new EventualConsistencyException(clearStagingResult.FirstError, clearStagingResult.Errors);
}
}
@@ -1,11 +1,11 @@
#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.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Progress;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
@@ -58,27 +58,27 @@ public class LibraryScanFailedDomainEventHandler : IDomainEventHandler<LibrarySc
ILibraryScanStagingResultsRepository stagingResultsRepository = _unitOfWork.GetRepository<ILibraryScanStagingResultsRepository>();
// get the library scan from the repository
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(
Result<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(
domainEvent.MediaLibraryScanCompositeId.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsError)
if (getLibraryScansResult.IsFailure)
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
if (getLibraryScansResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository scan to a domain object
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsError)
Result<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
// mark the media library scan as failed
ErrorOr<Success> failScanResult = libraryScanDomainResult.Value.FailScan();
Result<Success> failScanResult = libraryScanDomainResult.Value.FailScan();
// we're going to ignore errors in this point, because scan jobs run in parallel, and two concurrent jobs of the same scan might trigger this domain event,
// trying to set as failed a scan that has already been marked as failed by a concurrent job
if (!failScanResult.IsError)
if (!failScanResult.IsFailure)
{
// update the status of the library scan in the repository
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsError)
Result<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsFailure)
throw new EventualConsistencyException(updateLibraryScanResult.FirstError, updateLibraryScanResult.Errors);
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -87,8 +87,8 @@ public class LibraryScanFailedDomainEventHandler : IDomainEventHandler<LibrarySc
// release the scan processing resources, regardless of whether the scan was already marked as failed by a concurrent job
_mediaLibrariesScanCancellationTracker.RemoveScan(domainEvent.MediaLibraryScanCompositeId);
_mediaLibrariesScanProgressTracker.RemoveScanProgress(domainEvent.MediaLibraryScanCompositeId);
ErrorOr<Success> clearStagingResult = await stagingResultsRepository.ClearForScanAsync(domainEvent.MediaLibraryScanCompositeId.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (clearStagingResult.IsError)
Result<Success> clearStagingResult = await stagingResultsRepository.ClearForScanAsync(domainEvent.MediaLibraryScanCompositeId.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (clearStagingResult.IsFailure)
throw new EventualConsistencyException(clearStagingResult.FirstError, clearStagingResult.Errors);
// notify SignalR clients that the library scan failed
@@ -1,11 +1,11 @@
#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.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Progress;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
@@ -57,26 +57,26 @@ public class LibraryScanFinishedDomainEventHandler : IDomainEventHandler<Library
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// get the library scan from the repository
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(
Result<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(
domainEvent.MediaLibraryScanCompositeId.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsError)
if (getLibraryScansResult.IsFailure)
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
if (getLibraryScansResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository scan to a domain object
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsError)
Result<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
// mark the media library scan as finished
ErrorOr<Success> finishScanResult = libraryScanDomainResult.Value.FinishScan();
if (finishScanResult.IsError)
Result<Success> finishScanResult = libraryScanDomainResult.Value.FinishScan();
if (finishScanResult.IsFailure)
throw new EventualConsistencyException(finishScanResult.FirstError, finishScanResult.Errors);
// update the library scan in the repository
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsError)
Result<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsFailure)
throw new EventualConsistencyException(updateLibraryScanResult.FirstError, updateLibraryScanResult.Errors);
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -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.Application.Common.DataAccess.UoW;
@@ -51,19 +51,19 @@ public class LibraryScanQueuedDomainEventHandler : IDomainEventHandler<LibrarySc
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// get the library scan that was queued, from the repository
ErrorOr<LibraryScanEntity?> getLibraryScanResult = await libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScanResult.IsError || getLibraryScanResult.Value is null)
Result<LibraryScanEntity?> getLibraryScanResult = await libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScanResult.IsFailure || getLibraryScanResult.Value is null)
throw new EventualConsistencyException(getLibraryScanResult.FirstError, getLibraryScanResult.Errors);
// convert the repository entity to a domain entity
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsError)
Result<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
// start the media library scan
ErrorOr<Success> startScanResult = await _mediaLibraryScanningService.StartScanAsync(
Result<Success> startScanResult = await _mediaLibraryScanningService.StartScanAsync(
libraryScanDomainResult.Value, getLibraryScanResult.Value.Library.LibraryType, getLibraryScanResult.Value.Library.DownloadMetadataFromWeb, cancellationToken).ConfigureAwait(false);
if (startScanResult.IsError)
if (startScanResult.IsFailure)
throw new EventualConsistencyException(startScanResult.FirstError, startScanResult.Errors);
// queue any domain events
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
@@ -38,8 +38,8 @@ public class LibraryScanStartedDomainEventHandler : IDomainEventHandler<LibraryS
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
// update the status of the library scan in the repository
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(domainEvent.LibraryScan.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsError)
Result<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(domainEvent.LibraryScan.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateLibraryScanResult.IsFailure)
throw new EventualConsistencyException(updateLibraryScanResult.FirstError, updateLibraryScanResult.Errors);
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetEnabledLibr
/// <summary>
/// Handler for the query to get the enabled media libraries.
/// </summary>
public class GetEnabledLibrariesQueryHandler : IQueryHandler<GetEnabledLibrariesQuery, ErrorOr<LibraryResponse[]>>
public class GetEnabledLibrariesQueryHandler : IQueryHandler<GetEnabledLibrariesQuery, Result<LibraryResponse[]>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -47,19 +47,19 @@ public class GetEnabledLibrariesQueryHandler : IQueryHandler<GetEnabledLibraries
/// <param name="query">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<LibraryResponse[]>> HandleAsync(GetEnabledLibrariesQuery query, CancellationToken cancellationToken)
public async Task<Result<LibraryResponse[]>> HandleAsync(GetEnabledLibrariesQuery query, CancellationToken cancellationToken)
{
// get the enabled libraries from the repository
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<IEnumerable<LibraryEntity>> getEnabledLibrariesResult = await libraryRepository.GetAllEnabledAsync(cancellationToken).ConfigureAwait(false);
if (getEnabledLibrariesResult.IsError)
Result<IEnumerable<LibraryEntity>> getEnabledLibrariesResult = await libraryRepository.GetAllEnabledAsync(cancellationToken).ConfigureAwait(false);
if (getEnabledLibrariesResult.IsFailure)
return getEnabledLibrariesResult.Errors;
// admins can see all libraries
if (await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
return ErrorOrFactory.From(getEnabledLibrariesResult.Value.Select(library => library.ToResponse()).ToArray());
return Result.From(getEnabledLibrariesResult.Value.Select(library => library.ToResponse()).ToArray());
else
{
// for regular users, only take the libraries that belong to them
@@ -67,7 +67,7 @@ public class GetEnabledLibrariesQueryHandler : IQueryHandler<GetEnabledLibraries
.Where(library => library.UserId == _currentUserService.UserId)
.Select(library => library.ToResponse())];
return ErrorOrFactory.From(userEnabledLibraries);
return Result.From(userEnabledLibraries);
}
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraries;
/// <summary>
/// Handler for the query to get the media libraries.
/// </summary>
public class GetLibrariesQueryHandler : IQueryHandler<GetLibrariesQuery, ErrorOr<LibraryResponse[]>>
public class GetLibrariesQueryHandler : IQueryHandler<GetLibrariesQuery, Result<LibraryResponse[]>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -47,19 +47,19 @@ public class GetLibrariesQueryHandler : IQueryHandler<GetLibrariesQuery, ErrorOr
/// <param name="query">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<LibraryResponse[]>> HandleAsync(GetLibrariesQuery query, CancellationToken cancellationToken)
public async Task<Result<LibraryResponse[]>> HandleAsync(GetLibrariesQuery query, CancellationToken cancellationToken)
{
// get the libraries from the repository
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<IEnumerable<LibraryEntity>> getLibrariesResult = await libraryRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
if (getLibrariesResult.IsError)
Result<IEnumerable<LibraryEntity>> getLibrariesResult = await libraryRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
if (getLibrariesResult.IsFailure)
return getLibrariesResult.Errors;
// admins can see all libraries
if (await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
return ErrorOrFactory.From(getLibrariesResult.Value.Select(library => library.ToResponse()).ToArray());
return Result.From(getLibrariesResult.Value.Select(library => library.ToResponse()).ToArray());
else
{
// for regular users, only take the libraries that belong to them
@@ -67,7 +67,7 @@ public class GetLibrariesQueryHandler : IQueryHandler<GetLibrariesQuery, ErrorOr
.Where(library => library.UserId == _currentUserService.UserId)
.Select(library => library.ToResponse())];
return ErrorOrFactory.From(userLibraries);
return Result.From(userLibraries);
}
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -14,7 +14,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
/// <summary>
/// Handler for the query to get a library by its Id.
/// </summary>
public class GetLibraryQueryHandler : IQueryHandler<GetLibraryQuery, ErrorOr<LibraryResponse>>
public class GetLibraryQueryHandler : IQueryHandler<GetLibraryQuery, Result<LibraryResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -54,9 +54,9 @@ public class GetLibraryQueryHandler : IQueryHandler<GetLibraryQuery, ErrorOr<Lib
/// <param name="query">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LibraryResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<LibraryResponse>> HandleAsync(GetLibraryQuery query, CancellationToken cancellationToken)
public async Task<Result<LibraryResponse>> HandleAsync(GetLibraryQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
@@ -64,8 +64,8 @@ public class GetLibraryQueryHandler : IQueryHandler<GetLibraryQuery, ErrorOr<Lib
// get the library with the specified id from the repository
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(query.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsError)
Result<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(query.Id, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
return getLibraryResult.Errors;
else if (getLibraryResult.Value is null)
return DomainErrors.Library.LibraryNotFound;
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -17,7 +17,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryScanProgress;
@@ -25,7 +25,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryScan
/// <summary>
/// Handler for the query to get the progress of a library scan.
/// </summary>
public class GetLibraryScanProgressQueryHandler : IQueryHandler<GetLibraryScanProgressQuery, ErrorOr<MediaLibraryScanProgressResponse>>
public class GetLibraryScanProgressQueryHandler : IQueryHandler<GetLibraryScanProgressQuery, Result<MediaLibraryScanProgressResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -61,9 +61,9 @@ public class GetLibraryScanProgressQueryHandler : IQueryHandler<GetLibraryScanPr
/// <param name="query">The query to be handled.</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="MediaLibraryScanProgressResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a <see cref="MediaLibraryScanProgressResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<MediaLibraryScanProgressResponse>> HandleAsync(GetLibraryScanProgressQuery query, CancellationToken cancellationToken)
public async Task<Result<MediaLibraryScanProgressResponse>> HandleAsync(GetLibraryScanProgressQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
@@ -71,8 +71,8 @@ public class GetLibraryScanProgressQueryHandler : IQueryHandler<GetLibraryScanPr
// get the library with the specified id from the repository
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsError)
Result<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
return getLibraryResult.Errors;
else if (getLibraryResult.Value is null)
return DomainErrors.Library.LibraryNotFound;
@@ -82,9 +82,9 @@ public class GetLibraryScanProgressQueryHandler : IQueryHandler<GetLibraryScanPr
!await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
return ApplicationErrors.Authorization.NotAuthorized;
ErrorOr<MediaLibraryScanProgress> getProgressResult = _mediaLibrariesScanProgressTracker.GetScanProgress(
Result<MediaLibraryScanProgress> getProgressResult = _mediaLibrariesScanProgressTracker.GetScanProgress(
MediaLibraryScanCompositeId.Create(ScanId.Create(query.ScanId), UserId.Create(_currentUserService.UserId!.Value)));
if (getProgressResult.IsError)
if (getProgressResult.IsFailure)
return getProgressResult.Errors;
return getProgressResult.Value.ToResponse();
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
using System;
#endregion
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
@@ -22,7 +22,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetRunningLibr
/// <summary>
/// Handler for the query to get the ongoing media library scans.
/// </summary>
public class GetRunningLibraryScansQueryHandler : IQueryHandler<GetRunningLibraryScansQuery, ErrorOr<IEnumerable<MediaLibraryScanProgressResponse>>>
public class GetRunningLibraryScansQueryHandler : IQueryHandler<GetRunningLibraryScansQuery, Result<IEnumerable<MediaLibraryScanProgressResponse>>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICurrentUserService _currentUserService;
@@ -54,14 +54,14 @@ public class GetRunningLibraryScansQueryHandler : IQueryHandler<GetRunningLibrar
/// <param name="query">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="MediaLibraryScanProgress"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MediaLibraryScanProgress"/>, or an error message.
/// </returns>
public async Task<ErrorOr<IEnumerable<MediaLibraryScanProgressResponse>>> HandleAsync(GetRunningLibraryScansQuery query, CancellationToken cancellationToken)
public async Task<Result<IEnumerable<MediaLibraryScanProgressResponse>>> HandleAsync(GetRunningLibraryScansQuery query, CancellationToken cancellationToken)
{
// get the ongoing library scans from the repository
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
ErrorOr<IEnumerable<LibraryScanEntity>> getRunningScansResult = await libraryScanRepository.GetRunningScansAsync(cancellationToken).ConfigureAwait(false);
if (getRunningScansResult.IsError)
Result<IEnumerable<LibraryScanEntity>> getRunningScansResult = await libraryScanRepository.GetRunningScansAsync(cancellationToken).ConfigureAwait(false);
if (getRunningScansResult.IsFailure)
return getRunningScansResult.Errors;
// filter the library scans by what the user is allowed to see
@@ -75,21 +75,21 @@ public class GetRunningLibraryScansQueryHandler : IQueryHandler<GetRunningLibrar
// for each of the filtered library scans, get their progress
List<MediaLibraryScanProgressResponse> libraryScanProgresses = [];
IEnumerable<ErrorOr<LibraryScan>> userRunningDomainLibraryScans = userRunningRepositoryLibraryScans.ToDomainEntities();
foreach (ErrorOr<LibraryScan> userRunningDomainLibraryScan in userRunningDomainLibraryScans)
IEnumerable<Result<LibraryScan>> userRunningDomainLibraryScans = userRunningRepositoryLibraryScans.ToDomainEntities();
foreach (Result<LibraryScan> userRunningDomainLibraryScan in userRunningDomainLibraryScans)
{
if (userRunningDomainLibraryScan.IsError)
if (userRunningDomainLibraryScan.IsFailure)
return userRunningDomainLibraryScan.Errors;
else
{
ErrorOr<MediaLibraryScanProgress> getLibraryScanProgressResult = _mediaLibrariesScanProgressTracker.GetScanProgress(
Result<MediaLibraryScanProgress> getLibraryScanProgressResult = _mediaLibrariesScanProgressTracker.GetScanProgress(
MediaLibraryScanCompositeId.Create(userRunningDomainLibraryScan.Value.Id, userRunningDomainLibraryScan.Value.UserId));
if (getLibraryScanProgressResult.IsError)
if (getLibraryScanProgressResult.IsFailure)
return getLibraryScanProgressResult.Errors;
libraryScanProgresses.Add(getLibraryScanProgressResult.Value.ToResponse());
}
}
return ErrorOrFactory.From(libraryScanProgresses.AsEnumerable());
return Result.From(libraryScanProgresses.AsEnumerable());
}
}
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
@@ -8,7 +8,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentL
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
@@ -28,7 +28,7 @@ namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrar
/// <summary>
/// Handler for the command to add a book.
/// </summary>
public class AddBookCommandHandler : ICommandHandler<AddBookCommand, ErrorOr<BookResponse>>
public class AddBookCommandHandler : ICommandHandler<AddBookCommand, Result<BookResponse>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IValidator<AddBookCommand> _validator;
@@ -50,9 +50,9 @@ public class AddBookCommandHandler : ICommandHandler<AddBookCommand, ErrorOr<Boo
/// <param name="command">The command to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="BookResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="BookResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<BookResponse>> HandleAsync(AddBookCommand command, CancellationToken cancellationToken)
public async Task<Result<BookResponse>> HandleAsync(AddBookCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
@@ -70,37 +70,37 @@ public class AddBookCommandHandler : ICommandHandler<AddBookCommand, ErrorOr<Boo
// TODO: add logic to search the book series repository for existing book series, based on the provided title
// TODO: uncomment integration and unit tests about series
}
List<ErrorOr<BookRating>> domainRatingsResult = command.Ratings!.ConvertAll(rating => BookRating.Create(
List<Result<BookRating>> domainRatingsResult = command.Ratings!.ConvertAll(rating => BookRating.Create(
rating.Value ?? default,
rating.MaxValue ?? default,
Optional<BookRatingSource>.FromNullable(rating.Source.HasValue ? (BookRatingSource)(int)rating.Source : (BookRatingSource?)null),
Optional<int>.FromNullable(rating.VoteCount)));
// check if any of the results contain errors
List<Error> errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsError).SelectMany(ratingResult => ratingResult.Errors)];
List<Error> errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
if (errors.Count != 0) // if there are errors, return them
return errors;
List<BookRating> domainRatings = [.. domainRatingsResult.Select(rating => rating.Value)];
List<ErrorOr<Genre>> domainGenresResult = command.Metadata!.Genres!.ConvertAll(genre => Genre.Create(genre.Name!));
errors = [.. domainGenresResult.Where(genreResult => genreResult.IsError).SelectMany(genreResult => genreResult.Errors)];
List<Result<Genre>> domainGenresResult = command.Metadata!.Genres!.ConvertAll(genre => Genre.Create(genre.Name!));
errors = [.. domainGenresResult.Where(genreResult => genreResult.IsFailure).SelectMany(genreResult => genreResult.Errors)];
if (errors.Count != 0)
return errors;
List<Genre> domainGenres = [.. domainGenresResult.Select(genre => genre.Value)];
List<ErrorOr<Tag>> domainTagsResult = command.Metadata.Tags!.ConvertAll(tag => Tag.Create(tag.Name!));
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsError).SelectMany(tagResult => tagResult.Errors)];
List<Result<Tag>> domainTagsResult = command.Metadata.Tags!.ConvertAll(tag => Tag.Create(tag.Name!));
errors = [.. domainTagsResult.Where(tagResult => tagResult.IsFailure).SelectMany(tagResult => tagResult.Errors)];
if (errors.Count != 0)
return errors;
List<Tag> domainTags = [.. domainTagsResult.Select(tag => tag.Value)];
List<ErrorOr<Isbn>> domainIsbnsResult = command.ISBNs!.ConvertAll(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!));
errors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsError).SelectMany(isbnResult => isbnResult.Errors)];
List<Result<Isbn>> domainIsbnsResult = command.ISBNs!.ConvertAll(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!));
errors = [.. domainIsbnsResult.Where(isbnResult => isbnResult.IsFailure).SelectMany(isbnResult => isbnResult.Errors)];
if (errors.Count != 0)
return errors;
List<Isbn> domainIsbns = [.. domainIsbnsResult.Select(isbn => isbn.Value)];
ErrorOr<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Optional<DateOnly>.FromNullable(command.Metadata.ReleaseInfo!.OriginalReleaseDate),
Optional<int>.FromNullable(command.Metadata.ReleaseInfo.OriginalReleaseYear),
Optional<DateOnly>.FromNullable(command.Metadata.ReleaseInfo.ReReleaseDate),
@@ -108,32 +108,32 @@ public class AddBookCommandHandler : ICommandHandler<AddBookCommand, ErrorOr<Boo
Optional<string>.FromNullable(command.Metadata.ReleaseInfo.ReleaseCountry),
Optional<string>.FromNullable(command.Metadata.ReleaseInfo.ReleaseVersion)
);
if (releaseInfoResult.IsError)
if (releaseInfoResult.IsFailure)
return releaseInfoResult.Errors;
ReleaseInfo releaseInfo = releaseInfoResult.Value;
LanguageInfo? languageInfo = null;
if (command.Metadata.Language is not null)
{
ErrorOr<LanguageInfo> languageInfoResult = LanguageInfo.Create(
Result<LanguageInfo> languageInfoResult = LanguageInfo.Create(
command.Metadata.Language.LanguageCode!,
command.Metadata.Language.LanguageName!,
Optional<string>.FromNullable(command.Metadata.Language.NativeName));
if (languageInfoResult.IsError)
if (languageInfoResult.IsFailure)
return languageInfoResult.Errors;
languageInfo = languageInfoResult.Value;
}
LanguageInfo? originalLanguageInfo = null;
if (command.Metadata.OriginalLanguage is not null)
{
ErrorOr<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(
Result<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(
command.Metadata.OriginalLanguage.LanguageCode!,
command.Metadata.OriginalLanguage.LanguageName!,
Optional<string>.FromNullable(command.Metadata.OriginalLanguage.NativeName));
if (originalLanguageInfoResult.IsError)
if (originalLanguageInfoResult.IsFailure)
return originalLanguageInfoResult.Errors;
originalLanguageInfo = originalLanguageInfoResult.Value;
}
ErrorOr<WrittenContentMetadata> metadataResult = WrittenContentMetadata.Create(
Result<WrittenContentMetadata> metadataResult = WrittenContentMetadata.Create(
command.Metadata.Title!,
Optional<string>.FromNullable(command.Metadata.OriginalTitle),
Optional<string>.FromNullable(command.Metadata.Description),
@@ -145,9 +145,9 @@ public class AddBookCommandHandler : ICommandHandler<AddBookCommand, ErrorOr<Boo
Optional<string>.FromNullable(command.Metadata.Publisher),
Optional<int>.FromNullable(command.Metadata.PageCount)
);
if (metadataResult.IsError)
if (metadataResult.IsFailure)
return metadataResult.Errors;
ErrorOr<Book> createBookResult = Book.Create(
Result<Book> createBookResult = Book.Create(
LibraryId.Create(command.LibraryId),
command.Path,
metadataResult.Value,
@@ -168,13 +168,13 @@ public class AddBookCommandHandler : ICommandHandler<AddBookCommand, ErrorOr<Boo
contributorIds,
ratings: domainRatings
);
if (createBookResult.IsError)
if (createBookResult.IsFailure)
return createBookResult.Errors;
IBookRepository bookRepository = _unitOfWork.GetRepository<IBookRepository>();
BookEntity persistenceBook = createBookResult.Value.ToRepositoryEntity();
ErrorOr<Created> insertBookResult = await bookRepository.InsertAsync(persistenceBook, cancellationToken).ConfigureAwait(false);
if (insertBookResult.IsError)
Result<Created> insertBookResult = await bookRepository.InsertAsync(persistenceBook, cancellationToken).ConfigureAwait(false);
if (insertBookResult.IsFailure)
return insertBookResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
@@ -2,7 +2,7 @@
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Errors;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
@@ -1,5 +1,5 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Books;
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrar
/// <summary>
/// Handler for the query to get all books.
/// </summary>
public class GetBooksQueryHandler : IQueryHandler<GetBooksQuery, ErrorOr<IEnumerable<BookResponse>>>
public class GetBooksQueryHandler : IQueryHandler<GetBooksQuery, Result<IEnumerable<BookResponse>>>
{
private readonly IUnitOfWork _unitOfWork;
@@ -35,14 +35,14 @@ public class GetBooksQueryHandler : IQueryHandler<GetBooksQuery, ErrorOr<IEnumer
/// <param name="query">The query to be handled.</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="BookResponse"/>, or an error message.
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="BookResponse"/>, or an error message.
/// </returns>
public async Task<ErrorOr<IEnumerable<BookResponse>>> HandleAsync(GetBooksQuery query, CancellationToken cancellationToken)
public async Task<Result<IEnumerable<BookResponse>>> HandleAsync(GetBooksQuery query, CancellationToken cancellationToken)
{
// get a books repository
IBookRepository bookRepository = _unitOfWork.GetRepository<IBookRepository>();
// get all books of the media library from the book repository
ErrorOr<IEnumerable<BookEntity>> getBooksResult = await bookRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
return getBooksResult.Match(result => ErrorOrFactory.From(getBooksResult.Value.ToResponses()), errors => errors);
Result<IEnumerable<BookEntity>> getBooksResult = await bookRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
return getBooksResult.Match(result => Result.From(getBooksResult.Value.ToResponses()), errors => errors);
}
}
Loaded 100 of 436 files, more files were not shown because too many files have changed in this diff. Show more