Implements directory browser dialog, part 1: file system treeview

This commit is contained in:
BinaryAlley committed 2024-09-15 13:07:53 +03:00
1 parent 4a53348013
commit 4e4ecbbfca
318 files changed
+6012 -1184

No files matched your search

@@ -1,13 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Mediator;
using ErrorOr;
using FluentValidation;
using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.Behaviors;
/// <summary>
/// Behavior pipeline for the register command
/// Represents a validation behavior in the MediatR pipeline for handling requests and responses.
/// </summary>
/// <typeparam name="TRequest">The type representing a request. It should implement <see cref="IRequest{TResponse}"/>.</typeparam>
/// <typeparam name="TResponse">The type representing a response. It should implement <see cref="IErrorOr"/> interface.</typeparam>
@@ -15,7 +17,7 @@ public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TReques
where TResponse : IErrorOr
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IValidator<TRequest>? validator;
private readonly IValidator<TRequest>? _validator;
#endregion
#region ====================================================================== CTOR =====================================================================================
@@ -25,7 +27,7 @@ public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TReques
/// <param name="validator">The validator used in this behavior pipeline for the Mediator commands and queries.</param>
public ValidationBehavior(IValidator<TRequest>? validator = null)
{
this.validator = validator;
_validator = validator;
}
#endregion
@@ -39,13 +41,13 @@ public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TReques
public async ValueTask<TResponse> Handle(TRequest request, CancellationToken cancellationToken, MessageHandlerDelegate<TRequest, TResponse> next)
{
// if there is no validator, just invoke the handler
if (validator is null)
return await next(request, cancellationToken);
if (_validator is null)
return await next(request, cancellationToken).ConfigureAwait(false);
// before the handler of the command is executed
var validationResult = await validator.ValidateAsync(request, cancellationToken);
var validationResult = await _validator.ValidateAsync(request, cancellationToken).ConfigureAwait(false);
// if there are no validation errors, invoke the command handler
if (validationResult.IsValid)
return await next(request, cancellationToken);
return await next(request, cancellationToken).ConfigureAwait(false);
// after the command handler is executed
var errors = validationResult.Errors.ConvertAll(validationFailure => Error.Validation(description: validationFailure.ErrorMessage));
// the compiler doesn't know there is an implicit converter from a list of errors to the ErrorOr object, and unfortunately, there is no way around this but to use some magic
@@ -1,40 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Converters;
/// <summary>
/// Converts an <see cref="Optional{T}"/> to and from JSON.
/// Converts an <see cref="Optional{TValue}"/> to and from JSON.
/// </summary>
/// <typeparam name="T">The type of the value represented by the <see cref="Optional{T}"/> structure.</typeparam>
public class OptionalJsonConverter<T> : JsonConverter<Optional<T>>
/// <typeparam name="TValue">The type of the value represented by the <see cref="Optional{TValue}"/> structure.</typeparam>
public class OptionalJsonConverter<TValue> : JsonConverter<Optional<TValue>>
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Reads and converts the JSON to an instance of <see cref="Optional{T}"/>.
/// Reads and converts the JSON to an instance of <see cref="Optional{TValue}"/>.
/// </summary>
/// <param name="reader">The <see cref="Utf8JsonReader"/> to read from.</param>
/// <param name="typeToConvert">The type to convert.</param>
/// <param name="options">An object that specifies serialization options to use.</param>
/// <returns>The converted <see cref="Optional{T}"/> value.</returns>
public override Optional<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
/// <returns>The converted <see cref="Optional{TValue}"/> value.</returns>
public override Optional<TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
return Optional<T>.None();
var value = JsonSerializer.Deserialize<T>(ref reader, options);
return Optional<T>.Some(value!);
return Optional<TValue>.None();
var value = JsonSerializer.Deserialize<TValue>(ref reader, options);
return Optional<TValue>.Some(value!);
}
/// <summary>
/// Writes an <see cref="Optional{T}"/> value as JSON.
/// Writes an <see cref="Optional{TValue}"/> value as JSON.
/// </summary>
/// <param name="writer">The <see cref="Utf8JsonWriter"/> to write to.</param>
/// <param name="value">The value to convert to JSON.</param>
/// <param name="options">An object that specifies serialization options to use.</param>
public override void Write(Utf8JsonWriter writer, Optional<T> value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, Optional<TValue> value, JsonSerializerOptions options)
{
if (value.HasValue)
JsonSerializer.Serialize(writer, value.Value, options);
@@ -1,7 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Application.Common.Converters;
@@ -16,7 +17,7 @@ public class OptionalJsonConverterFactory : JsonConverterFactory
/// Determines whether the converter can convert the specified type.
/// </summary>
/// <param name="typeToConvert">The type to check for convertibility.</param>
/// <returns><see langword="true"/> if the type is <see cref="Optional{T}"/>, <see langword="false"/> otherwise.</returns>
/// <returns><see langword="true"/> if the type is <see cref="Optional{TValue}"/>, <see langword="false"/> otherwise.</returns>
public override bool CanConvert(Type typeToConvert)
{
if (!typeToConvert.IsGenericType)
@@ -29,7 +30,7 @@ public class OptionalJsonConverterFactory : JsonConverterFactory
/// </summary>
/// <param name="typeToConvert">The type for which to create a converter.</param>
/// <param name="options">The serializer options to use.</param>
/// <returns>A converter for <see cref="Optional{T}"/>.</returns>
/// <returns>A converter for <see cref="Optional{TValue}"/>.</returns>
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
Type valueType = typeToConvert.GetGenericArguments()[0];
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Application.Common.Models.Books;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
@@ -9,8 +9,8 @@ namespace Lumina.Application.Common.DataAccess.Repositories.Books;
/// <summary>
/// Interface for the repository for books.
/// </summary>
public interface IBookRepository : IRepository<BookDto>,
IInsertRepositoryAction<BookDto>,
IGetAllRepositoryAction<BookDto>
public interface IBookRepository : IRepository<BookModel>,
IInsertRepositoryAction<BookModel>,
IGetAllRepositoryAction<BookModel>
{
}
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
@@ -13,7 +14,7 @@ public interface IDeleteAllRepositoryAction
/// <summary>
/// Deletes all entities from the storage medium.
/// </summary>
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Deleted>> DeleteAllAsync();
#endregion
}
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
@@ -16,7 +18,7 @@ public interface IDeleteByIdRepositoryAction<TId> where TId : notnull
/// </summary>
/// <param name="id">The id of the element to be deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Deleted>> DeleteByIdAsync(TId id, CancellationToken cancellationToken);
#endregion
}
@@ -1,6 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
@@ -16,7 +19,7 @@ public interface IGetAllRepositoryAction<TModel> where TModel : IStorageEntity
/// Gets all data of type <typeparamref name="TModel"/> from the storage medium.
/// </summary>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> containing either a collection of <typeparamref name="TModel"/>, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <typeparamref name="TModel"/>, or an error.</returns>
Task<ErrorOr<IEnumerable<TModel>>> GetAllAsync(CancellationToken cancellationToken);
#endregion
}
@@ -1,6 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
@@ -19,7 +21,7 @@ public interface IGetByIdRepositoryAction<TModel, TId> where TModel : IStorageEn
/// </summary>
/// <param name="id">The id of the element to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> containing either a <typeparamref name="TModel"/> identified by <paramref name="id"/>, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <typeparamref name="TModel"/> identified by <paramref name="id"/>, or an error.</returns>
Task<ErrorOr<TModel?>> GetByIdAsync(TId id, CancellationToken cancellationToken);
#endregion
}
@@ -1,6 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
@@ -17,7 +19,7 @@ public interface IInsertRepositoryAction<TModel> where TModel : IStorageEntity
/// </summary>
/// <param name="data">The element to be saved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Created>> InsertAsync(TModel data, CancellationToken cancellationToken);
#endregion
}
@@ -1,6 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
@@ -17,7 +19,7 @@ public interface IUpdateRepositoryAction<TModel> where TModel : IStorageEntity
/// </summary>
/// <param name="data">The element that will be updated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successfull operation, or an error.</returns>
Task<ErrorOr<Updated>> UpdateAsync(TModel data, CancellationToken cancellationToken);
#endregion
}
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Common;
using Lumina.Contracts.Models.Common;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Base;
@@ -1,4 +1,9 @@
namespace Lumina.Application.Common.DataAccess.UoW;
#region ========================================================================= USING =====================================================================================
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.UoW;
/// <summary>
/// Interaction boundary with the Data Access Layer.
@@ -0,0 +1,31 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Mapster;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system directories between the domain object and the presentation object.
/// </summary>
public class DirectoryMappingConfig : IRegister
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Directory, FileSystemTreeNodeResponse>()
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.ItemType, src => src.Type)
.Map(dest => dest.IsExpanded, () => false)
.Map(dest => dest.ChildrenLoaded, () => false)
.Map(dest => dest.Children, src => src.Items)
.MapToConstructor(true);
}
#endregion
}
@@ -0,0 +1,30 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Mapster;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system files between the domain object and the presentation object.
/// </summary>
public class FileMappingConfig : IRegister
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<File, FileSystemTreeNodeResponse>()
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.ItemType, src => src.Type)
.Map(dest => dest.IsExpanded, () => false)
.Map(dest => dest.ChildrenLoaded, () => false)
.MapToConstructor(true);
}
#endregion
}
@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
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 Mapster;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system trees between the domain object and the presentation object.
/// </summary>
public class FileSystemTreeMappingConfig : IRegister
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<WindowsRootItem, FileSystemTreeNodeResponse>()
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.ItemType, src => FileSystemItemType.Root)
.Map(dest => dest.IsExpanded, () => false);
config.NewConfig<FileSystemTreeNodeResponse, WindowsRootItem>()
.MapWith(src => WindowsRootItem.Create(
src.Path,
src.Name,
FileSystemItemStatus.Accessible)
.Value);
config.NewConfig<UnixRootItem, FileSystemTreeNodeResponse>()
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.ItemType, src => FileSystemItemType.Root)
.Map(dest => dest.IsExpanded, () => false);
config.NewConfig<FileSystemTreeNodeResponse, UnixRootItem>()
.MapWith(src => UnixRootItem.Create(
FileSystemItemStatus.Accessible)
.Value);
config.NewConfig<FileSystemItem, FileSystemTreeNodeResponse>()
.MapWith(src => new FileSystemTreeNodeResponse
{
Path = src.Id.Path,
Name = src.Name,
ItemType = src.Type,
IsExpanded = false,
ChildrenLoaded = false,
Children = new List<FileSystemTreeNodeResponse>()
});
}
#endregion
}
@@ -0,0 +1,26 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using Mapster;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system paths between the domain object and the presentation object.
/// </summary>
public class PathSegmentMappingConfig : IRegister
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<PathSegment, PathSegmentResponse>()
.Map(dest => dest.Path, src => src.Name)
.MapToConstructor(true);
}
#endregion
}
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Books;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
@@ -8,6 +8,9 @@ using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary;
@@ -24,7 +27,7 @@ public class BookMappingConfig : IRegister
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Book, BookDto>()
config.NewConfig<Book, BookModel>()
.Map(dest => dest.Id, src => src.Id.Value)
.Map(dest => dest.Title, src => src.Metadata.Title)
.Map(dest => dest.OriginalTitle, src => src.Metadata.OriginalTitle.HasValue ? src.Metadata.OriginalTitle.Value : default)
@@ -62,7 +65,7 @@ public class BookMappingConfig : IRegister
.Map(dest => dest.Created, src => src.Created)
.Map(dest => dest.Updated, src => src.Updated.HasValue ? src.Updated : null);
config.NewConfig<BookRating, BookRatingDto>()
config.NewConfig<BookRating, BookRatingModel>()
.Map(dest => dest.Value, src => src.Value)
.Map(dest => dest.MaxValue, src => src.MaxValue)
.Map(dest => dest.VoteCount, src => src.VoteCount.HasValue ? src.VoteCount.Value : default)
@@ -71,8 +74,8 @@ public class BookMappingConfig : IRegister
config.NewConfig<Optional<BookRatingSource>, BookRatingSource?>()
.MapWith(src => src.HasValue ? src.Value : default);
// from BookDto to Book
config.NewConfig<BookDto, Book>()
// from BookModel to Book
config.NewConfig<BookModel, Book>()
.MapWith(src => Book.Create(
BookId.Create(src.Id),
WrittenContentMetadata.Create(
@@ -1,201 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Common;
#endregion
namespace Lumina.Application.Common.Models.Books;
/// <summary>
/// Represents a book.
/// </summary>
public class BookDto : IStorageEntity
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Id { get; init; }
/// <summary>
/// Gets the title of the media item.
/// </summary>
public string Title { get; init; } = null!;
/// <summary>
/// Gets the original title of the media item.
/// </summary>
public string? OriginalTitle { get; init; }
/// <summary>
/// Gets the optional description of the media item.
/// </summary>
public string? Description { get; init; }
/// <summary>
/// Gets the optional original release date of the media item.
/// </summary>
public DateOnly? OriginalReleaseDate { get; init; }
/// <summary>
/// Gets the optional original release year of the media item.
/// This is useful when only the year of original release is known.
/// </summary>
public int? OriginalReleaseYear { get; init; }
/// <summary>
/// Gets the optional re-release or reissue date of the media item.
/// </summary>
public DateOnly? ReReleaseDate { get; init; }
/// <summary>
/// Gets the optional re-release or reissue year of the media item.
/// </summary>
public int? ReReleaseYear { get; init; }
/// <summary>
/// Gets the optional country or region of release.
/// </summary>
public string? ReleaseCountry { get; init; }
/// <summary>
/// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0")
/// </summary>
public string? ReleaseVersion { get; init; }
/// <summary>
/// Gets the ISO 639-1 two-letter language code.
/// </summary>
public string? LanguageCode { get; init; }
/// <summary>
/// Gets the full name of the language in English.
/// </summary>
public string? LanguageName { get; init; }
/// <summary>
/// Gets an optional native name of the language.
/// </summary>
public string? LanguageNativeName { get; init; }
/// <summary>
/// Gets the optional ISO 639-1 two-letter original language code.
/// </summary>
public string? OriginalLanguageCode { get; init; }
/// <summary>
/// Gets the optional full name of the original language in English.
/// </summary>
public string? OriginalLanguageName { get; init; }
/// <summary>
/// Gets an optional native name of the original language.
/// </summary>
public string? OriginalLanguageNativeName { get; init; }
/// <summary>
/// Gets the list of tags associated with the media item.
/// </summary>
public HashSet<TagDto> Tags { get; set; } = [];
/// <summary>
/// Gets the list of genres associated with the media item.
/// </summary>
public HashSet<GenreDto> Genres { get; set; } = [];
/// <summary>
/// Gets the publisher of the written content.
/// </summary>
public string? Publisher { get; init; }
/// <summary>
/// Gets the number of pages in the written content.
/// </summary>
public int? PageCount { get; init; }
/// <summary>
/// Gets the format of the book (e.g., Hardcover, Paperback), if applicable.
/// </summary>
public string Format { get; init; } = null!;
/// <summary>
/// Gets the edition of the book, if applicable.
/// </summary>
public string? Edition { get; init; }
/// <summary>
/// Gets the volume or book number in the series, if applicable.
/// </summary>
public int? VolumeNumber { get; init; }
/// <summary>
/// Gets the series id, if the book is part of a series.
/// </summary>
//public Guid? BookSeriesId { get; init; } = null;
/// <summary>
/// Gets the ASIN (Amazon Standard Identification Number) of the book.
/// </summary>
public string? ASIN { get; init; } = null!;
/// <summary>
/// Gets the Goodreads ID of the book.
/// </summary>
public string? GoodreadsId { get; init; } = null!;
/// <summary>
/// Gets the Library of Congress Control Number (LCCN) of the book.
/// </summary>
public string? LCCN { get; init; } = null!;
/// <summary>
/// Gets the OCLC Number (WorldCat identifier) of the book.
/// </summary>
public string? OCLCNumber { get; init; } = null!;
/// <summary>
/// Gets the Open Library ID of the book.
/// </summary>
public string? OpenLibraryId { get; init; } = null!;
/// <summary>
/// Gets the LibraryThing ID of the book.
/// </summary>
public string? LibraryThingId { get; init; } = null!;
/// <summary>
/// Gets the Google Books ID of the book.
/// </summary>
public string? GoogleBooksId { get; init; } = null!;
/// <summary>
/// Gets the Barnes & Noble ID of the book.
/// </summary>
public string? BarnesAndNobleId { get; init; } = null!;
/// <summary>
/// Gets the Apple Books ID of the book.
/// </summary>
public string? AppleBooksId { get; init; } = null!;
/// <summary>
/// Gets the list of ISBN (International Standard Book Number) of the book.
/// </summary>
public List<IsbnDto> ISBNs { get; set; } = [];
/// <summary>
/// Gets the list of media contributors (actors, directors, etc) starring in this book.
/// </summary>
//public List<ContributorIdDto> ContributorIds { get; init; } = [];
/// <summary>
/// Gets the list of ratings for this book.
/// </summary>
public List<BookRatingDto> Ratings { get; init; } = [];
/// <summary>
/// Gets the time and date when the entity was added.
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// Gets the optional time and date when the entity was updated.
/// </summary>
public DateTime? Updated { get; set; }
#endregion
}
@@ -1,16 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Common;
using Lumina.Domain.Common.Enums;
#endregion
namespace Lumina.Application.Common.Models.Books;
/// <summary>
/// Represents a book rating.
/// </summary>
public record BookRatingDto(
decimal? Value,
decimal? MaxValue,
BookRatingSource? Source,
int? VoteCount
) : RatingDto(Value, MaxValue, VoteCount);
@@ -1,8 +0,0 @@
namespace Lumina.Application.Common.Models.Books;
/// <summary>
/// Represents a request to get book series information.
/// </summary>
public record BookSeriesDto(
string? Title
);
@@ -1,13 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums;
#endregion
namespace Lumina.Application.Common.Models.Books;
/// <summary>
/// Represents a request to get ISBN information.
/// </summary>
public record IsbnDto(
string? Value,
IsbnFormat? Format
);
@@ -1,21 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Models.Common;
#endregion
namespace Lumina.Application.Common.Models.Books;
/// <summary>
/// Represents written content metadata.
/// </summary>
public record WrittenContentMetadataDto(
string? Title,
string? OriginalTitle,
string? Description,
ReleaseInfoDto? ReleaseInfo,
List<GenreDto>? Genres,
List<TagDto>? Tags,
LanguageInfoDto? Language,
LanguageInfoDto? OriginalLanguage,
string? Publisher,
int? PageCount
);
@@ -1,8 +0,0 @@
namespace Lumina.Application.Common.Models.Common;
/// <summary>
/// Represents a request to get genre information.
/// </summary>
public record GenreDto(
string? Name
);
@@ -1,24 +0,0 @@
namespace Lumina.Application.Common.Models.Common;
/// <summary>
/// Interface for storage DTOs, enforces Id.
/// </summary>
public interface IStorageEntity
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets or sets the identifier of the entity.
/// </summary>
Guid Id { get; init; }
/// <summary>
/// The time and date when the entity was added.
/// </summary>
DateTime Created { get; set; }
/// <summary>
/// The time and date when the entity was updated.
/// </summary>
DateTime? Updated { get; set; }
#endregion
}
@@ -1,10 +0,0 @@
namespace Lumina.Application.Common.Models.Common;
/// <summary>
/// Represents a request to get language information.
/// </summary>
public record LanguageInfoDto(
string? LanguageCode,
string? LanguageName,
string? NativeName
);
@@ -1,10 +0,0 @@
namespace Lumina.Application.Common.Models.Common;
/// <summary>
/// Represents a rating.
/// </summary>
public abstract record RatingDto(
decimal? Value,
decimal? MaxValue,
int? VoteCount
);
@@ -1,13 +0,0 @@
namespace Lumina.Application.Common.Models.Common;
/// <summary>
/// Represents a request to get release information.
/// </summary>
public record ReleaseInfoDto(
DateOnly? OriginalReleaseDate,
int? OriginalReleaseYear,
DateOnly? ReReleaseDate,
int? ReReleaseYear,
string? ReleaseCountry,
string? ReleaseVersion
);
@@ -1,8 +0,0 @@
namespace Lumina.Application.Common.Models.Common;
/// <summary>
/// Represents a request to get tag information.
/// </summary>
public record TagDto(
string? Name
);
@@ -1,9 +0,0 @@
namespace Lumina.Application.Common.Models.Contributors;
/// <summary>
/// Represents a media contributor.
/// </summary>
public record MediaContributorDto(
MediaContributorNameDto? Name,
MediaContributorRoleDto? Role
);
@@ -1,9 +0,0 @@
namespace Lumina.Application.Common.Models.Contributors;
/// <summary>
/// Represents a media contributor name.
/// </summary>
public record MediaContributorNameDto(
string? DisplayName,
string? LegalName
);
@@ -1,9 +0,0 @@
namespace Lumina.Application.Common.Models.Contributors;
/// <summary>
/// Represents a media contributor role.
/// </summary>
public record MediaContributorRoleDto(
string? Name,
string? Category
);
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries;
/// <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>
public record GetDirectoriesQuery(string Path) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
@@ -0,0 +1,51 @@
#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 Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries;
/// <summary>
/// Handler for the query to get all directories.
/// </summary>
public class GetDirectoriesQueryHandler : IRequestHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IDirectoryService _directoryService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetDirectoriesQueryHandler"/> class.
/// </summary>
/// <param name="directoryService">Injected service for handling directories.</param>
public GetDirectoriesQueryHandler(IDirectoryService directoryService)
{
_directoryService = directoryService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the list of directories at the specified path.
/// </summary>
/// <param name="request">The query containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDirectoriesQuery request, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<Directory>> result = _directoryService.GetSubdirectories(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors));
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries;
/// <summary>
/// Validates the needed validation rules for <see cref="GetDirectoriesQuery"/>.
/// </summary>
public class GetDirectoriesQueryValidator : AbstractValidator<GetDirectoriesQuery>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetDirectoriesQueryValidator"/> class.
/// </summary>
public GetDirectoriesQueryValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries;
/// <summary>
/// Query for retrieving the tree of directories of a path.
/// </summary>
/// <param name="Path">The path for which to retrieve the tree of directories.</param>
public record GetDirectoryTreeQuery(string Path) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
@@ -0,0 +1,179 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
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 Mediator;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries;
/// <summary>
/// Handler for the query to get a directory tree.
/// </summary>
public class GetDirectoryTreeQueryHandler : IRequestHandler<GetDirectoryTreeQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IDirectoryService _directoryService;
private readonly IFileService _fileService;
private readonly IPathService _pathService;
private readonly IDriveService _driveService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetDirectoryTreeQueryHandler"/> class.
/// </summary>
/// <param name="driveService">Injected service for handling file system drives.</param>
/// <param name="directoryService">Injected service for handling directories.</param>
/// <param name="fileService">Injected service for handling files.</param>
/// <param name="pathService">Injected service for handling file system paths.</param>
public GetDirectoryTreeQueryHandler(IDriveService driveService, IDirectoryService directoryService, IFileService fileService, IPathService pathService)
{
_directoryService = directoryService;
_fileService = fileService;
_pathService = pathService;
_driveService = driveService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the tree of expanded directories leading up to the requested path, with the additional list of drives, and children of the last child directory.
/// </summary>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
public async ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDirectoryTreeQuery request, CancellationToken cancellationToken)
{
List<FileSystemTreeNodeResponse> result = [];
// retrieve the list of drives
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> getDrivesResult = GetDrives();
if (getDrivesResult.IsError)
return getDrivesResult.Errors;
result.AddRange(getDrivesResult.Value);
ErrorOr<IEnumerable<PathSegment>> pathPartsResults = _pathService.ParsePath(request.Path);
if (pathPartsResults.IsError)
return pathPartsResults.Errors;
List<PathSegment> pathParts = pathPartsResults.Value.ToList();
string currentPath = pathParts[0].Name;
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out FileSystemTreeNodeResponse currentNode);
if (buildDirectoryTreeResult.IsError)
return buildDirectoryTreeResult.Errors;
// add subdirectories of the last directory node
ErrorOr<Success> loadChildrenResult = LoadChildren(currentNode);
if (loadChildrenResult.IsError)
return loadChildrenResult.Errors;
return await ValueTask.FromResult(result);
}
/// <summary>
/// Gets the root drives (on Windows), or an empty list on Unix-based systems.
/// </summary>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing a list of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
private ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> GetDrives()
{
ErrorOr<IEnumerable<FileSystemItem>> driveResult = _driveService.GetDrives();
if (driveResult.IsError)
return driveResult.Errors;
return ErrorOrFactory.From(driveResult.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>());
}
/// <summary>
/// Builds the tree of directories based on the parsed path parts.
/// </summary>
/// <param name="drives">The list of available drives.</param>
/// <param name="pathParts">The list of parsed path segments (directories).</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing a list of <see cref="FileSystemTreeNodeResponse"/> representing the directory tree, or an error message.
/// </returns>
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
FileSystemTreeNodeResponse drive = drives.First(d => d.Name.Contains(pathParts[0].Name));
drive.IsExpanded = true;
currentNode = drive;
string currentPath = pathParts[0].Name;
// traverse the remaining path parts to build the tree structure
for (int i = 1; i < pathParts.Count; i++)
{
ErrorOr<string> combinedPathResult = _pathService.CombinePath(currentPath, pathParts[i].Name);
if (combinedPathResult.IsError)
return combinedPathResult.Errors;
currentPath = combinedPathResult.Value;
// create a new node for the directory and add it as a child of the current node
FileSystemTreeNodeResponse newNode = new FileSystemTreeNodeResponse
{
Path = currentPath,
Name = pathParts[i].Name,
ItemType = FileSystemItemType.Directory,
IsExpanded = true
};
currentNode.Children.Add(newNode);
currentNode = newNode; // move to the new node
}
return new List<FileSystemTreeNodeResponse> { drive };
}
/// <summary>
/// Loads the child directories and files of the specified directory node.
/// </summary>
/// <param name="node">The directory node to load children for.</param>
/// <returns>A result indicating a successful operation, or an error message.</returns>
private ErrorOr<Success> LoadChildren(FileSystemTreeNodeResponse node)
{
// get subdirectories under the current node's path
ErrorOr<IEnumerable<Directory>> subDirectoriesResult = _directoryService.GetSubdirectories(node.Path);
if (subDirectoriesResult.IsError)
return subDirectoriesResult.Errors;
// add each subdirectory as a child node of the current directory
foreach (Directory subDirectory in subDirectoriesResult.Value)
{
FileSystemTreeNodeResponse subDirNode = new FileSystemTreeNodeResponse
{
Name = subDirectory.Name,
Path = subDirectory.Id.Path,
ItemType = FileSystemItemType.Directory,
IsExpanded = false,
ChildrenLoaded = false
};
node.Children.Add(subDirNode);
}
// get files under the current node's path
ErrorOr<IEnumerable<File>> filesResult = _fileService.GetFiles(node.Path);
if (filesResult.IsError)
return filesResult.Errors;
// add each file as a child node of the current directory
foreach (File file in filesResult.Value)
{
FileSystemTreeNodeResponse fileNode = new FileSystemTreeNodeResponse
{
Name = file.Name,
Path = file.Id.Path,
ItemType = FileSystemItemType.File,
IsExpanded = false,
ChildrenLoaded = true
};
node.Children.Add(fileNode);
}
node.ChildrenLoaded = true;
return Result.Success;
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries;
/// <summary>
/// Validates the needed validation rules for <see cref="GetDirectoryTreeQuery"/>.
/// </summary>
public class GetDirectoryTreeQueryValidator : AbstractValidator<GetDirectoryTreeQuery>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetDirectoryTreeQueryValidator"/> class.
/// </summary>
public GetDirectoryTreeQueryValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Drives.Queries;
/// <summary>
/// Query for retrieving the list of drives.
/// </summary>
public record GetDrivesQuery() : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
@@ -0,0 +1,50 @@
#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 Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Drives.Queries;
/// <summary>
/// Handler for the query to get all drives.
/// </summary>
public class GetDrivesQueryHandler : IRequestHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IDriveService _driveService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetDrivesQueryHandler"/> class.
/// </summary>
/// <param name="driveService">Injected service for handling file system drives.</param>
public GetDrivesQueryHandler(IDriveService driveService)
{
_driveService = driveService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the list of file system drives.
/// </summary>
/// <param name="request">The query containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetDrivesQuery request, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<FileSystemItem>> result = _driveService.GetDrives();
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors));
}
#endregion
}
@@ -0,0 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
#endregion
namespace Lumina.Application.Core.FileManagement.FileSystem.Queries;
/// <summary>
/// Query for retrieving the file system type.
/// </summary>
public record GetFileSystemQuery() : IRequest<FileSystemTypeResponse>;
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform;
using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.FileSystem.Queries;
/// <summary>
/// Handler for the query to get the file system type.
/// </summary>
public class GetFileSystemQueryHandler : IRequestHandler<GetFileSystemQuery, FileSystemTypeResponse>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPlatformContext _platformContext;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetFileSystemQueryHandler"/> class.
/// </summary>
/// <param name="platformContextManager">Injected service for managing platform contexts.</param>
public GetFileSystemQueryHandler(IPlatformContextManager platformContextManager)
{
_platformContext = platformContextManager.GetCurrentContext();
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the type of the file system.
/// </summary>
/// <param name="request">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>The type of the file system.</returns>
public ValueTask<FileSystemTypeResponse> Handle(GetFileSystemQuery request, CancellationToken cancellationToken)
{
return ValueTask.FromResult(new FileSystemTypeResponse(_platformContext.Platform));
}
#endregion
}
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries;
/// <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>
public record GetFilesQuery(string Path) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
@@ -0,0 +1,50 @@
#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 Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries;
/// <summary>
/// Handler for the query to get all files.
/// </summary>
public class GetFilesQueryHandler : IRequestHandler<GetFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IFileService _fileService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetFilesQueryHandler"/> class.
/// </summary>
/// <param name="fileService">Injected service for handling files.</param>
public GetFilesQueryHandler(IFileService fileService)
{
_fileService = fileService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the list of files at the specified path.
/// </summary>
/// <param name="request">The query containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="FileSystemTreeNodeResponse"/>, or an error message.
/// </returns>
public ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> Handle(GetFilesQuery request, CancellationToken cancellationToken)
{
ErrorOr<IEnumerable<File>> result = _fileService.GetFiles(request.Path);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt<IEnumerable<FileSystemTreeNodeResponse>>()), errors => errors));
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries;
/// <summary>
/// Validates the needed validation rules for <see cref="GetFilesQuery"/>.
/// </summary>
public class GetFilesQueryValidator : AbstractValidator<GetFilesQuery>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetFilesQueryValidator"/> class.
/// </summary>
public GetFilesQueryValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands;
/// <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>>;
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Mapster;
using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands;
/// <summary>
/// Handler for the command to split a file system path.
/// </summary>
public class CombinePathCommandHandler : IRequestHandler<CombinePathCommand, ErrorOr<PathSegmentResponse>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPathService _pathService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="SplitPathCommandHandler"/> class.
/// </summary>
/// <param name="pathService">Injected service for handling file system paths.</param>
public CombinePathCommandHandler(IPathService pathService)
{
_pathService = pathService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Combines two file system paths.
/// </summary>
/// <param name="request">The command containing the requested paths.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a <see cref="PathSegmentResponse"/>, or an error message.
/// </returns>
public ValueTask<ErrorOr<PathSegmentResponse>> Handle(CombinePathCommand request, CancellationToken cancellationToken)
{
ErrorOr<string> result = _pathService.CombinePath(request.OriginalPath, request.NewPath);
return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(new PathSegmentResponse(result.Value)), errors => errors));
}
#endregion
}
@@ -0,0 +1,23 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands;
/// <summary>
/// Validates the needed validation rules for <see cref="CombinePathCommand"/>.
/// </summary>
public class CombinePathCommandValidator : AbstractValidator<CombinePathCommand>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="CombinePathCommandValidator"/> class.
/// </summary>
public CombinePathCommandValidator()
{
RuleFor(x => x.OriginalPath).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
RuleFor(x => x.NewPath).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands;
/// <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>>>;
@@ -0,0 +1,50 @@
#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 Mapster;
using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands;
/// <summary>
/// Handler for the command to split a file system path.
/// </summary>
public class SplitPathCommandHandler : IRequestHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPathService _pathService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="SplitPathCommandHandler"/> class.
/// </summary>
/// <param name="pathService">Injected service for handling file system paths.</param>
public SplitPathCommandHandler(IPathService pathService)
{
_pathService = pathService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the path components of the specified path.
/// </summary>
/// <param name="request">The command containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="PathSegmentResponse"/>, or an error message.
/// </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(result.Value.Adapt<IEnumerable<PathSegmentResponse>>()), errors => errors));
}
#endregion
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands;
/// <summary>
/// Validates the needed validation rules for <see cref="SplitPathCommand"/>.
/// </summary>
public class SplitPathCommandValidator : AbstractValidator<SplitPathCommand>
{
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="SplitPathCommandValidator"/> class.
/// </summary>
public SplitPathCommandValidator()
{
RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code);
}
#endregion
}
@@ -0,0 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <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>>;
@@ -0,0 +1,47 @@
#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 Mapster;
using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Handler for the query to get the root of a file system path.
/// </summary>
public class GetPathRootQueryHandler : IRequestHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPathService _pathService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetPathRootQueryHandler"/> class.
/// </summary>
/// <param name="pathService">Injected service for managing file system paths.</param>
public GetPathRootQueryHandler(IPathService pathService)
{
_pathService = pathService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the root of the specified file system path.
/// </summary>
/// <param name="request">The query containing the requested path.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <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(result.Value.Adapt<PathSegmentResponse>()), errors => errors));
}
#endregion
}
@@ -0,0 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Query for retrieving the file system path separator.
/// </summary>
public record GetPathSeparatorQuery() : IRequest<PathSeparatorResponse>;
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services;
using Mediator;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Queries;
/// <summary>
/// Handler for the query to get the path separator character of a file system path.
/// </summary>
public class GetPathSeparatorQueryHandler : IRequestHandler<GetPathSeparatorQuery, PathSeparatorResponse>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IPathService _pathService;
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="GetPathSeparatorQueryHandler"/> class.
/// </summary>
/// <param name="pathService">Injected service for managing file system paths.</param>
public GetPathSeparatorQueryHandler(IPathService pathService)
{
_pathService = pathService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Gets the path separator character of a file system path.
/// </summary>
/// <param name="request">The query containing the request.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>The file system path separator character.</returns>
public ValueTask<PathSeparatorResponse> Handle(GetPathSeparatorQuery request, CancellationToken cancellationToken)
{
return ValueTask.FromResult(new PathSeparatorResponse(_pathService.PathSeparator.ToString()));
}
#endregion
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Models.Books;
using Lumina.Application.Common.Models.Contributors;
using Lumina.Domain.Common.Enums;
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 Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands;
@@ -12,12 +14,29 @@ namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Comma
/// <summary>
/// Command for adding a book.
/// </summary>
/// <param name="Metadata">Written content metadata of the book.</param>
/// <param name="Format">The format of the book (e.g., Hardcover, Paperback), if applicable.</param>
/// <param name="Edition">The edition of the book, if applicable.</param>
/// <param name="VolumeNumber">The volume or book number in the series, if applicable.</param>
/// <param name="Series">The series name, if the book is part of a series.</param>
/// <param name="ASIN">The ASIN (Amazon Standard Identification Number) of the book, if applicable.</param>
/// <param name="GoodreadsId">The Goodreads ID of the book, if applicable.</param>
/// <param name="LCCN">The Library of Congress Control Number (LCCN) of the book, if applicable.</param>
/// <param name="OCLCNumber">The OCLC Number (WorldCat identifier) of the book, if applicable.</param>
/// <param name="OpenLibraryId">The Open Library ID of the book, if applicable.</param>
/// <param name="LibraryThingId">The LibraryThing ID of the book, if applicable.</param>
/// <param name="GoogleBooksId">The Google Books ID of the book, if applicable.</param>
/// <param name="BarnesAndNobleId">The Barnes & Noble ID of the book, if applicable.</param>
/// <param name="AppleBooksId">The Apple Books ID of the book, if applicable.</param>
/// <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>
public record AddBookCommand(
WrittenContentMetadataDto Metadata,
WrittenContentMetadataModel Metadata,
BookFormat? Format,
string? Edition,
int? VolumeNumber,
BookSeriesDto? Series,
BookSeriesModel? Series,
string? ASIN,
string? GoodreadsId,
string? LCCN,
@@ -27,7 +46,7 @@ public record AddBookCommand(
string? GoogleBooksId,
string? BarnesAndNobleId,
string? AppleBooksId,
List<IsbnDto> ISBNs,
List<MediaContributorDto> Contributors,
List<BookRatingDto> Ratings
List<IsbnModel> ISBNs,
List<MediaContributorModel> Contributors,
List<BookRatingModel> Ratings
) : IRequest<ErrorOr<Book>>;
@@ -2,8 +2,8 @@
using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Models.Books;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
@@ -12,6 +12,11 @@ using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.E
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using MapsterMapper;
using Mediator;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands;
@@ -46,7 +51,7 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
/// <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{T}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// 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)
{
@@ -162,11 +167,11 @@ public class AddBookCommandHandler : IRequestHandler<AddBookCommand, ErrorOr<Boo
return createBookResult.Errors;
var bookRepository = _unitOfWork.GetRepository<IBookRepository>();
var persistenceBook = _mapper.Map<BookDto>(createBookResult.Value);
var insertBookResult = await bookRepository.InsertAsync(persistenceBook, cancellationToken);
var persistenceBook = _mapper.Map<BookModel>(createBookResult.Value);
var insertBookResult = await bookRepository.InsertAsync(persistenceBook, cancellationToken).ConfigureAwait(false);
if (insertBookResult.IsError)
return insertBookResult.Errors;
await _unitOfWork.SaveChangesAsync(cancellationToken);
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
return createBookResult.Value;
}
@@ -1,8 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Domain.Common.Enums;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Errors;
using System.Text.RegularExpressions;
#endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands;
@@ -2,6 +2,7 @@
using ErrorOr;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries;
@@ -3,8 +3,11 @@ using ErrorOr;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using MapsterMapper;
using Mapster;
using Mediator;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries;
@@ -16,7 +19,6 @@ public class GetBooksQueryHandler : IRequestHandler<GetBooksQuery, ErrorOr<IEnum
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
#endregion
#region ====================================================================== CTOR =====================================================================================
@@ -24,11 +26,9 @@ public class GetBooksQueryHandler : IRequestHandler<GetBooksQuery, ErrorOr<IEnum
/// Initializes a new instance of the <see cref="GetBooksQueryHandler"/> 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 GetBooksQueryHandler(IUnitOfWork unitOfWork, IMapper mapper)
public GetBooksQueryHandler(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
_mapper = mapper;
}
#endregion
@@ -39,15 +39,13 @@ 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{T}"/> containing either a collection of <see cref="Book"/>, or an error message.
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="Book"/>, or an error message.
/// </returns>
public async ValueTask<ErrorOr<IEnumerable<Book>>> Handle(GetBooksQuery request, CancellationToken cancellationToken)
{
var bookRepository = _unitOfWork.GetRepository<IBookRepository>();
var getBooksResult = await bookRepository.GetAllAsync(cancellationToken).ConfigureAwait(false);
if (getBooksResult.IsError)
return getBooksResult.Errors;
return ErrorOrFactory.From(getBooksResult.Value.Select(book => _mapper.Map<Book>(book)));
return getBooksResult.Match(values => ErrorOrFactory.From(values.Adapt<IEnumerable<Book>>()), errors => errors);
}
#endregion
}
}
@@ -2,9 +2,9 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>..\..\bin\</BaseOutputPath>
<BaseOutputPath>$(SolutionDir)..\bin\server\</BaseOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
@@ -13,6 +13,8 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
<ProjectReference Include="..\Lumina.Domain\Lumina.Domain.csproj" />
</ItemGroup>