mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Replaces ErrorOr library with a custom implementation.
This commit is contained in:
1 parent
8fe90a4dde
commit
3b772d68ca
436 files changed
+4234
-3922
No files matched your search
+6
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -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;
|
||||
|
||||
+8
-8
@@ -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;
|
||||
|
||||
+8
-8
@@ -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;
|
||||
|
||||
+6
-6
@@ -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;
|
||||
|
||||
+6
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+6
-6
@@ -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));
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+6
-6
@@ -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
-1
@@ -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;
|
||||
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+7
-7
@@ -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
-1
@@ -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;
|
||||
|
||||
+6
-6
@@ -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
-1
@@ -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;
|
||||
|
||||
+6
-6
@@ -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
-1
@@ -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;
|
||||
|
||||
+16
-16
@@ -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
|
||||
|
||||
+3
-3
@@ -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);
|
||||
}
|
||||
|
||||
+15
-15
@@ -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;
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+13
-13
@@ -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
|
||||
|
||||
+13
-13
@@ -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
-1
@@ -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
|
||||
|
||||
|
||||
+13
-13
@@ -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
-1
@@ -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
|
||||
|
||||
|
||||
+20
-20
@@ -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
|
||||
|
||||
+20
-20
@@ -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
-1
@@ -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
|
||||
|
||||
|
||||
+17
-17
@@ -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;
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+15
-15
@@ -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;
|
||||
}
|
||||
|
||||
+52
-52
@@ -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)
|
||||
|
||||
+10
-10
@@ -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);
|
||||
}
|
||||
}
|
||||
+12
-12
@@ -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
|
||||
|
||||
+10
-10
@@ -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);
|
||||
|
||||
+7
-7
@@ -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
|
||||
|
||||
+3
-3
@@ -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);
|
||||
|
||||
+8
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -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
-1
@@ -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
|
||||
|
||||
|
||||
+9
-9
@@ -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
-1
@@ -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
|
||||
|
||||
|
||||
+12
-12
@@ -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());
|
||||
}
|
||||
}
|
||||
+25
-25
@@ -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);
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+6
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -17,7 +17,7 @@ namespace Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProvide
|
||||
/// <summary>
|
||||
/// Handler for the command to reorder the metadata providers of a media library.
|
||||
/// </summary>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<ReorderLibraryMetadataProvidersCommand, ErrorOr<Success>>
|
||||
public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<ReorderLibraryMetadataProvidersCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<ReorderLibraryMetadataProvidersCommand> _validator;
|
||||
@@ -39,17 +39,17 @@ public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<Reo
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<Success>> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<Success>> HandleAsync(ReorderLibraryMetadataProvidersCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
Dictionary<Guid, LibraryMetadataProviderConfigurationEntity> configurationsByPluginId = getConfigurationsResult.Value.ToDictionary(configuration => configuration.PluginId);
|
||||
@@ -59,8 +59,8 @@ public class ReorderLibraryMetadataProvidersCommandHandler : ICommandHandler<Reo
|
||||
if (configurationsByPluginId.TryGetValue(pluginId, out LibraryMetadataProviderConfigurationEntity? configuration))
|
||||
{
|
||||
configuration.Rank = rank + 1;
|
||||
ErrorOr<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsError)
|
||||
Result<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -17,7 +17,7 @@ namespace Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEna
|
||||
/// <summary>
|
||||
/// Handler for the command to enable or disable a metadata provider for a media library.
|
||||
/// </summary>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, ErrorOr<Success>>
|
||||
public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<SetLibraryMetadataProviderEnabledCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<SetLibraryMetadataProviderEnabledCommand> _validator;
|
||||
@@ -39,17 +39,17 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<S
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<Success>> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<Success>> HandleAsync(SetLibraryMetadataProviderEnabledCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await configurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsError)
|
||||
Result<LibraryMetadataProviderConfigurationEntity?> getConfigurationResult = await configurationRepository.GetByLibraryAndPluginIdAsync(command.LibraryId, command.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationResult.IsFailure)
|
||||
return getConfigurationResult.Errors;
|
||||
|
||||
LibraryMetadataProviderConfigurationEntity configuration;
|
||||
@@ -61,8 +61,8 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<S
|
||||
else
|
||||
{
|
||||
// compute the rank to assign to the new configuration, appending it after the existing ones
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
int nextRank = getConfigurationsResult.Value.Count == 0 ? 1 : getConfigurationsResult.Value.Max(configuration => configuration.Rank) + 1;
|
||||
configuration = new LibraryMetadataProviderConfigurationEntity
|
||||
@@ -78,8 +78,8 @@ public class SetLibraryMetadataProviderEnabledCommandHandler : ICommandHandler<S
|
||||
};
|
||||
}
|
||||
|
||||
ErrorOr<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsError)
|
||||
Result<Updated> upsertResult = await configurationRepository.UpsertAsync(configuration, cancellationToken).ConfigureAwait(false);
|
||||
if (upsertResult.IsFailure)
|
||||
return upsertResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
|
||||
+1
-1
@@ -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.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -15,7 +15,7 @@ namespace Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
/// <summary>
|
||||
/// Handler for the command to update the settings of a plugin.
|
||||
/// </summary>
|
||||
public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSettingsCommand, ErrorOr<Success>>
|
||||
public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSettingsCommand, Result<Success>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IValidator<UpdatePluginSettingsCommand> _validator;
|
||||
@@ -37,9 +37,9 @@ public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSe
|
||||
/// <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.
|
||||
/// An <see cref="Result{TValue}"/> representing either a successful operation, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<Success>> HandleAsync(UpdatePluginSettingsCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<Success>> HandleAsync(UpdatePluginSettingsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -47,8 +47,8 @@ public class UpdatePluginSettingsCommandHandler : ICommandHandler<UpdatePluginSe
|
||||
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
string? settingsJson = command.Settings is not null ? JsonSerializer.Serialize(command.Settings) : null;
|
||||
ErrorOr<Updated> updateResult = await pluginRepository.UpdateSettingsAsync(command.PluginId, settingsJson, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsError)
|
||||
Result<Updated> updateResult = await pluginRepository.UpdateSettingsAsync(command.PluginId, settingsJson, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.Success;
|
||||
|
||||
+1
-1
@@ -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.Plugins.Commands.UpdatePluginSettings;
|
||||
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -18,7 +18,7 @@ namespace Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
/// <summary>
|
||||
/// Handler for the query to get the metadata providers configured for a media library.
|
||||
/// </summary>
|
||||
public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryMetadataProvidersQuery, ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryMetadataProvidersQuery, Result<IReadOnlyList<LibraryMetadataProviderResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -37,19 +37,19 @@ public class GetLibraryMetadataProvidersQueryHandler : IQueryHandler<GetLibraryM
|
||||
/// <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="LibraryMetadataProviderResponse"/>, or an error.
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="LibraryMetadataProviderResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<IReadOnlyList<LibraryMetadataProviderResponse>>> HandleAsync(GetLibraryMetadataProvidersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryMetadataProviderConfigurationRepository configurationRepository = _unitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>();
|
||||
ErrorOr<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsError)
|
||||
Result<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>> getConfigurationsResult = await configurationRepository.GetByLibraryIdAsync(query.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getConfigurationsResult.IsFailure)
|
||||
return getConfigurationsResult.Errors;
|
||||
|
||||
// build a plugin name lookup from the detected plugins
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsError)
|
||||
Result<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginsResult.IsFailure)
|
||||
return getPluginsResult.Errors;
|
||||
Dictionary<Guid, string> pluginNames = getPluginsResult.Value.ToDictionary(plugin => plugin.Id, plugin => plugin.Name);
|
||||
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -7,7 +7,7 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Plugins;
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Plugins.Contracts.Core.Plugins;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,7 +20,7 @@ namespace Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
/// <summary>
|
||||
/// Handler for the query to get the settings of a plugin and their schema.
|
||||
/// </summary>
|
||||
public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuery, ErrorOr<PluginSettingsResponse>>
|
||||
public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuery, Result<PluginSettingsResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPluginManager _pluginManager;
|
||||
@@ -42,13 +42,13 @@ public class GetPluginSettingsQueryHandler : IQueryHandler<GetPluginSettingsQuer
|
||||
/// <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 <see cref="PluginSettingsResponse"/>, or an error.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="PluginSettingsResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<PluginSettingsResponse>> HandleAsync(GetPluginSettingsQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<PluginSettingsResponse>> HandleAsync(GetPluginSettingsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsError)
|
||||
Result<PluginEntity?> getPluginResult = await pluginRepository.GetByIdAsync(query.PluginId, cancellationToken).ConfigureAwait(false);
|
||||
if (getPluginResult.IsFailure)
|
||||
return getPluginResult.Errors;
|
||||
PluginEntity? pluginEntity = getPluginResult.Value;
|
||||
if (pluginEntity is null)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
@@ -17,7 +17,7 @@ namespace Lumina.Application.Core.Plugins.Queries.GetPlugins;
|
||||
/// <summary>
|
||||
/// Handler for the query to get all the detected plugins.
|
||||
/// </summary>
|
||||
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, ErrorOr<IReadOnlyList<PluginResponse>>>
|
||||
public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, Result<IReadOnlyList<PluginResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -36,14 +36,14 @@ public class GetPluginsQueryHandler : IQueryHandler<GetPluginsQuery, ErrorOr<IRe
|
||||
/// <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="PluginResponse"/>, or an error.
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="PluginResponse"/>, or an error.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<IReadOnlyList<PluginResponse>>> HandleAsync(GetPluginsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
IPluginRepository pluginRepository = _unitOfWork.GetRepository<IPluginRepository>();
|
||||
ErrorOr<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
Result<IEnumerable<PluginEntity>> getPluginsResult = await pluginRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getPluginsResult.Match(
|
||||
plugins => ErrorOrFactory.From<IReadOnlyList<PluginResponse>>(plugins.Select(plugin => plugin.ToResponse()).ToList()),
|
||||
plugins => Result.From<IReadOnlyList<PluginResponse>>(plugins.Select(plugin => plugin.ToResponse()).ToList()),
|
||||
errors => errors);
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -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;
|
||||
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Commands.Change
|
||||
/// <summary>
|
||||
/// Handler for the command to change the password of a user account.
|
||||
/// </summary>
|
||||
public class ChangePasswordCommandHandler : ICommandHandler<ChangePasswordCommand, ErrorOr<ChangePasswordResponse>>
|
||||
public class ChangePasswordCommandHandler : ICommandHandler<ChangePasswordCommand, Result<ChangePasswordResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
@@ -47,17 +47,17 @@ public class ChangePasswordCommandHandler : ICommandHandler<ChangePasswordComman
|
||||
/// <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="ChangePasswordResponse"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="ChangePasswordResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<ChangePasswordResponse>> HandleAsync(ChangePasswordCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<ChangePasswordResponse>> HandleAsync(ChangePasswordCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
IUserRepository userRepository = _unitOfWork.GetRepository<IUserRepository>();
|
||||
ErrorOr<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(command.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(command.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
else if (getUserResult.Value is null)
|
||||
return Errors.Authentication.UsernameDoesNotExist;
|
||||
@@ -69,8 +69,8 @@ public class ChangePasswordCommandHandler : ICommandHandler<ChangePasswordComman
|
||||
getUserResult.Value.TempPassword = null;
|
||||
getUserResult.Value.TempPasswordCreated = null;
|
||||
// update the user
|
||||
ErrorOr<Updated> updateUserResult = await userRepository.UpdateAsync(getUserResult.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (updateUserResult.IsError)
|
||||
Result<Updated> updateUserResult = await userRepository.UpdateAsync(getUserResult.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (updateUserResult.IsFailure)
|
||||
return updateUserResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return new ChangePasswordResponse(true);
|
||||
|
||||
+8
-8
@@ -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;
|
||||
@@ -20,7 +20,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Commands.Recove
|
||||
/// <summary>
|
||||
/// Handler for the command to recover the password of an account.
|
||||
/// </summary>
|
||||
public class RecoverPasswordCommandHandler : ICommandHandler<RecoverPasswordCommand, ErrorOr<RecoverPasswordResponse>>
|
||||
public class RecoverPasswordCommandHandler : ICommandHandler<RecoverPasswordCommand, Result<RecoverPasswordResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
@@ -56,9 +56,9 @@ public class RecoverPasswordCommandHandler : ICommandHandler<RecoverPasswordComm
|
||||
/// <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="RecoverPasswordResponse"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="RecoverPasswordResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<RecoverPasswordResponse>> HandleAsync(RecoverPasswordCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<RecoverPasswordResponse>> HandleAsync(RecoverPasswordCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -66,8 +66,8 @@ public class RecoverPasswordCommandHandler : ICommandHandler<RecoverPasswordComm
|
||||
|
||||
// check if any users already exists
|
||||
IUserRepository userRepository = _unitOfWork.GetRepository<IUserRepository>();
|
||||
ErrorOr<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(command.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(command.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
else if (getUserResult.Value is null)
|
||||
return Errors.Authentication.UsernameDoesNotExist;
|
||||
@@ -86,8 +86,8 @@ public class RecoverPasswordCommandHandler : ICommandHandler<RecoverPasswordComm
|
||||
getUserResult.Value.TempPassword = Uri.EscapeDataString(_hashService.HashString("Abcd123$")); // TODO: replace with random password generator
|
||||
getUserResult.Value.TempPasswordCreated = DateTime.UtcNow;
|
||||
// update the user
|
||||
ErrorOr<Updated> updateUserResult = await userRepository.UpdateAsync(getUserResult.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (updateUserResult.IsError)
|
||||
Result<Updated> updateUserResult = await userRepository.UpdateAsync(getUserResult.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (updateUserResult.IsFailure)
|
||||
return updateUserResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
return new RecoverPasswordResponse(true);
|
||||
|
||||
+8
-8
@@ -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;
|
||||
@@ -21,7 +21,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Commands.Regist
|
||||
/// <summary>
|
||||
/// Handler for the command to register a new user account.
|
||||
/// </summary>
|
||||
public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, ErrorOr<RegistrationResponse>>
|
||||
public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, Result<RegistrationResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
@@ -65,9 +65,9 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, E
|
||||
/// <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(RegisterUserCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<RegistrationResponse>> HandleAsync(RegisterUserCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -75,8 +75,8 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, E
|
||||
|
||||
// check if any users already exists (admin account is only set once!)
|
||||
IUserRepository userRepository = _unitOfWork.GetRepository<IUserRepository>();
|
||||
ErrorOr<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(command.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(command.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
else if (getUserResult.Value is not null)
|
||||
return Errors.Authentication.UsernameAlreadyExists;
|
||||
@@ -105,8 +105,8 @@ public class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, E
|
||||
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);
|
||||
// TODO: insert the default admin profile preferences when they are implemented
|
||||
|
||||
+6
-6
@@ -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;
|
||||
@@ -20,7 +20,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUser
|
||||
/// <summary>
|
||||
/// Handler for the query to retrieve the list of users.
|
||||
/// </summary>
|
||||
public class GetUsersQueryHandler : IQueryHandler<GetUsersQuery, ErrorOr<IEnumerable<UserResponse>>>
|
||||
public class GetUsersQueryHandler : IQueryHandler<GetUsersQuery, Result<IEnumerable<UserResponse>>>
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
@@ -45,15 +45,15 @@ public class GetUsersQueryHandler : IQueryHandler<GetUsersQuery, 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="UserResponse"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a collection of <see cref="UserResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<IEnumerable<UserResponse>>> HandleAsync(GetUsersQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<IEnumerable<UserResponse>>> HandleAsync(GetUsersQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
// only admins can see the list of users
|
||||
bool isAdmin = await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false);
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
ErrorOr<IEnumerable<UserEntity>> getRolesResult = await _userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => ErrorOrFactory.From(value.ToResponses()), errors => errors);
|
||||
Result<IEnumerable<UserEntity>> getRolesResult = await _userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getRolesResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -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;
|
||||
@@ -21,7 +21,7 @@ namespace Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUs
|
||||
/// <summary>
|
||||
/// Handler for the query to authenticate an account.
|
||||
/// </summary>
|
||||
public class LoginUserQueryHandler : IQueryHandler<LoginUserQuery, ErrorOr<LoginResponse>>
|
||||
public class LoginUserQueryHandler : IQueryHandler<LoginUserQuery, Result<LoginResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPasswordHashService _hashService;
|
||||
@@ -65,9 +65,9 @@ public class LoginUserQueryHandler : IQueryHandler<LoginUserQuery, ErrorOr<Login
|
||||
/// <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 successfully created <see cref="LoginResponse"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="LoginResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<LoginResponse>> HandleAsync(LoginUserQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<LoginResponse>> HandleAsync(LoginUserQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -75,8 +75,8 @@ public class LoginUserQueryHandler : IQueryHandler<LoginUserQuery, ErrorOr<Login
|
||||
|
||||
// check if any users already exists
|
||||
IUserRepository userRepository = _unitOfWork.GetRepository<IUserRepository>();
|
||||
ErrorOr<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(query.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await userRepository.GetByUsernameAsync(query.Username!, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
else if (getUserResult.Value is null)
|
||||
return Errors.Authentication.InvalidUsernameOrPassword;
|
||||
|
||||
+15
-15
@@ -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.Entities.UsersManagement;
|
||||
@@ -16,7 +16,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.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
@@ -24,7 +24,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateU
|
||||
/// <summary>
|
||||
/// Handler for the command to update an authorization role.
|
||||
/// </summary>
|
||||
public class UpdateUserRoleAndPermissionsCommandHandler : ICommandHandler<UpdateUserRoleAndPermissionsCommand, ErrorOr<AuthorizationResponse>>
|
||||
public class UpdateUserRoleAndPermissionsCommandHandler : ICommandHandler<UpdateUserRoleAndPermissionsCommand, Result<AuthorizationResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
@@ -52,9 +52,9 @@ public class UpdateUserRoleAndPermissionsCommandHandler : ICommandHandler<Update
|
||||
/// <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<AuthorizationResponse>> HandleAsync(UpdateUserRoleAndPermissionsCommand command, CancellationToken cancellationToken)
|
||||
public async Task<Result<AuthorizationResponse>> HandleAsync(UpdateUserRoleAndPermissionsCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -71,24 +71,24 @@ public class UpdateUserRoleAndPermissionsCommandHandler : ICommandHandler<Update
|
||||
IPermissionRepository permissionRepository = _unitOfWork.GetRepository<IPermissionRepository>();
|
||||
|
||||
// get the user to update
|
||||
ErrorOr<UserEntity?> getUserResult = await userRepository.GetByIdAsync(command.UserId, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError || getUserResult.Value is null)
|
||||
Result<UserEntity?> getUserResult = await userRepository.GetByIdAsync(command.UserId, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure || getUserResult.Value is null)
|
||||
return DomainErrors.Users.UserDoesNotExist;
|
||||
|
||||
ErrorOr<RoleEntity?> getRoleResult = default;
|
||||
Result<RoleEntity?> getRoleResult = default;
|
||||
if (command.RoleId is not null)
|
||||
{
|
||||
// get the new role
|
||||
getRoleResult = await roleRepository.GetByIdAsync(command.RoleId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getRoleResult.IsError || getRoleResult.Value is null)
|
||||
if (getRoleResult.IsFailure || getRoleResult.Value is null)
|
||||
return ApplicationErrors.Authorization.RoleNotFound;
|
||||
|
||||
// check if we're changing an admin's role and if this would leave us without admins
|
||||
if (getUserResult.Value.UserRole?.Role.RoleName == "Admin" && getRoleResult.Value.RoleName != "Admin")
|
||||
{
|
||||
// count how many admins we have
|
||||
ErrorOr<IEnumerable<UserEntity>> getAllUsersResult = await userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getAllUsersResult.IsError)
|
||||
Result<IEnumerable<UserEntity>> getAllUsersResult = await userRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getAllUsersResult.IsFailure)
|
||||
return getAllUsersResult.Errors;
|
||||
|
||||
int adminCount = getAllUsersResult.Value.Count(user => user.UserRole?.Role.RoleName == "Admin");
|
||||
@@ -97,9 +97,9 @@ public class UpdateUserRoleAndPermissionsCommandHandler : ICommandHandler<Update
|
||||
}
|
||||
}
|
||||
// get the permissions to assign
|
||||
ErrorOr<IEnumerable<PermissionEntity>> getPermissionsResult =
|
||||
Result<IEnumerable<PermissionEntity>> getPermissionsResult =
|
||||
await permissionRepository.GetByIdsAsync(command.Permissions, cancellationToken).ConfigureAwait(false);
|
||||
if (getPermissionsResult.IsError)
|
||||
if (getPermissionsResult.IsFailure)
|
||||
return getPermissionsResult.Errors;
|
||||
|
||||
// update the user
|
||||
@@ -138,8 +138,8 @@ public class UpdateUserRoleAndPermissionsCommandHandler : ICommandHandler<Update
|
||||
};
|
||||
|
||||
// save changes and return result
|
||||
ErrorOr<Updated> updateResult = await userRepository.UpdateAsync(updatedUser, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsError)
|
||||
Result<Updated> updateResult = await userRepository.UpdateAsync(updatedUser, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using System;
|
||||
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.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
|
||||
+8
-8
@@ -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.Errors;
|
||||
@@ -19,7 +19,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAutho
|
||||
/// <summary>
|
||||
/// Handler for the query to retrieve the authorization roles and permissions of an account.
|
||||
/// </summary>
|
||||
public class GetAuthorizationQueryHandler : IQueryHandler<GetAuthorizationQuery, ErrorOr<AuthorizationResponse>>
|
||||
public class GetAuthorizationQueryHandler : IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>>
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
@@ -44,9 +44,9 @@ public class GetAuthorizationQueryHandler : IQueryHandler<GetAuthorizationQuery,
|
||||
/// <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 <see cref="AuthorizationResponse"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="AuthorizationResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<AuthorizationResponse>> HandleAsync(GetAuthorizationQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<AuthorizationResponse>> HandleAsync(GetAuthorizationQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -56,14 +56,14 @@ public class GetAuthorizationQueryHandler : IQueryHandler<GetAuthorizationQuery,
|
||||
if (_currentUserService.UserId != query.UserId)
|
||||
{
|
||||
// if it is, get the role of the current user, and see if they are Admin
|
||||
ErrorOr<UserAuthorizationEntity> getCurrentUserPermissionResult = await _authorizationService.GetUserAuthorizationAsync(_currentUserService.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getCurrentUserPermissionResult.IsError)
|
||||
Result<UserAuthorizationEntity> getCurrentUserPermissionResult = await _authorizationService.GetUserAuthorizationAsync(_currentUserService.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getCurrentUserPermissionResult.IsFailure)
|
||||
return getCurrentUserPermissionResult.Errors;
|
||||
// if the current user is not an Admin, and the account for whom they request the permissions list is not theirs, deny the request
|
||||
if (getCurrentUserPermissionResult.Value.Role != "Admin")
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
}
|
||||
ErrorOr<UserAuthorizationEntity> getUserPermissionResult = await _authorizationService.GetUserAuthorizationAsync(query.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
return getUserPermissionResult.Match(value => ErrorOrFactory.From(value.ToResponse()), errors => errors);
|
||||
Result<UserAuthorizationEntity> getUserPermissionResult = await _authorizationService.GetUserAuthorizationAsync(query.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
return getUserPermissionResult.Match(value => Result.From(value.ToResponse()), errors => errors);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+7
-7
@@ -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;
|
||||
@@ -21,7 +21,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserP
|
||||
/// <summary>
|
||||
/// Handler for the query to retrieve the authorization permissions of a user.
|
||||
/// </summary>
|
||||
public class GetUserPermissionsQueryHandler : IQueryHandler<GetUserPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>>
|
||||
public class GetUserPermissionsQueryHandler : IQueryHandler<GetUserPermissionsQuery, Result<IEnumerable<PermissionResponse>>>
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
@@ -49,9 +49,9 @@ public class GetUserPermissionsQueryHandler : IQueryHandler<GetUserPermissionsQu
|
||||
/// <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(GetUserPermissionsQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<IEnumerable<PermissionResponse>>> HandleAsync(GetUserPermissionsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -62,11 +62,11 @@ public class GetUserPermissionsQueryHandler : IQueryHandler<GetUserPermissionsQu
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
// get the user from the repository and return its permissions
|
||||
ErrorOr<UserEntity?> getUserResult = await _userRepository.GetByIdAsync(query.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await _userRepository.GetByIdAsync(query.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
else if (getUserResult.Value is null)
|
||||
return Errors.Authentication.UsernameDoesNotExist;
|
||||
return ErrorOrFactory.From(getUserResult.Value.UserPermissions.Select(userPermission => userPermission.Permission).ToResponses());
|
||||
return Result.From(getUserResult.Value.UserPermissions.Select(userPermission => userPermission.Permission).ToResponses());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+7
-7
@@ -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;
|
||||
@@ -20,7 +20,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserR
|
||||
/// <summary>
|
||||
/// Handler for the query to retrieve the authorization role of a user.
|
||||
/// </summary>
|
||||
public class GetUserRoleQueryHandler : IQueryHandler<GetUserRoleQuery, ErrorOr<RoleResponse?>>
|
||||
public class GetUserRoleQueryHandler : IQueryHandler<GetUserRoleQuery, Result<RoleResponse?>>
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
@@ -48,9 +48,9 @@ public class GetUserRoleQueryHandler : IQueryHandler<GetUserRoleQuery, ErrorOr<R
|
||||
/// <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 <see cref="RoleResponse"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either a <see cref="RoleResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async Task<ErrorOr<RoleResponse?>> HandleAsync(GetUserRoleQuery query, CancellationToken cancellationToken)
|
||||
public async Task<Result<RoleResponse?>> HandleAsync(GetUserRoleQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
@@ -61,11 +61,11 @@ public class GetUserRoleQueryHandler : IQueryHandler<GetUserRoleQuery, ErrorOr<R
|
||||
if (!isAdmin)
|
||||
return Errors.Authorization.NotAuthorized;
|
||||
// get the user from the repository and return its roles
|
||||
ErrorOr<UserEntity?> getUserResult = await _userRepository.GetByIdAsync(query.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsError)
|
||||
Result<UserEntity?> getUserResult = await _userRepository.GetByIdAsync(query.UserId!.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getUserResult.IsFailure)
|
||||
return getUserResult.Errors;
|
||||
else if (getUserResult.Value is null)
|
||||
return Errors.Authentication.UsernameDoesNotExist;
|
||||
return ErrorOrFactory.From(getUserResult.Value.UserRole?.Role.ToResponse());
|
||||
return Result.From(getUserResult.Value.UserRole?.Role.ToResponse());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user