mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 13:01:10 +00:00
Replaces MVC with FastEndpoints in Lumina.Presentation.Api
This commit is contained in:
1 parent
b1a20716df
commit
c7b8bc2f1c
519 files changed
+15329
-8539
No files matched your search
-15
@@ -1,15 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of directories at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of directories.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
|
||||
public record GetDirectoriesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<DirectoryResponse>>>;
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of directories at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of directories.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
|
||||
public record GetTreeDirectoriesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
@@ -1,15 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of files at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
|
||||
public record GetFilesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileResponse>>>;
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of files at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
|
||||
public record GetTreeFilesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Command for combining two file system path.
|
||||
/// </summary>
|
||||
/// <param name="OriginalPath">The path to combine to.</param>
|
||||
/// <param name="NewPath">The path to combine with.</param>
|
||||
public record CombinePathCommand(
|
||||
string OriginalPath, string NewPath
|
||||
) : IRequest<ErrorOr<PathSegmentResponse>>;
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Command for splitting a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path to split.</param>
|
||||
public record SplitPathCommand(
|
||||
string Path
|
||||
) : IRequest<ErrorOr<IEnumerable<PathSegmentResponse>>>;
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the existence of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to check the existence.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
public record CheckPathExistsQuery(string Path, bool IncludeHiddenElements) : IRequest<PathExistsResponse>;
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the parent of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to get the parent.</param>
|
||||
public record GetPathParentQuery(string Path) : IRequest<ErrorOr<IEnumerable<PathSegmentResponse>>>;
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the root of a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to get the path root.</param>
|
||||
public record GetPathRootQuery(string Path) : IRequest<ErrorOr<PathSegmentResponse>>;
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Query for validating a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path to be validated.</param>
|
||||
public record ValidatePathQuery(string Path) : IRequest<PathValidResponse>;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of directories at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of directories.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetDirectoriesQuery(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<DirectoryResponse>>>;
|
||||
+8
-12
@@ -1,17 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all directories.
|
||||
@@ -19,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirector
|
||||
public class GetDirectoriesQueryHandler : IRequestHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<DirectoryResponse>>>
|
||||
{
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="directoryService">Injected service for handling directories.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetDirectoriesQueryHandler(IDirectoryService directoryService, IMapper mapper)
|
||||
public GetDirectoriesQueryHandler(IDirectoryService directoryService)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,7 +38,7 @@ public class GetDirectoriesQueryHandler : IRequestHandler<GetDirectoriesQuery, E
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<DirectoryResponse>>> Handle(GetDirectoriesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<DirectoryResponse>>(values)), errors => errors));
|
||||
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path!, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetDirectoriesQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetDirectoriesQueryValidator : AbstractValidator<GetDirectoriesQuer
|
||||
/// </summary>
|
||||
public GetDirectoriesQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -1,11 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the tree of directories of a path.
|
||||
@@ -13,4 +14,9 @@ namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirector
|
||||
/// <param name="Path">The path for which to retrieve the tree of directories.</param>
|
||||
/// <param name="IncludeFiles">Whether to include files in the directory tree or not.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
|
||||
public record GetDirectoryTreeQuery(string Path, bool IncludeFiles, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetDirectoryTreeQuery(
|
||||
string? Path,
|
||||
bool IncludeFiles,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
+9
-9
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Mapster;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -14,7 +14,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get a directory tree.
|
||||
@@ -56,7 +56,7 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
|
||||
return getDrivesResult.Errors;
|
||||
result.AddRange(getDrivesResult.Value);
|
||||
|
||||
ErrorOr<IEnumerable<PathSegment>> pathPartsResults = _pathService.ParsePath(request.Path);
|
||||
ErrorOr<IEnumerable<PathSegment>> pathPartsResults = _pathService.ParsePath(request.Path!);
|
||||
if (pathPartsResults.IsError)
|
||||
return pathPartsResults.Errors;
|
||||
|
||||
@@ -84,7 +84,7 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
|
||||
ErrorOr<IEnumerable<FileSystemItem>> driveResult = _driveService.GetDrives();
|
||||
if (driveResult.IsError)
|
||||
return driveResult.Errors;
|
||||
return ErrorOrFactory.From(driveResult.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>());
|
||||
return ErrorOrFactory.From(driveResult.Value.ToTreeNodeResponses());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetDirectoryTreeQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetDirectoryTreeQueryValidator : AbstractValidator<GetDirectoryTree
|
||||
/// </summary>
|
||||
public GetDirectoryTreeQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of directories at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of directories.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetTreeDirectoriesQuery(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
+8
-12
@@ -1,17 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all directories.
|
||||
@@ -19,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDire
|
||||
public class GetTreeDirectoriesQueryHandler : IRequestHandler<GetTreeDirectoriesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
|
||||
{
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="directoryService">Injected service for handling directories.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetTreeDirectoriesQueryHandler(IDirectoryService directoryService, IMapper mapper)
|
||||
public GetTreeDirectoriesQueryHandler(IDirectoryService directoryService)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,7 +38,7 @@ public class GetTreeDirectoriesQueryHandler : IRequestHandler<GetTreeDirectories
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeDirectoriesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(values)), errors => errors));
|
||||
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path!, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetTreeDirectoriesQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetTreeDirectoriesQueryValidator : AbstractValidator<GetTreeDirecto
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of drives.
|
||||
+7
-11
@@ -1,17 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all drives.
|
||||
@@ -19,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
|
||||
public class GetDrivesQueryHandler : IRequestHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
|
||||
{
|
||||
private readonly IDriveService _driveService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDrivesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="driveService">Injected service for handling file system drives.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetDrivesQueryHandler(IDriveService driveService, IMapper mapper)
|
||||
public GetDrivesQueryHandler(IDriveService driveService)
|
||||
{
|
||||
_driveService = driveService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,6 +39,6 @@ public class GetDrivesQueryHandler : IRequestHandler<GetDrivesQuery, ErrorOr<IEn
|
||||
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDrivesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<FileSystemItem>> result = _driveService.GetDrives();
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(values)), errors => errors));
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToTreeNodeResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSystem;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the file system type.
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSystem;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the file system type.
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of files at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetFilesQuery(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<FileResponse>>>;
|
||||
+8
-12
@@ -1,17 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all files.
|
||||
@@ -19,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
public class GetFilesQueryHandler : IRequestHandler<GetFilesQuery, ErrorOr<IEnumerable<FileResponse>>>
|
||||
{
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFilesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="fileService">Injected service for handling files.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetFilesQueryHandler(IFileService fileService, IMapper mapper)
|
||||
public GetFilesQueryHandler(IFileService fileService)
|
||||
{
|
||||
_fileService = fileService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,7 +38,7 @@ public class GetFilesQueryHandler : IRequestHandler<GetFilesQuery, ErrorOr<IEnum
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<FileResponse>>> Handle(GetFilesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<FileResponse>>(values)), errors => errors));
|
||||
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path!, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetFilesQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetFilesQueryValidator : AbstractValidator<GetFilesQuery>
|
||||
/// </summary>
|
||||
public GetFilesQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the list of files at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to retrieve the list of files.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetTreeFilesQuery(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
|
||||
+8
-12
@@ -1,17 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Mapster;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get all files.
|
||||
@@ -19,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
public class GetTreeFilesQueryHandler : IRequestHandler<GetTreeFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
|
||||
{
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeFilesQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="fileService">Injected service for handling files.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetTreeFilesQueryHandler(IFileService fileService, IMapper mapper)
|
||||
public GetTreeFilesQueryHandler(IFileService fileService)
|
||||
{
|
||||
_fileService = fileService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,7 +38,7 @@ public class GetTreeFilesQueryHandler : IRequestHandler<GetTreeFilesQuery, Error
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeFilesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<FileSystemTreeNodeResponse>>(values)), errors => errors));
|
||||
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path!, request.IncludeHiddenElements);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToFileSystemTreeNodeResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetTreeFilesQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetTreeFilesQueryValidator : AbstractValidator<GetTreeFilesQuery>
|
||||
/// </summary>
|
||||
public GetTreeFilesQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Command for combining two file system path.
|
||||
/// </summary>
|
||||
/// <param name="OriginalPath">The path to combine to.</param>
|
||||
/// <param name="NewPath">The path to combine with.</param>
|
||||
[DebuggerDisplay("OriginalPath: {OriginalPath}, NewPath: {NewPath}")]
|
||||
public record CombinePathCommand(
|
||||
string? OriginalPath,
|
||||
string? NewPath
|
||||
) : IRequest<ErrorOr<PathSegmentResponse>>;
|
||||
+7
-7
@@ -1,14 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to split a file system path.
|
||||
@@ -36,7 +36,7 @@ public class CombinePathCommandHandler : IRequestHandler<CombinePathCommand, Err
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<PathSegmentResponse>> Handle(CombinePathCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<string> result = _pathService.CombinePath(request.OriginalPath, request.NewPath);
|
||||
ErrorOr<string> result = _pathService.CombinePath(request.OriginalPath!, request.NewPath!);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(new PathSegmentResponse(result.Value)), errors => errors));
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="CombinePathCommand"/>.
|
||||
@@ -15,7 +15,7 @@ public class CombinePathCommandValidator : AbstractValidator<CombinePathCommand>
|
||||
/// </summary>
|
||||
public CombinePathCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.OriginalPath).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.NewPath).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.OriginalPath).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
RuleFor(x => x.NewPath).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Command for splitting a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The file system path to split.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record SplitPathCommand(
|
||||
string? Path
|
||||
) : IRequest<ErrorOr<IEnumerable<PathSegmentResponse>>>;
|
||||
+8
-11
@@ -1,16 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to split a file system path.
|
||||
@@ -18,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
public class SplitPathCommandHandler : IRequestHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>>
|
||||
{
|
||||
private readonly IPathService _pathService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SplitPathCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pathService">Injected service for handling file system paths.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public SplitPathCommandHandler(IPathService pathService, IMapper mapper)
|
||||
public SplitPathCommandHandler(IPathService pathService)
|
||||
{
|
||||
_pathService = pathService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +38,7 @@ public class SplitPathCommandHandler : IRequestHandler<SplitPathCommand, ErrorOr
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(SplitPathCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<PathSegment>> result = _pathService.ParsePath(request.Path);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<PathSegmentResponse>>(values)), errors => errors));
|
||||
ErrorOr<IEnumerable<PathSegment>> result = _pathService.ParsePath(request.Path!);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="SplitPathCommand"/>.
|
||||
@@ -15,6 +15,6 @@ public class SplitPathCommandValidator : AbstractValidator<SplitPathCommand>
|
||||
/// </summary>
|
||||
public SplitPathCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Query for checking the existence of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to check the existence of.</param>
|
||||
/// <param name="IncludeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
[DebuggerDisplay("Path: {Path}, IncludeHiddenElements: {IncludeHiddenElements}")]
|
||||
public record CheckPathExistsQuery(
|
||||
string? Path,
|
||||
bool IncludeHiddenElements
|
||||
) : IRequest<PathExistsResponse>;
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to check the existence a file system path.
|
||||
@@ -34,6 +34,6 @@ public class CheckPathExistsQueryHandler : IRequestHandler<CheckPathExistsQuery,
|
||||
/// </returns>
|
||||
public ValueTask<PathExistsResponse> Handle(CheckPathExistsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return ValueTask.FromResult(new PathExistsResponse(_pathService.Exists(request.Path, request.IncludeHiddenElements)));
|
||||
return ValueTask.FromResult(new PathExistsResponse(_pathService.Exists(request.Path!, request.IncludeHiddenElements)));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="CheckPathExistsQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class CheckPathExistsQueryValidator : AbstractValidator<CheckPathExistsQu
|
||||
/// </summary>
|
||||
public CheckPathExistsQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the parent of a file system path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to get the parent.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetPathParentQuery(
|
||||
string? Path
|
||||
) : IRequest<ErrorOr<IEnumerable<PathSegmentResponse>>>;
|
||||
+8
-11
@@ -1,16 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the parent of a file system path.
|
||||
@@ -18,17 +18,14 @@ namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
public class GetPathParentQueryHandler : IRequestHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>>
|
||||
{
|
||||
private readonly IPathService _pathService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathParentQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pathService">Injected service for managing file system paths.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetPathParentQueryHandler(IPathService pathService, IMapper mapper)
|
||||
public GetPathParentQueryHandler(IPathService pathService)
|
||||
{
|
||||
_pathService = pathService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +38,7 @@ public class GetPathParentQueryHandler : IRequestHandler<GetPathParentQuery, Err
|
||||
/// </returns>
|
||||
public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(GetPathParentQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<IEnumerable<PathSegment>> result = _pathService.GoUpOneLevel(request.Path);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<IEnumerable<PathSegmentResponse>>(values)), errors => errors));
|
||||
ErrorOr<IEnumerable<PathSegment>> result = _pathService.GoUpOneLevel(request.Path!);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToResponses()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetPathParentQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetPathParentQueryValidator : AbstractValidator<GetPathParentQuery>
|
||||
/// </summary>
|
||||
public GetPathParentQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the root of a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path for which to get the path root.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetPathRootQuery(
|
||||
string? Path
|
||||
) : IRequest<ErrorOr<PathSegmentResponse>>;
|
||||
+8
-11
@@ -1,15 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the root of a file system path.
|
||||
@@ -17,17 +17,14 @@ namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
public class GetPathRootQueryHandler : IRequestHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>>
|
||||
{
|
||||
private readonly IPathService _pathService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPathRootQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="pathService">Injected service for managing file system paths.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetPathRootQueryHandler(IPathService pathService, IMapper mapper)
|
||||
public GetPathRootQueryHandler(IPathService pathService)
|
||||
{
|
||||
_pathService = pathService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +35,7 @@ public class GetPathRootQueryHandler : IRequestHandler<GetPathRootQuery, ErrorOr
|
||||
/// <returns>The root of the specified path.</returns>
|
||||
public ValueTask<ErrorOr<PathSegmentResponse>> Handle(GetPathRootQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<PathSegment> result = _pathService.GetPathRoot(request.Path);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<PathSegmentResponse>(values)), errors => errors));
|
||||
ErrorOr<PathSegment> result = _pathService.GetPathRoot(request.Path!);
|
||||
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.ToResponse()), errors => errors));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetPathRootQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class GetPathRootQueryValidator : AbstractValidator<GetPathRootQuery>
|
||||
/// </summary>
|
||||
public GetPathRootQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the file system path separator.
|
||||
+3
-3
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the path separator character of a file system path.
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Mediator;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Query for validating a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The path to be validated.</param>
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record ValidatePathQuery(
|
||||
string? Path
|
||||
) : IRequest<PathValidResponse>;
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to validate a file system path.
|
||||
@@ -34,6 +34,6 @@ public class ValidatePathQueryHandler : IRequestHandler<ValidatePathQuery, PathV
|
||||
/// </returns>
|
||||
public ValueTask<PathValidResponse> Handle(ValidatePathQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return ValueTask.FromResult(new PathValidResponse(_pathService.IsValidPath(request.Path)));
|
||||
return ValueTask.FromResult(new PathValidResponse(_pathService.IsValidPath(request.Path!)));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="ValidatePathQuery"/>.
|
||||
@@ -15,6 +15,6 @@ public class ValidatePathQueryValidator : AbstractValidator<ValidatePathQuery>
|
||||
/// </summary>
|
||||
public ValidatePathQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+8
-3
@@ -1,14 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Mediator;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Query for retrieving the thumbnail of a file at a path.
|
||||
/// </summary>
|
||||
/// <param name="Path">The file path of the image to generate the thumbnail from.</param>
|
||||
/// <param name="Quality">The desired quality of the thumbnail image (e.g., resolution or compression level).</param>
|
||||
public record GetThumbnailQuery(string Path, int Quality) : IRequest<ErrorOr<ThumbnailResponse>>;
|
||||
[DebuggerDisplay("Path: {Path}")]
|
||||
public record GetThumbnailQuery(
|
||||
string? Path,
|
||||
int Quality
|
||||
) : IRequest<ErrorOr<ThumbnailResponse>>;
|
||||
+8
-11
@@ -1,15 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the file thumbnail.
|
||||
@@ -17,17 +17,14 @@ namespace Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail
|
||||
public class GetThumbnailQueryHandler : IRequestHandler<GetThumbnailQuery, ErrorOr<ThumbnailResponse>>
|
||||
{
|
||||
private readonly IThumbnailService _thumbnailsService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThumbnailQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="thumbnailsService">Injected service for handling thumbnails.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public GetThumbnailQueryHandler(IThumbnailService thumbnailsService, IMapper mapper)
|
||||
public GetThumbnailQueryHandler(IThumbnailService thumbnailsService)
|
||||
{
|
||||
_thumbnailsService = thumbnailsService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,7 +35,7 @@ public class GetThumbnailQueryHandler : IRequestHandler<GetThumbnailQuery, Error
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> containing either a thumbnail, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<ThumbnailResponse>> Handle(GetThumbnailQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
ErrorOr<Thumbnail> result = await _thumbnailsService.GetThumbnailAsync(request.Path, request.Quality, cancellationToken);
|
||||
return await ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(_mapper.Map<ThumbnailResponse>(values)), errors => errors));
|
||||
ErrorOr<Thumbnail> result = await _thumbnailsService.GetThumbnailAsync(request.Path!, request.Quality, cancellationToken);
|
||||
return await ValueTask.FromResult(result.Match(value => ErrorOrFactory.From(value.ToResponse()), errors => errors));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -3,7 +3,7 @@ using FluentValidation;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.FileManagement.Thumbnails.Queries.GetThumbnail;
|
||||
namespace Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetThumbnailQuery"/>.
|
||||
@@ -15,7 +15,7 @@ public class GetThumbnailQueryValidator : AbstractValidator<GetThumbnailQuery>
|
||||
/// </summary>
|
||||
public GetThumbnailQueryValidator()
|
||||
{
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
|
||||
RuleFor(x => x.Quality).InclusiveBetween(0, 100).WithMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Code);
|
||||
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
RuleFor(x => x.Quality).InclusiveBetween(0, 100).WithMessage(Errors.Thumbnails.ImageQaulityMustBeBetweenZeroAndOneHundred.Description);
|
||||
}
|
||||
}
|
||||
+12
-10
@@ -1,12 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.MediaContributors;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
@@ -31,12 +32,13 @@ namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Comma
|
||||
/// <param name="ISBNs">The list of ISBN (International Standard Book Number) of the book.</param>
|
||||
/// <param name="Contributors">The list of media contributors (actors, directors, etc) starring in this book.</param>
|
||||
/// <param name="Ratings">The list of ratings for this book.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public record AddBookCommand(
|
||||
WrittenContentMetadataModel Metadata,
|
||||
WrittenContentMetadataEntity? Metadata,
|
||||
BookFormat? Format,
|
||||
string? Edition,
|
||||
int? VolumeNumber,
|
||||
BookSeriesModel? Series,
|
||||
BookSeriesEntity? Series,
|
||||
string? ASIN,
|
||||
string? GoodreadsId,
|
||||
string? LCCN,
|
||||
@@ -46,7 +48,7 @@ public record AddBookCommand(
|
||||
string? GoogleBooksId,
|
||||
string? BarnesAndNobleId,
|
||||
string? AppleBooksId,
|
||||
List<IsbnModel> ISBNs,
|
||||
List<MediaContributorModel> Contributors,
|
||||
List<BookRatingModel> Ratings
|
||||
) : IRequest<ErrorOr<Book>>;
|
||||
List<IsbnEntity>? ISBNs,
|
||||
List<MediaContributorEntity>? Contributors,
|
||||
List<BookRatingEntity>? Ratings
|
||||
) : IRequest<ErrorOr<BookResponse>>;
|
||||
+14
-16
@@ -2,16 +2,17 @@
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Models.MediaContributors;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
using MapsterMapper;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,20 +26,17 @@ namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Comma
|
||||
/// <summary>
|
||||
/// Handler for the command to add a book.
|
||||
/// </summary>
|
||||
public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Book>>
|
||||
public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<BookResponse>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddBookCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="mapper">Injected service for mapping objects.</param>
|
||||
public AddBookCommandHandler(IUnitOfWork unitOfWork, IMapper mapper)
|
||||
public AddBookCommandHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,11 +47,11 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Book"/>, or an error message.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<Book>> Handle(AddBookCommand request, CancellationToken cancellationToken)
|
||||
public async ValueTask<ErrorOr<BookResponse>> Handle(AddBookCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// TODO: update Api.Book.md documentation when the functionality is fully implemented
|
||||
List<MediaContributorId> contributorIds = [];
|
||||
foreach (MediaContributorModel mediaContributor in request.Contributors)
|
||||
foreach (MediaContributorEntity mediaContributor in request.Contributors!)
|
||||
{
|
||||
// TODO: add logic to search the media contributors repository for existing contributors, based on the provided names
|
||||
}
|
||||
@@ -63,10 +61,10 @@ public class AddBookCommandHandler : IRequestHandler<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 = request.Ratings.ConvertAll(rating => BookRating.Create(
|
||||
List<ErrorOr<BookRating>> domainRatingsResult = request.Ratings!.ConvertAll(rating => BookRating.Create(
|
||||
rating.Value ?? default,
|
||||
rating.MaxValue ?? default,
|
||||
Optional<BookRatingSource>.FromNullable(rating.Source.HasValue ? (BookRatingSource)(int)rating.Source : 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).ToList();
|
||||
@@ -75,7 +73,7 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
|
||||
|
||||
List<BookRating> domainRatings = domainRatingsResult.Select(rating => rating.Value).ToList();
|
||||
|
||||
List<ErrorOr<Genre>> domainGenresResult = request.Metadata.Genres!.ConvertAll(genre => Genre.Create(genre.Name!));
|
||||
List<ErrorOr<Genre>> domainGenresResult = request.Metadata!.Genres!.ConvertAll(genre => Genre.Create(genre.Name!));
|
||||
errors = domainGenresResult.Where(genreResult => genreResult.IsError).SelectMany(genreResult => genreResult.Errors).ToList();
|
||||
if (errors.Count != 0)
|
||||
return errors;
|
||||
@@ -87,7 +85,7 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
|
||||
return errors;
|
||||
List<Tag> domainTags = domainTagsResult.Select(tag => tag.Value).ToList();
|
||||
|
||||
List<ErrorOr<Isbn>> domainIsbnsResult = request.ISBNs.ConvertAll(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!));
|
||||
List<ErrorOr<Isbn>> domainIsbnsResult = request.ISBNs!.ConvertAll(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!));
|
||||
errors = domainIsbnsResult.Where(isbnResult => isbnResult.IsError).SelectMany(isbnResult => isbnResult.Errors).ToList();
|
||||
if (errors.Count != 0)
|
||||
return errors;
|
||||
@@ -163,12 +161,12 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
|
||||
return createBookResult.Errors;
|
||||
|
||||
IBookRepository bookRepository = _unitOfWork.GetRepository<IBookRepository>();
|
||||
BookModel persistenceBook = _mapper.Map<BookModel>(createBookResult.Value);
|
||||
BookEntity persistenceBook = createBookResult.Value.ToRepositoryEntity();
|
||||
ErrorOr<Created> insertBookResult = await bookRepository.InsertAsync(persistenceBook, cancellationToken).ConfigureAwait(false);
|
||||
if (insertBookResult.IsError)
|
||||
return insertBookResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return createBookResult.Value;
|
||||
return persistenceBook.ToResponse();
|
||||
}
|
||||
}
|
||||
+133
-100
@@ -17,197 +17,230 @@ public class AddBookCommandValidator : AbstractValidator<AddBookCommand>
|
||||
public AddBookCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.Metadata)
|
||||
.NotNull().WithMessage(Errors.Metadata.MetadataCannotBeNull.Code)
|
||||
.NotNull().WithMessage(Errors.Metadata.MetadataCannotBeNull.Description)
|
||||
.ChildRules(metadata =>
|
||||
{
|
||||
metadata.RuleFor(m => m.Title)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.TitleCannotBeEmpty.Code)
|
||||
.MaximumLength(255).WithMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Code);
|
||||
metadata.RuleFor(m => m.OriginalTitle)
|
||||
.MaximumLength(255).When(m => m.OriginalTitle is not null)
|
||||
.WithMessage(Errors.Metadata.OriginalTitleMustBeMaximum255CharactersLong.Code);
|
||||
metadata.RuleFor(m => m.Description)
|
||||
.MaximumLength(2000).When(m => m.Description is not null)
|
||||
.WithMessage(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong.Code);
|
||||
metadata.RuleFor(m => m.ReleaseInfo)
|
||||
.NotNull().WithMessage(Errors.Metadata.ReleaseInfoCannotBeNull.Code)
|
||||
metadata.RuleFor(m => m!.Title)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.TitleCannotBeEmpty.Description)
|
||||
.MaximumLength(255).WithMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Description);
|
||||
metadata.RuleFor(m => m!.OriginalTitle)
|
||||
.MaximumLength(255).When(m => m!.OriginalTitle is not null)
|
||||
.WithMessage(Errors.Metadata.OriginalTitleMustBeMaximum255CharactersLong.Description);
|
||||
metadata.RuleFor(m => m!.Description)
|
||||
.MaximumLength(2000).When(m => m!.Description is not null)
|
||||
.WithMessage(Errors.Metadata.DescriptionMustBeMaximum2000CharactersLong.Description);
|
||||
metadata.RuleFor(m => m!.ReleaseInfo)
|
||||
.NotNull().WithMessage(Errors.Metadata.ReleaseInfoCannotBeNull.Description)
|
||||
.ChildRules(ri =>
|
||||
{
|
||||
ri.RuleFor(r => r!.OriginalReleaseYear)
|
||||
.InclusiveBetween(1, 9999).When(r => r!.OriginalReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.OriginalReleaseYearMustBeBetween1And9999.Code);
|
||||
.WithMessage(Errors.Metadata.OriginalReleaseYearMustBeBetween1And9999.Description);
|
||||
ri.RuleFor(r => r!.ReReleaseYear)
|
||||
.InclusiveBetween(1, 9999).When(r => r!.ReReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.ReReleaseYearMustBeBetween1And9999.Code);
|
||||
.WithMessage(Errors.Metadata.ReReleaseYearMustBeBetween1And9999.Description);
|
||||
ri.RuleFor(r => r!.ReleaseCountry)
|
||||
.Matches("^[A-Za-z]{2}$").When(r => r!.ReleaseCountry is not null)
|
||||
.WithMessage(Errors.Metadata.CountryCodeMustBe2CharactersLong.Code);
|
||||
.WithMessage(Errors.Metadata.CountryCodeMustBe2CharactersLong.Description);
|
||||
ri.RuleFor(r => r!.ReleaseVersion)
|
||||
.MaximumLength(50).When(r => r!.ReleaseVersion is not null)
|
||||
.WithMessage(Errors.Metadata.ReleaseVersionMustBeMaximum50CharactersLong.Code);
|
||||
.WithMessage(Errors.Metadata.ReleaseVersionMustBeMaximum50CharactersLong.Description);
|
||||
ri.RuleFor(r => r!.OriginalReleaseYear)
|
||||
.Must((releaseInfo, originalReleaseYear) =>
|
||||
!releaseInfo!.OriginalReleaseDate.HasValue ||
|
||||
!releaseInfo.OriginalReleaseYear.HasValue ||
|
||||
originalReleaseYear == releaseInfo.OriginalReleaseDate.Value.Year)
|
||||
.When(r => r!.OriginalReleaseDate.HasValue && r.OriginalReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.OriginalReleaseDateAndYearMustMatch.Description);
|
||||
ri.RuleFor(r => r!.ReReleaseYear)
|
||||
.Must((releaseInfo, reReleaseYear) =>
|
||||
!releaseInfo!.ReReleaseYear.HasValue ||
|
||||
!releaseInfo.OriginalReleaseYear.HasValue ||
|
||||
reReleaseYear >= releaseInfo.OriginalReleaseYear)
|
||||
.When(r => r!.ReReleaseYear.HasValue && r.OriginalReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear.Code);
|
||||
!releaseInfo!.ReReleaseDate.HasValue ||
|
||||
!releaseInfo.ReReleaseYear.HasValue ||
|
||||
reReleaseYear == releaseInfo.ReReleaseDate.Value.Year)
|
||||
.When(r => r!.ReReleaseDate.HasValue && r.ReReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.ReReleaseDateAndYearMustMatch.Description);
|
||||
ri.RuleFor(r => r!.ReReleaseYear)
|
||||
.Must((releaseInfo, reReleaseYear) =>
|
||||
!releaseInfo!.ReReleaseYear.HasValue ||
|
||||
!releaseInfo.OriginalReleaseYear.HasValue ||
|
||||
reReleaseYear >= releaseInfo.OriginalReleaseYear)
|
||||
.When(r => r!.ReReleaseYear.HasValue && r.OriginalReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear.Description);
|
||||
ri.RuleFor(r => r!.ReReleaseDate)
|
||||
.Must((releaseInfo, reReleaseDate) =>
|
||||
!releaseInfo!.ReReleaseDate.HasValue ||
|
||||
!releaseInfo.OriginalReleaseDate.HasValue ||
|
||||
reReleaseDate >= releaseInfo.OriginalReleaseDate)
|
||||
.When(r => r!.ReReleaseDate.HasValue && r.OriginalReleaseDate.HasValue)
|
||||
.WithMessage(Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Code);
|
||||
.WithMessage(Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Description);
|
||||
ri.RuleFor(r => r!.ReReleaseYear)
|
||||
.Must((releaseInfo, reReleaseYear) =>
|
||||
!releaseInfo!.ReReleaseDate.HasValue ||
|
||||
!releaseInfo.ReReleaseYear.HasValue ||
|
||||
reReleaseYear == releaseInfo.ReReleaseDate.Value.Year)
|
||||
.When(r => r!.ReReleaseDate.HasValue && r.ReReleaseYear.HasValue)
|
||||
.WithMessage(Errors.Metadata.ReReleaseDateAndYearMustMatch.Description);
|
||||
});
|
||||
metadata.RuleFor(m => m.Genres)
|
||||
.NotNull().WithMessage(Errors.Metadata.GenresListCannotBeNull.Code);
|
||||
metadata.RuleForEach(m => m.Genres)
|
||||
metadata.RuleFor(m => m!.Genres)
|
||||
.NotNull().WithMessage(Errors.Metadata.GenresListCannotBeNull.Description);
|
||||
metadata.RuleForEach(m => m!.Genres)
|
||||
.ChildRules(g =>
|
||||
g.RuleFor(genre => genre.Name)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.GenreNameCannotBeEmpty.Code)
|
||||
.MaximumLength(50).WithMessage(Errors.Metadata.GenreNameMustBeMaximum50CharactersLong.Code));
|
||||
metadata.RuleFor(m => m.Tags)
|
||||
.NotNull().WithMessage(Errors.Metadata.TagsListCannotBeNull.Code);
|
||||
metadata.RuleForEach(m => m.Tags)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.GenreNameCannotBeEmpty.Description)
|
||||
.MaximumLength(50).WithMessage(Errors.Metadata.GenreNameMustBeMaximum50CharactersLong.Description));
|
||||
metadata.RuleFor(m => m!.Tags)
|
||||
.NotNull().WithMessage(Errors.Metadata.TagsListCannotBeNull.Description);
|
||||
metadata.RuleForEach(m => m!.Tags)
|
||||
.ChildRules(t =>
|
||||
t.RuleFor(tag => tag.Name)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.TagNameCannotBeEmpty.Code)
|
||||
.MaximumLength(50).WithMessage(Errors.Metadata.TagNameMustBeMaximum50CharactersLong.Code));
|
||||
metadata.RuleFor(m => m.Language)
|
||||
.ChildRules(l =>
|
||||
.NotEmpty().WithMessage(Errors.Metadata.TagNameCannotBeEmpty.Description)
|
||||
.MaximumLength(50).WithMessage(Errors.Metadata.TagNameMustBeMaximum50CharactersLong.Description));
|
||||
metadata.RuleFor(m => m!.Language)
|
||||
.Custom((language, context) =>
|
||||
{
|
||||
l.RuleFor(x => x!.LanguageCode)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.LanguageCodeCannotBeEmpty.Code)
|
||||
.MaximumLength(2).WithMessage(Errors.Metadata.LanguageCodeMustBe2CharactersLong.Code);
|
||||
l.RuleFor(x => x!.LanguageName)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.LanguageNameCannotBeEmpty.Code)
|
||||
.MaximumLength(50).WithMessage(Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Code);
|
||||
l.RuleFor(x => x!.NativeName)
|
||||
.MaximumLength(50).When(x => x!.NativeName is not null)
|
||||
.WithMessage(Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Code);
|
||||
}).When(m => m.Language is not null);
|
||||
metadata.RuleFor(m => m.OriginalLanguage)
|
||||
.ChildRules(l =>
|
||||
if (language is null)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(language.LanguageCode))
|
||||
context.AddFailure("Language.LanguageCode", Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
|
||||
else if (language.LanguageCode.Length > 2)
|
||||
context.AddFailure("Language.LanguageCode", Errors.Metadata.LanguageCodeMustBe2CharactersLong.Description);
|
||||
|
||||
if (string.IsNullOrEmpty(language.LanguageName))
|
||||
context.AddFailure("Language.LanguageName", Errors.Metadata.LanguageNameCannotBeEmpty.Description);
|
||||
else if (language.LanguageName.Length > 50)
|
||||
context.AddFailure("Language.LanguageName", Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Description);
|
||||
|
||||
if (language.NativeName != null && language.NativeName.Length > 50)
|
||||
context.AddFailure("Language.NativeName", Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Description);
|
||||
});
|
||||
metadata.RuleFor(m => m!.OriginalLanguage)
|
||||
.Custom((language, context) =>
|
||||
{
|
||||
l.RuleFor(x => x!.LanguageCode)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.LanguageCodeCannotBeEmpty.Code)
|
||||
.MaximumLength(2).WithMessage(Errors.Metadata.LanguageCodeMustBe2CharactersLong.Code);
|
||||
l.RuleFor(x => x!.LanguageName)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.LanguageNameCannotBeEmpty.Code)
|
||||
.MaximumLength(50).WithMessage(Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Code);
|
||||
l.RuleFor(x => x!.NativeName)
|
||||
.MaximumLength(50).When(x => x!.NativeName is not null)
|
||||
.WithMessage(Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Code);
|
||||
}).When(m => m.OriginalLanguage is not null);
|
||||
metadata.RuleFor(m => m.Publisher)
|
||||
.MaximumLength(100).When(m => m.Publisher is not null)
|
||||
.WithMessage(Errors.WrittenContent.PublisherMustBeMaximum100CharactersLong.Code);
|
||||
metadata.RuleFor(m => m.PageCount)
|
||||
.GreaterThan(0).When(m => m.PageCount.HasValue)
|
||||
.WithMessage(Errors.WrittenContent.PageCountMustBeGreaterThanZero.Code);
|
||||
if (language is null)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(language.LanguageCode))
|
||||
context.AddFailure("OriginalLanguage.LanguageCode", Errors.Metadata.LanguageCodeCannotBeEmpty.Description);
|
||||
else if (language.LanguageCode.Length > 2)
|
||||
context.AddFailure("OriginalLanguage.LanguageCode", Errors.Metadata.LanguageCodeMustBe2CharactersLong.Description);
|
||||
|
||||
if (string.IsNullOrEmpty(language.LanguageName))
|
||||
context.AddFailure("OriginalLanguage.LanguageName", Errors.Metadata.LanguageNameCannotBeEmpty.Description);
|
||||
else if (language.LanguageName.Length > 50)
|
||||
context.AddFailure("OriginalLanguage.LanguageName", Errors.Metadata.LanguageNameMustBeMaximum50CharactersLong.Description);
|
||||
|
||||
if (language.NativeName != null && language.NativeName.Length > 50)
|
||||
context.AddFailure("OriginalLanguage.NativeName", Errors.Metadata.LanguageNativeNameMustBeMaximum50CharactersLong.Description);
|
||||
});
|
||||
metadata.RuleFor(m => m!.Publisher)
|
||||
.MaximumLength(100).When(m => m!.Publisher is not null)
|
||||
.WithMessage(Errors.WrittenContent.PublisherMustBeMaximum100CharactersLong.Description);
|
||||
metadata.RuleFor(m => m!.PageCount)
|
||||
.GreaterThan(0).When(m => m!.PageCount.HasValue)
|
||||
.WithMessage(Errors.WrittenContent.PageCountMustBeGreaterThanZero.Description);
|
||||
});
|
||||
RuleFor(x => x.Format)
|
||||
.IsInEnum().When(f => f.Format is not null).WithMessage(Errors.WrittenContent.UnknownBookFormat.Code);
|
||||
.IsInEnum().When(f => f.Format is not null).WithMessage(Errors.WrittenContent.UnknownBookFormat.Description);
|
||||
RuleFor(x => x.Edition)
|
||||
.MaximumLength(50).When(x => x.Edition is not null)
|
||||
.WithMessage(Errors.WrittenContent.EditionMustBeMaximum50CharactersLong.Code);
|
||||
.WithMessage(Errors.WrittenContent.EditionMustBeMaximum50CharactersLong.Description);
|
||||
RuleFor(x => x.VolumeNumber)
|
||||
.GreaterThan(0).When(x => x.VolumeNumber.HasValue)
|
||||
.WithMessage(Errors.WrittenContent.VolumeNumberMustBeGreaterThanZero.Code);
|
||||
.WithMessage(Errors.WrittenContent.VolumeNumberMustBeGreaterThanZero.Description);
|
||||
RuleFor(x => x.Series)
|
||||
.ChildRules(s =>
|
||||
s.RuleFor(series => series!.Title)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.TitleCannotBeEmpty.Code)
|
||||
.MaximumLength(255)).WithMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Code)
|
||||
.NotEmpty().WithMessage(Errors.Metadata.TitleCannotBeEmpty.Description)
|
||||
.MaximumLength(255)).WithMessage(Errors.Metadata.TitleMustBeMaximum255CharactersLong.Description)
|
||||
.When(x => x.Series is not null);
|
||||
RuleFor(x => x.ASIN)
|
||||
.Length(10).When(x => x.ASIN is not null)
|
||||
.WithMessage(Errors.WrittenContent.AsinMustBe10CharactersLong.Code);
|
||||
.WithMessage(Errors.WrittenContent.AsinMustBe10CharactersLong.Description);
|
||||
RuleFor(x => x.GoodreadsId)
|
||||
.Matches(@"^\d+$").When(x => x.GoodreadsId is not null)
|
||||
.WithMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Code);
|
||||
.WithMessage(Errors.WrittenContent.GoodreadsIdMustBeNumeric.Description);
|
||||
RuleFor(x => x.LCCN)
|
||||
.Matches(@"^[a-z]{0,3}\d{8,10}$").WithMessage(Errors.WrittenContent.InvalidLccnFormat.Code)
|
||||
.Matches(@"^[a-z]{0,3}\d{8,10}$").WithMessage(Errors.WrittenContent.InvalidLccnFormat.Description)
|
||||
.When(x => x.LCCN is not null);
|
||||
RuleFor(x => x.OCLCNumber)
|
||||
.Matches(@"^(ocm\d{8}|ocn\d{9,}|on\d{10,}|\(OCoLC\)\d{8,}|\d{8,})$").When(x => x.OCLCNumber is not null)
|
||||
.WithMessage(Errors.WrittenContent.InvalidOclcFormat.Code);
|
||||
.WithMessage(Errors.WrittenContent.InvalidOclcFormat.Description);
|
||||
RuleFor(x => x.OpenLibraryId)
|
||||
.Matches(@"^OL[1-9]\d*[AMW]$").When(x => x.OpenLibraryId is not null)
|
||||
.WithMessage(Errors.WrittenContent.InvalidOpenLibraryId.Code);
|
||||
.WithMessage(Errors.WrittenContent.InvalidOpenLibraryId.Description);
|
||||
RuleFor(x => x.LibraryThingId)
|
||||
.MaximumLength(50).When(x => x.LibraryThingId is not null)
|
||||
.WithMessage(Errors.WrittenContent.LibraryThingIdMustBeMaximum50CharactersLong.Code);
|
||||
.WithMessage(Errors.WrittenContent.LibraryThingIdMustBeMaximum50CharactersLong.Description);
|
||||
RuleFor(x => x.GoogleBooksId)
|
||||
.Length(12).WithMessage(Errors.WrittenContent.GoogleBooksIdMustBe12CharactersLong.Code)
|
||||
.Matches(@"^[A-Za-z0-9_-]{12}$").WithMessage(Errors.WrittenContent.InvalidGoogleBooksIdFormat.Code)
|
||||
.Length(12).WithMessage(Errors.WrittenContent.GoogleBooksIdMustBe12CharactersLong.Description)
|
||||
.Matches(@"^[A-Za-z0-9_-]{12}$").WithMessage(Errors.WrittenContent.InvalidGoogleBooksIdFormat.Description)
|
||||
.When(x => x.GoogleBooksId is not null);
|
||||
RuleFor(x => x.BarnesAndNobleId)
|
||||
.Length(10).WithMessage(Errors.WrittenContent.BarnesAndNoblesIdMustBe10CharactersLong.Code)
|
||||
.Matches(@"^\d{10}$").WithMessage(Errors.WrittenContent.InvalidBarnesAndNoblesIdFormat.Code)
|
||||
.Length(10).WithMessage(Errors.WrittenContent.BarnesAndNoblesIdMustBe10CharactersLong.Description)
|
||||
.Matches(@"^\d{10}$").WithMessage(Errors.WrittenContent.InvalidBarnesAndNoblesIdFormat.Description)
|
||||
.When(x => x.BarnesAndNobleId is not null);
|
||||
RuleFor(x => x.AppleBooksId)
|
||||
.Matches(@"^id\d+$").When(x => x.AppleBooksId is not null)
|
||||
.WithMessage(Errors.WrittenContent.InvalidAppleBooksIdFormat.Code);
|
||||
.WithMessage(Errors.WrittenContent.InvalidAppleBooksIdFormat.Description);
|
||||
RuleFor(x => x.ISBNs)
|
||||
.NotNull().WithMessage(Errors.WrittenContent.IsbnListCannotBeNull.Code);
|
||||
.NotNull().WithMessage(Errors.WrittenContent.IsbnListCannotBeNull.Description);
|
||||
RuleForEach(x => x.ISBNs)
|
||||
.ChildRules(isbn =>
|
||||
{
|
||||
isbn.RuleFor(i => i.Value)
|
||||
.NotEmpty().WithMessage(Errors.WrittenContent.IsbnValueCannotBeEmpty.Code)
|
||||
.NotEmpty().WithMessage(Errors.WrittenContent.IsbnValueCannotBeEmpty.Description)
|
||||
.Matches(i => i.Format == IsbnFormat.Isbn13
|
||||
? @"^(?:ISBN(?:-13)?:? )?(?=[0-9]{13}$|(?=(?:[0-9]+[-\ ]){4})[-\ 0-9]{17}$)97[89][-\ ]?[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9]$"
|
||||
: @"^(?:ISBN(?:-10)?:? )?(?=[0-9X]{10}$|(?=(?:[0-9]+[-\ ]){3})[-\ 0-9X]{13}$)[0-9]{1,5}[-\ ]?[0-9]+[-\ ]?[0-9]+[-\ ]?[0-9X]$")
|
||||
.WithMessage(i => i.Format == IsbnFormat.Isbn13
|
||||
? Errors.WrittenContent.InvalidIsbn13Format.Code
|
||||
: Errors.WrittenContent.InvalidIsbn10Format.Code);
|
||||
? Errors.WrittenContent.InvalidIsbn13Format.Description
|
||||
: Errors.WrittenContent.InvalidIsbn10Format.Description);
|
||||
isbn.RuleFor(i => i.Format)
|
||||
.IsInEnum().WithMessage(Errors.WrittenContent.UnknownIsbnFormat.Code);
|
||||
.IsInEnum().WithMessage(Errors.WrittenContent.UnknownIsbnFormat.Description);
|
||||
});
|
||||
RuleFor(x => x.Contributors)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorsListCannotBeNull.Code);
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorsListCannotBeNull.Description);
|
||||
RuleForEach(x => x.Contributors)
|
||||
.ChildRules(contributor =>
|
||||
{
|
||||
contributor.RuleFor(c => c.Name)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorNameCannotBeEmpty.Code)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorNameCannotBeEmpty.Description)
|
||||
.ChildRules(name =>
|
||||
{
|
||||
name.RuleFor(n => n!.DisplayName)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code)
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Code)
|
||||
.MaximumLength(100).WithMessage(Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Code);
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Description)
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.ContributorDisplayNameCannotBeEmpty.Description)
|
||||
.MaximumLength(100).WithMessage(Errors.MediaContributor.ContributorDisplayNameMustBeMaximum100CharactersLong.Description);
|
||||
name.RuleFor(n => n!.LegalName)
|
||||
.MaximumLength(100).When(n => n!.LegalName is not null)
|
||||
.WithMessage(Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Code);
|
||||
.WithMessage(Errors.MediaContributor.ContributorLegalNameMustBeMaximum100CharactersLong.Description);
|
||||
});
|
||||
contributor.RuleFor(c => c.Role)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorRoleCannotBeNull.Code)
|
||||
.NotNull().WithMessage(Errors.MediaContributor.ContributorRoleCannotBeNull.Description)
|
||||
.ChildRules(role =>
|
||||
{
|
||||
role.RuleFor(r => r!.Name)
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.RoleNameCannotBeEmpty.Code)
|
||||
.MaximumLength(50).WithMessage(Errors.MediaContributor.RoleNameMustBeMaximum50CharactersLong.Code);
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.RoleNameCannotBeEmpty.Description)
|
||||
.MaximumLength(50).WithMessage(Errors.MediaContributor.RoleNameMustBeMaximum50CharactersLong.Description);
|
||||
role.RuleFor(r => r!.Category)
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.RoleCategoryCannotBeEmpty.Code)
|
||||
.MaximumLength(50).WithMessage(Errors.MediaContributor.RoleCategoryMustBeMaximum50CharactersLong.Code);
|
||||
.NotEmpty().WithMessage(Errors.MediaContributor.RoleCategoryCannotBeEmpty.Description)
|
||||
.MaximumLength(50).WithMessage(Errors.MediaContributor.RoleCategoryMustBeMaximum50CharactersLong.Description);
|
||||
});
|
||||
});
|
||||
RuleFor(x => x.Ratings)
|
||||
.NotNull().WithMessage(Errors.Metadata.RatingsListCannotBeNull.Code);
|
||||
.NotNull().WithMessage(Errors.Metadata.RatingsListCannotBeNull.Description);
|
||||
RuleForEach(x => x.Ratings)
|
||||
.ChildRules(rating =>
|
||||
{
|
||||
rating.RuleFor(r => r.Value)
|
||||
.GreaterThan(0).WithMessage(Errors.Metadata.RatingValueMustBePositive.Code)
|
||||
.Must((r, value) => value <= r.MaxValue).WithMessage(Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue.Code);
|
||||
.GreaterThan(0).WithMessage(Errors.Metadata.RatingValueMustBePositive.Description)
|
||||
.Must((r, value) => value <= r.MaxValue).WithMessage(Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue.Description);
|
||||
rating.RuleFor(r => r.MaxValue)
|
||||
.GreaterThan(0).WithMessage(Errors.Metadata.RatingMaxValueMustBePositive.Code);
|
||||
.GreaterThan(0).WithMessage(Errors.Metadata.RatingMaxValueMustBePositive.Description);
|
||||
rating.RuleFor(r => r.VoteCount)
|
||||
.GreaterThanOrEqualTo(0).When(r => r.VoteCount.HasValue)
|
||||
.WithMessage(Errors.Metadata.RatingVoteCountMustBePositive.Code);
|
||||
.WithMessage(Errors.Metadata.RatingVoteCountMustBePositive.Description);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
@@ -10,4 +10,4 @@ namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queri
|
||||
/// <summary>
|
||||
/// Query for getting all books.
|
||||
/// </summary>
|
||||
public record class GetBooksQuery() : IRequest<ErrorOr<IEnumerable<Book>>>;
|
||||
public record class GetBooksQuery() : IRequest<ErrorOr<IEnumerable<BookResponse>>>;
|
||||
+10
-8
@@ -2,9 +2,9 @@
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using Mapster;
|
||||
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -16,7 +16,7 @@ namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queri
|
||||
/// <summary>
|
||||
/// Handler for the query to get all books.
|
||||
/// </summary>
|
||||
public class GetBooksQueryHandler : IRequestHandler<GetBooksQuery, ErrorOr<IEnumerable<Book>>>
|
||||
public class GetBooksQueryHandler : IRequestHandler<GetBooksQuery, ErrorOr<IEnumerable<BookResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
@@ -35,12 +35,14 @@ public class GetBooksQueryHandler : IRequestHandler<GetBooksQuery, ErrorOr<IEnum
|
||||
/// <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="Book"/>, or an error message.
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
public async ValueTask<ErrorOr<IEnumerable<Book>>> Handle(GetBooksQuery request, CancellationToken cancellationToken)
|
||||
public async ValueTask<ErrorOr<IEnumerable<BookResponse>>> Handle(GetBooksQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// get a books repository
|
||||
IBookRepository bookRepository = _unitOfWork.GetRepository<IBookRepository>();
|
||||
ErrorOr<IEnumerable<BookModel>> getBooksResult = await bookRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getBooksResult.Match(values => ErrorOrFactory.From(values.Adapt<IEnumerable<Book>>()), errors => errors);
|
||||
// get all books from the book repository
|
||||
ErrorOr<IEnumerable<BookEntity>> getBooksResult = await bookRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
|
||||
return getBooksResult.Match(result => ErrorOrFactory.From(getBooksResult.Value.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user