Refactors directory structure for commands and queries

This commit is contained in:
BinaryAlley committed 2024-09-23 08:39:30 +03:00
1 parent 35fe931173
commit 712a0f2b27
54 files changed
+98 -88

No files matched your search

@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
/// <summary> /// <summary>
/// Query for retrieving the list of directories at a path. /// Query for retrieving the list of directories at a path.
@@ -11,7 +11,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
/// <summary> /// <summary>
/// Handler for the query to get all directories. /// Handler for the query to get all directories.
@@ -44,7 +44,7 @@ public class GetDirectoriesQueryHandler : IRequestHandler<GetDirectoriesQuery, E
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<DirectoryResponse>>> Handle(GetDirectoriesQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<DirectoryResponse>>> Handle(GetDirectoriesQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path); var result = _directoryService.GetSubdirectories(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<DirectoryResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<DirectoryResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetDirectoriesQuery"/>. /// Validates the needed validation rules for <see cref="GetDirectoriesQuery"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
/// <summary> /// <summary>
/// Query for retrieving the tree of directories of a path. /// Query for retrieving the tree of directories of a path.
@@ -14,7 +14,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
/// <summary> /// <summary>
/// Handler for the query to get a directory tree. /// Handler for the query to get a directory tree.
@@ -56,24 +56,24 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
{ {
List<FileSystemTreeNodeResponse> result = []; List<FileSystemTreeNodeResponse> result = [];
// retrieve the list of drives // retrieve the list of drives
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> getDrivesResult = GetDrives(); var getDrivesResult = GetDrives();
if (getDrivesResult.IsError) if (getDrivesResult.IsError)
return getDrivesResult.Errors; return getDrivesResult.Errors;
result.AddRange(getDrivesResult.Value); result.AddRange(getDrivesResult.Value);
ErrorOr<IEnumerable<PathSegment>> pathPartsResults = _pathService.ParsePath(request.Path); var pathPartsResults = _pathService.ParsePath(request.Path);
if (pathPartsResults.IsError) if (pathPartsResults.IsError)
return pathPartsResults.Errors; return pathPartsResults.Errors;
List<PathSegment> pathParts = pathPartsResults.Value.ToList(); var pathParts = pathPartsResults.Value.ToList();
string currentPath = pathParts[0].Name; var currentPath = pathParts[0].Name;
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out FileSystemTreeNodeResponse currentNode); var buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out var currentNode);
if (buildDirectoryTreeResult.IsError) if (buildDirectoryTreeResult.IsError)
return buildDirectoryTreeResult.Errors; return buildDirectoryTreeResult.Errors;
// add subdirectories of the last directory node // add subdirectories of the last directory node
ErrorOr<Success> loadChildrenResult = LoadChildren(currentNode, request.IncludeFiles); var loadChildrenResult = LoadChildren(currentNode, request.IncludeFiles);
if (loadChildrenResult.IsError) if (loadChildrenResult.IsError)
return loadChildrenResult.Errors; return loadChildrenResult.Errors;
return await ValueTask.FromResult(result); return await ValueTask.FromResult(result);
@@ -87,7 +87,7 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
/// </returns> /// </returns>
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> GetDrives() private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> GetDrives()
{ {
ErrorOr<IEnumerable<FileSystemItem>> driveResult = _driveService.GetDrives(); var driveResult = _driveService.GetDrives();
if (driveResult.IsError) if (driveResult.IsError)
return driveResult.Errors; return driveResult.Errors;
return ErrorOrFactory.From(driveResult.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()); return ErrorOrFactory.From(driveResult.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>());
@@ -104,21 +104,21 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> BuildDirectoryTree(List<FileSystemTreeNodeResponse> drives, List<PathSegment> pathParts, out FileSystemTreeNodeResponse currentNode) private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> BuildDirectoryTree(List<FileSystemTreeNodeResponse> drives, List<PathSegment> pathParts, out FileSystemTreeNodeResponse currentNode)
{ {
// find the root drive that matches the first part of the path // find the root drive that matches the first part of the path
FileSystemTreeNodeResponse drive = drives.First(d => d.Name.Contains(pathParts[0].Name)); var drive = drives.First(d => d.Name.Contains(pathParts[0].Name));
drive.IsExpanded = true; drive.IsExpanded = true;
currentNode = drive; currentNode = drive;
string currentPath = pathParts[0].Name; var currentPath = pathParts[0].Name;
// traverse the remaining path parts to build the tree structure // traverse the remaining path parts to build the tree structure
for (int i = 1; i < pathParts.Count; i++) for (var i = 1; i < pathParts.Count; i++)
{ {
ErrorOr<string> combinedPathResult = _pathService.CombinePath(currentPath, pathParts[i].Name); var combinedPathResult = _pathService.CombinePath(currentPath, pathParts[i].Name);
if (combinedPathResult.IsError) if (combinedPathResult.IsError)
return combinedPathResult.Errors; return combinedPathResult.Errors;
currentPath = combinedPathResult.Value; currentPath = combinedPathResult.Value;
// create a new node for the directory and add it as a child of the current node // create a new node for the directory and add it as a child of the current node
FileSystemTreeNodeResponse newNode = new FileSystemTreeNodeResponse var newNode = new FileSystemTreeNodeResponse
{ {
Path = currentPath, Path = currentPath,
Name = pathParts[i].Name, Name = pathParts[i].Name,
@@ -140,13 +140,13 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
private ErrorOr<Success> LoadChildren(FileSystemTreeNodeResponse node, bool includeFiles) private ErrorOr<Success> LoadChildren(FileSystemTreeNodeResponse node, bool includeFiles)
{ {
// get subdirectories under the current node's path // get subdirectories under the current node's path
ErrorOr<IEnumerable<Directory>> subDirectoriesResult = _directoryService.GetSubdirectories(node.Path); var subDirectoriesResult = _directoryService.GetSubdirectories(node.Path);
if (subDirectoriesResult.IsError) if (subDirectoriesResult.IsError)
return subDirectoriesResult.Errors; return subDirectoriesResult.Errors;
// add each subdirectory as a child node of the current directory // add each subdirectory as a child node of the current directory
foreach (Directory subDirectory in subDirectoriesResult.Value) foreach (var subDirectory in subDirectoriesResult.Value)
{ {
FileSystemTreeNodeResponse subDirNode = new FileSystemTreeNodeResponse var subDirNode = new FileSystemTreeNodeResponse
{ {
Name = subDirectory.Name, Name = subDirectory.Name,
Path = subDirectory.Id.Path, Path = subDirectory.Id.Path,
@@ -159,13 +159,13 @@ public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuer
if (includeFiles) if (includeFiles)
{ {
// get files under the current node's path // get files under the current node's path
ErrorOr<IEnumerable<File>> filesResult = _fileService.GetFiles(node.Path); var filesResult = _fileService.GetFiles(node.Path);
if (filesResult.IsError) if (filesResult.IsError)
return filesResult.Errors; return filesResult.Errors;
// add each file as a child node of the current directory // add each file as a child node of the current directory
foreach (File file in filesResult.Value) foreach (var file in filesResult.Value)
{ {
FileSystemTreeNodeResponse fileNode = new FileSystemTreeNodeResponse var fileNode = new FileSystemTreeNodeResponse
{ {
Name = file.Name, Name = file.Name,
Path = file.Id.Path, Path = file.Id.Path,
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetDirectoryTreeQuery"/>. /// Validates the needed validation rules for <see cref="GetDirectoryTreeQuery"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
/// <summary> /// <summary>
/// Query for retrieving the list of directories at a path. /// Query for retrieving the list of directories at a path.
@@ -11,7 +11,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
/// <summary> /// <summary>
/// Handler for the query to get all directories. /// Handler for the query to get all directories.
@@ -44,7 +44,7 @@ public class GetTreeDirectoriesQueryHandler : IRequestHandler<GetTreeDirectories
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeDirectoriesQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeDirectoriesQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path); var result = _directoryService.GetSubdirectories(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries; namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetTreeDirectoriesQuery"/>. /// Validates the needed validation rules for <see cref="GetTreeDirectoriesQuery"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Drives.Queries; namespace Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
/// <summary> /// <summary>
/// Query for retrieving the list of drives. /// Query for retrieving the list of drives.
@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Drives.Queries; namespace Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
/// <summary> /// <summary>
/// Handler for the query to get all drives. /// Handler for the query to get all drives.
@@ -43,7 +43,7 @@ public class GetDrivesQueryHandler : IRequestHandler<GetDrivesQuery, ErrorOr<IEn
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDrivesQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDrivesQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<FileSystemItem>> result = _driveService.GetDrives(); var result = _driveService.GetDrives();
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using Lumina.Contracts.Responses.FileManagement;
using Mediator; using Mediator;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.FileSystem.Queries; namespace Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSysem;
/// <summary> /// <summary>
/// Query for retrieving the file system type. /// Query for retrieving the file system type.
@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.FileSystem.Queries; namespace Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSysem;
/// <summary> /// <summary>
/// Handler for the query to get the file system type. /// Handler for the query to get the file system type.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries; namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
/// <summary> /// <summary>
/// Query for retrieving the list of files at a path. /// Query for retrieving the list of files at a path.
@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries; namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
/// <summary> /// <summary>
/// Handler for the query to get all files. /// Handler for the query to get all files.
@@ -43,7 +43,7 @@ public class GetFilesQueryHandler : IRequestHandler<GetFilesQuery, ErrorOr<IEnum
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<FileResponse>>> Handle(GetFilesQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<FileResponse>>> Handle(GetFilesQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path); var result = _fileService.GetFiles(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries; namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetFilesQuery"/>. /// Validates the needed validation rules for <see cref="GetFilesQuery"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries; namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
/// <summary> /// <summary>
/// Query for retrieving the list of files at a path. /// Query for retrieving the list of files at a path.
@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries; namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
/// <summary> /// <summary>
/// Handler for the query to get all files. /// Handler for the query to get all files.
@@ -43,7 +43,7 @@ public class GetTreeFilesQueryHandler : IRequestHandler<GetTreeFilesQuery, Error
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeFilesQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetTreeFilesQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path); var result = _fileService.GetFiles(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries; namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetTreeFilesQuery"/>. /// Validates the needed validation rules for <see cref="GetTreeFilesQuery"/>.
@@ -4,7 +4,7 @@ using Lumina.Contracts.Responses.FileManagement;
using Mediator; using Mediator;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands; namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
/// <summary> /// <summary>
/// Command for combining two file system path. /// Command for combining two file system path.
@@ -1,5 +1,6 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using ErrorOr; using ErrorOr;
using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Responses.FileManagement; using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Mapster; using Mapster;
@@ -8,7 +9,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands; namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
/// <summary> /// <summary>
/// Handler for the command to split a file system path. /// Handler for the command to split a file system path.
@@ -41,7 +42,7 @@ public class CombinePathCommandHandler : IRequestHandler<CombinePathCommand, Err
/// </returns> /// </returns>
public ValueTask<ErrorOr<PathSegmentResponse>> Handle(CombinePathCommand request, CancellationToken cancellationToken) public ValueTask<ErrorOr<PathSegmentResponse>> Handle(CombinePathCommand request, CancellationToken cancellationToken)
{ {
ErrorOr<string> result = _pathService.CombinePath(request.OriginalPath, request.NewPath); var result = _pathService.CombinePath(request.OriginalPath, request.NewPath);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(new PathSegmentResponse(result.Value)), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(new PathSegmentResponse(result.Value)), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands; namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="CombinePathCommand"/>. /// Validates the needed validation rules for <see cref="CombinePathCommand"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands; namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
/// <summary> /// <summary>
/// Command for splitting a file system path. /// Command for splitting a file system path.
@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands; namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
/// <summary> /// <summary>
/// Handler for the command to split a file system path. /// Handler for the command to split a file system path.
@@ -43,7 +43,7 @@ public class SplitPathCommandHandler : IRequestHandler<SplitPathCommand, ErrorOr
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(SplitPathCommand request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(SplitPathCommand request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<PathSegment>> result = _pathService.ParsePath(request.Path); var result = _pathService.ParsePath(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<PathSegmentResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<PathSegmentResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands; namespace Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="SplitPathCommand"/>. /// Validates the needed validation rules for <see cref="SplitPathCommand"/>.
@@ -3,6 +3,8 @@ using Lumina.Contracts.Responses.FileManagement;
using Mediator; using Mediator;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
/// <summary> /// <summary>
/// Query for retrieving the existence of a file system path. /// Query for retrieving the existence of a file system path.
/// </summary> /// </summary>
@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
/// <summary> /// <summary>
/// Handler for the query to check the existence a file system path. /// Handler for the query to check the existence a file system path.
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="CheckPathExistsQuery"/>. /// Validates the needed validation rules for <see cref="CheckPathExistsQuery"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
/// <summary> /// <summary>
/// Query for retrieving the parent of a file system path. /// Query for retrieving the parent of a file system path.
@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
/// <summary> /// <summary>
/// Handler for the query to get the parent of a file system path. /// Handler for the query to get the parent of a file system path.
@@ -43,7 +43,7 @@ public class GetPathParentQueryHandler : IRequestHandler<GetPathParentQuery, Err
/// </returns> /// </returns>
public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(GetPathParentQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>> Handle(GetPathParentQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<IEnumerable<PathSegment>> result = _pathService.GoUpOneLevel(request.Path); var result = _pathService.GoUpOneLevel(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<PathSegmentResponse>>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<PathSegmentResponse>>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetPathParentQuery"/>. /// Validates the needed validation rules for <see cref="GetPathParentQuery"/>.
@@ -4,7 +4,7 @@ using Lumina.Contracts.Responses.FileManagement;
using Mediator; using Mediator;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
/// <summary> /// <summary>
/// Query for retrieving the root of a path. /// Query for retrieving the root of a path.
@@ -9,7 +9,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
/// <summary> /// <summary>
/// Handler for the query to get the root of a file system path. /// Handler for the query to get the root of a file system path.
@@ -40,7 +40,7 @@ public class GetPathRootQueryHandler : IRequestHandler<GetPathRootQuery, ErrorOr
/// <returns>The root of the specified path.</returns> /// <returns>The root of the specified path.</returns>
public ValueTask<ErrorOr<PathSegmentResponse>> Handle(GetPathRootQuery request, CancellationToken cancellationToken) public ValueTask<ErrorOr<PathSegmentResponse>> Handle(GetPathRootQuery request, CancellationToken cancellationToken)
{ {
ErrorOr<PathSegment> result = _pathService.GetPathRoot(request.Path); var result = _pathService.GetPathRoot(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<PathSegmentResponse>()), errors => errors)); return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<PathSegmentResponse>()), errors => errors));
} }
#endregion #endregion
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="GetPathRootQuery"/>. /// Validates the needed validation rules for <see cref="GetPathRootQuery"/>.
@@ -3,7 +3,7 @@ using Lumina.Contracts.Responses.FileManagement;
using Mediator; using Mediator;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
/// <summary> /// <summary>
/// Query for retrieving the file system path separator. /// Query for retrieving the file system path separator.
@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
/// <summary> /// <summary>
/// Handler for the query to get the path separator character of a file system path. /// Handler for the query to get the path separator character of a file system path.
@@ -3,7 +3,7 @@ using Lumina.Contracts.Responses.FileManagement;
using Mediator; using Mediator;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
/// <summary> /// <summary>
/// Query for validating a path. /// Query for validating a path.
@@ -6,7 +6,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
/// <summary> /// <summary>
/// Handler for the query to validate a file system path. /// Handler for the query to validate a file system path.
@@ -3,7 +3,7 @@ using FluentValidation;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries; namespace Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="ValidatePathQuery"/>. /// Validates the needed validation rules for <see cref="ValidatePathQuery"/>.
@@ -9,7 +9,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
/// <summary> /// <summary>
/// Command for adding a book. /// Command for adding a book.
@@ -19,7 +19,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
/// <summary> /// <summary>
/// Handler for the command to add a book. /// Handler for the command to add a book.
@@ -77,25 +77,25 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
if (errors.Count != 0) // if there are errors, return them if (errors.Count != 0) // if there are errors, return them
return errors; return errors;
List<BookRating> domainRatings = domainRatingsResult.Select(rating => rating.Value).ToList(); var domainRatings = domainRatingsResult.Select(rating => rating.Value).ToList();
var domainGenresResult = request.Metadata.Genres!.ConvertAll(genre => Genre.Create(genre.Name!)); var domainGenresResult = request.Metadata.Genres!.ConvertAll(genre => Genre.Create(genre.Name!));
errors = domainGenresResult.Where(genreResult => genreResult.IsError).SelectMany(genreResult => genreResult.Errors).ToList(); errors = domainGenresResult.Where(genreResult => genreResult.IsError).SelectMany(genreResult => genreResult.Errors).ToList();
if (errors.Count != 0) if (errors.Count != 0)
return errors; return errors;
List<Genre> domainGenres = domainGenresResult.Select(genre => genre.Value).ToList(); var domainGenres = domainGenresResult.Select(genre => genre.Value).ToList();
var domainTagsResult = request.Metadata.Tags!.ConvertAll(tag => Tag.Create(tag.Name!)); var domainTagsResult = request.Metadata.Tags!.ConvertAll(tag => Tag.Create(tag.Name!));
errors = domainTagsResult.Where(tagResult => tagResult.IsError).SelectMany(tagResult => tagResult.Errors).ToList(); errors = domainTagsResult.Where(tagResult => tagResult.IsError).SelectMany(tagResult => tagResult.Errors).ToList();
if (errors.Count != 0) if (errors.Count != 0)
return errors; return errors;
List<Tag> domainTags = domainTagsResult.Select(tag => tag.Value).ToList(); var domainTags = domainTagsResult.Select(tag => tag.Value).ToList();
var domainIsbnsResult = request.ISBNs.ConvertAll(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!)); var domainIsbnsResult = request.ISBNs.ConvertAll(isbn => Isbn.Create(isbn.Value!, (IsbnFormat)(int)isbn.Format!));
errors = domainIsbnsResult.Where(isbnResult => isbnResult.IsError).SelectMany(isbnResult => isbnResult.Errors).ToList(); errors = domainIsbnsResult.Where(isbnResult => isbnResult.IsError).SelectMany(isbnResult => isbnResult.Errors).ToList();
if (errors.Count != 0) if (errors.Count != 0)
return errors; return errors;
List<Isbn> domainIsbns = domainIsbnsResult.Select(isbn => isbn.Value).ToList(); var domainIsbns = domainIsbnsResult.Select(isbn => isbn.Value).ToList();
var releaseInfoResult = ReleaseInfo.Create( var releaseInfoResult = ReleaseInfo.Create(
Optional<DateOnly>.FromNullable(request.Metadata.ReleaseInfo!.OriginalReleaseDate), Optional<DateOnly>.FromNullable(request.Metadata.ReleaseInfo!.OriginalReleaseDate),
@@ -107,7 +107,7 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
); );
if (releaseInfoResult.IsError) if (releaseInfoResult.IsError)
return releaseInfoResult.Errors; return releaseInfoResult.Errors;
ReleaseInfo releaseInfo = releaseInfoResult.Value; var releaseInfo = releaseInfoResult.Value;
LanguageInfo? languageInfo = null; LanguageInfo? languageInfo = null;
if (request.Metadata.Language is not null) if (request.Metadata.Language is not null)
{ {
@@ -4,7 +4,7 @@ using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
#endregion #endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
/// <summary> /// <summary>
/// Validates the needed validation rules for <see cref="AddBookCommand"/>. /// Validates the needed validation rules for <see cref="AddBookCommand"/>.
@@ -5,7 +5,7 @@ using Mediator;
using System.Collections.Generic; using System.Collections.Generic;
#endregion #endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries; namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
/// <summary> /// <summary>
/// Query for getting all books. /// Query for getting all books.
@@ -10,7 +10,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries; namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
/// <summary> /// <summary>
/// Handler for the query to get all books. /// Handler for the query to get all books.
@@ -1,5 +1,5 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary;
using Mapster; using Mapster;
#endregion #endregion
@@ -1,6 +1,8 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using ErrorOr; using ErrorOr;
using Lumina.Application.Core.FileManagement.Directories.Queries; using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
using Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectoryTree;
using Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
using Lumina.Contracts.Responses.FileManagement; using Lumina.Contracts.Responses.FileManagement;
using Lumina.Presentation.Api.Common.ModelBinders; using Lumina.Presentation.Api.Common.ModelBinders;
using Lumina.Presentation.Api.Core.Controllers.Common; using Lumina.Presentation.Api.Core.Controllers.Common;
@@ -1,6 +1,6 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using ErrorOr; using ErrorOr;
using Lumina.Application.Core.FileManagement.Drives.Queries; using Lumina.Application.Core.FileManagement.Drives.Queries.GetDrives;
using Lumina.Contracts.Responses.FileManagement; using Lumina.Contracts.Responses.FileManagement;
using Lumina.Presentation.Api.Core.Controllers.Common; using Lumina.Presentation.Api.Core.Controllers.Common;
using Mediator; using Mediator;
@@ -1,5 +1,5 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileManagement.FileSystem.Queries; using Lumina.Application.Core.FileManagement.FileSystem.Queries.GetFileSysem;
using Lumina.Presentation.Api.Core.Controllers.Common; using Lumina.Presentation.Api.Core.Controllers.Common;
using Mediator; using Mediator;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -1,6 +1,7 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using ErrorOr; using ErrorOr;
using Lumina.Application.Core.FileManagement.Files.Queries; using Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
using Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
using Lumina.Contracts.Responses.FileManagement; using Lumina.Contracts.Responses.FileManagement;
using Lumina.Presentation.Api.Common.ModelBinders; using Lumina.Presentation.Api.Common.ModelBinders;
using Lumina.Presentation.Api.Core.Controllers.Common; using Lumina.Presentation.Api.Core.Controllers.Common;
@@ -1,11 +1,15 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using ErrorOr; using ErrorOr;
using Lumina.Application.Core.FileManagement.Paths.Commands; using Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
using Lumina.Application.Core.FileManagement.Paths.Queries; using Lumina.Application.Core.FileManagement.Paths.Commands.SplitPath;
using Lumina.Application.Core.FileManagement.Paths.Queries.CheckPathExists;
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathParent;
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathRoot;
using Lumina.Application.Core.FileManagement.Paths.Queries.GetPathSeparator;
using Lumina.Application.Core.FileManagement.Paths.Queries.ValidatePath;
using Lumina.Contracts.Responses.FileManagement; using Lumina.Contracts.Responses.FileManagement;
using Lumina.Presentation.Api.Common.ModelBinders; using Lumina.Presentation.Api.Common.ModelBinders;
using Lumina.Presentation.Api.Core.Controllers.Common; using Lumina.Presentation.Api.Core.Controllers.Common;
using MapsterMapper;
using Mediator; using Mediator;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
@@ -1,6 +1,6 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Api.Core.Controllers.Common; using Lumina.Presentation.Api.Core.Controllers.Common;
using MapsterMapper; using MapsterMapper;
@@ -5,7 +5,7 @@ using ErrorOr;
using FluentAssertions; using FluentAssertions;
using Lumina.Application.Common.DataAccess.Repositories.Books; using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Common.Setup; using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures; using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures;
using Lumina.Contracts.Enums.BookLibrary; using Lumina.Contracts.Enums.BookLibrary;
@@ -1,7 +1,7 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using Bogus; using Bogus;
using FluentValidation.TestHelper; using FluentValidation.TestHelper;
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures; using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures;
using Lumina.Contracts.Enums.BookLibrary; using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Errors;
@@ -1,7 +1,7 @@
#region ========================================================================= USING ===================================================================================== #region ========================================================================= USING =====================================================================================
using AutoFixture; using AutoFixture;
using Bogus; using Bogus;
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Common.Setup; using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Contracts.Enums.BookLibrary; using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Contracts.Models.Common; using Lumina.Contracts.Models.Common;