diff --git a/docs/LICENSE.md b/docs/LICENSE.md index 6bae9b54..d766ce78 100644 --- a/docs/LICENSE.md +++ b/docs/LICENSE.md @@ -189,8 +189,8 @@ If you develop a new program, and you want it to be of the greatest possible use To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. - Lyrida - web based file explorer. - Copyright (C) 2023 BinaryAlley + Lumina - complete management solution for media libraries of all kinds. + Copyright (C) 2024 BinaryAlley This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/docs/technical/domain/UbiquitousLanguage.md b/docs/technical/domain/UbiquitousLanguage.md index aac4b5d2..6d935dc8 100644 --- a/docs/technical/domain/UbiquitousLanguage.md +++ b/docs/technical/domain/UbiquitousLanguage.md @@ -36,8 +36,10 @@ - _**Cover Song**_: A rendition of a song performed by an artist other than the original - _**Remix**_: A modified version of an original song - _**Sound Effect**_: A short audio clip used for specific purposes +- _**Soundtrack**_: A collection of music used in a film or TV show - _**Podcast**_: A series of audio episodes - _**Podcast Episode**_: An individual installment of a podcast +- _**Radio Show**_: An audio program broadcast on the radio ## Written Content - _**Book**_: A standalone written work @@ -115,7 +117,7 @@ - VideoLibrary (root: VideoLibrary, entities: TVShow, Season, Episode, Movie, FilmSeries, ConcertVideo, Documentary, TutorialVideo, HomeVideo, Anime, YouTubeVideo, MusicVideo) - AudioLibrary (root: AudioLibrary, entities: Song, Album, Artist, Audiobook, LiveRecording, Interview, CoverSong, Remix, SoundEffect) - PodcastLibrary (root: PodcastLibrary, entities: Podcast, PodcastEpisode) -- WrittenContentLibrary (root: WrittenContentLibrary, entities: Book, BookSeries, ComicBook, ComicSeries, Magazine, MagazineIssue, Manga, GraphicNovel, AcademicPaper, SheetMusic, Screenplay) +- WrittenContentLibrary (root: WrittenContentLibrary, entities: Book, EBook, BookSeries, ComicBook, ComicSeries, Magazine, MagazineIssue, Manga, GraphicNovel, AcademicPaper, SheetMusic, Screenplay) - PhotoLibrary (root: PhotoLibrary, entities: Photo, PhotoAlbum, AlbumArtwork, MoviePoster) - UserProfile (root: User, entities: Playlist, Collection) - SupplementaryContentLibrary (root: SupplementaryContentLibrary, entities: SubtitleFile, Lyrics, LanguageTrack) diff --git a/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs b/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs index b4b4490d..a3b6ef59 100644 --- a/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs +++ b/src/Lumina.Application/Common/Behaviors/ValidationBehavior.cs @@ -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; /// -/// Behavior pipeline for the register command +/// Represents a validation behavior in the MediatR pipeline for handling requests and responses. /// /// The type representing a request. It should implement . /// The type representing a response. It should implement interface. @@ -15,7 +17,7 @@ public class ValidationBehavior : IPipelineBehavior? validator; + private readonly IValidator? _validator; #endregion #region ====================================================================== CTOR ===================================================================================== @@ -25,7 +27,7 @@ public class ValidationBehavior : IPipelineBehaviorThe validator used in this behavior pipeline for the Mediator commands and queries. public ValidationBehavior(IValidator? validator = null) { - this.validator = validator; + _validator = validator; } #endregion @@ -39,13 +41,13 @@ public class ValidationBehavior : IPipelineBehavior Handle(TRequest request, CancellationToken cancellationToken, MessageHandlerDelegate 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 diff --git a/src/Lumina.Application/Common/Converters/OptionalJsonConverter.cs b/src/Lumina.Application/Common/Converters/OptionalJsonConverter.cs index 61d764b1..29607964 100644 --- a/src/Lumina.Application/Common/Converters/OptionalJsonConverter.cs +++ b/src/Lumina.Application/Common/Converters/OptionalJsonConverter.cs @@ -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; /// -/// Converts an to and from JSON. +/// Converts an to and from JSON. /// -/// The type of the value represented by the structure. -public class OptionalJsonConverter : JsonConverter> +/// The type of the value represented by the structure. +public class OptionalJsonConverter : JsonConverter> { #region ===================================================================== METHODS =================================================================================== /// - /// Reads and converts the JSON to an instance of . + /// Reads and converts the JSON to an instance of . /// /// The to read from. /// The type to convert. /// An object that specifies serialization options to use. - /// The converted value. - public override Optional Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + /// The converted value. + public override Optional Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.Null) - return Optional.None(); - var value = JsonSerializer.Deserialize(ref reader, options); - return Optional.Some(value!); + return Optional.None(); + var value = JsonSerializer.Deserialize(ref reader, options); + return Optional.Some(value!); } /// - /// Writes an value as JSON. + /// Writes an value as JSON. /// /// The to write to. /// The value to convert to JSON. /// An object that specifies serialization options to use. - public override void Write(Utf8JsonWriter writer, Optional value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, Optional value, JsonSerializerOptions options) { if (value.HasValue) JsonSerializer.Serialize(writer, value.Value, options); diff --git a/src/Lumina.Application/Common/Converters/OptionalJsonConverterFactory.cs b/src/Lumina.Application/Common/Converters/OptionalJsonConverterFactory.cs index 92a66150..1f811ded 100644 --- a/src/Lumina.Application/Common/Converters/OptionalJsonConverterFactory.cs +++ b/src/Lumina.Application/Common/Converters/OptionalJsonConverterFactory.cs @@ -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. /// /// The type to check for convertibility. - /// if the type is , otherwise. + /// if the type is , otherwise. public override bool CanConvert(Type typeToConvert) { if (!typeToConvert.IsGenericType) @@ -29,7 +30,7 @@ public class OptionalJsonConverterFactory : JsonConverterFactory /// /// The type for which to create a converter. /// The serializer options to use. - /// A converter for . + /// A converter for . public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) { Type valueType = typeToConvert.GetGenericArguments()[0]; diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs index ca279313..b925c108 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Books/IBookRepository.cs @@ -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; /// /// Interface for the repository for books. /// -public interface IBookRepository : IRepository, - IInsertRepositoryAction, - IGetAllRepositoryAction +public interface IBookRepository : IRepository, + IInsertRepositoryAction, + IGetAllRepositoryAction { } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs index 0d0cf3bb..12e6f358 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteAllRepositoryAction.cs @@ -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 /// /// Deletes all entities from the storage medium. /// - /// An representing either a successfull operation, or an error. + /// An representing either a successfull operation, or an error. Task> DeleteAllAsync(); #endregion } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs index e4727002..b2d4404a 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IDeleteByIdRepositoryAction.cs @@ -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 where TId : notnull /// /// The id of the element to be deleted. /// Cancellation token that can be used to stop the execution. - /// An representing either a successfull operation, or an error. + /// An representing either a successfull operation, or an error. Task> DeleteByIdAsync(TId id, CancellationToken cancellationToken); #endregion } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs index 4a2bba09..cfaac9a3 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetAllRepositoryAction.cs @@ -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 where TModel : IStorageEntity /// Gets all data of type from the storage medium. /// /// Cancellation token that can be used to stop the execution. - /// An containing either a collection of , or an error. + /// An containing either a collection of , or an error. Task>> GetAllAsync(CancellationToken cancellationToken); #endregion } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs index 9cb18ba4..928109ff 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IGetByIdRepositoryAction.cs @@ -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 where TModel : IStorageEn /// /// The id of the element to get. /// Cancellation token that can be used to stop the execution. - /// An containing either a identified by , or an error. + /// An containing either a identified by , or an error. Task> GetByIdAsync(TId id, CancellationToken cancellationToken); #endregion } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs index 189b19f5..2d1ce4f2 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IInsertRepositoryAction.cs @@ -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 where TModel : IStorageEntity /// /// The element to be saved. /// Cancellation token that can be used to stop the execution. - /// An representing either a successfull operation, or an error. + /// An representing either a successfull operation, or an error. Task> InsertAsync(TModel data, CancellationToken cancellationToken); #endregion } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs index 6233cc42..ba908dce 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Actions/IUpdateRepositoryAction.cs @@ -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 where TModel : IStorageEntity /// /// The element that will be updated. /// Cancellation token that can be used to stop the execution. - /// An representing either a successfull operation, or an error. + /// An representing either a successfull operation, or an error. Task> UpdateAsync(TModel data, CancellationToken cancellationToken); #endregion } \ No newline at end of file diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs index 57fc4a41..4049862b 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/Common/Base/IRepository.cs @@ -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; diff --git a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs index 83932cbd..b5a45ec2 100644 --- a/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs +++ b/src/Lumina.Application/Common/DataAccess/UoW/IUnitOfWork.cs @@ -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; /// /// Interaction boundary with the Data Access Layer. diff --git a/src/Lumina.Application/Common/Mapping/FileManagement/DirectoryMappingConfig.cs b/src/Lumina.Application/Common/Mapping/FileManagement/DirectoryMappingConfig.cs new file mode 100644 index 00000000..c97bce33 --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/FileManagement/DirectoryMappingConfig.cs @@ -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; + +/// +/// Mapping configuration for file system directories between the domain object and the presentation object. +/// +public class DirectoryMappingConfig : IRegister +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Registers the mapping configuration. + /// + /// The type adapter configuration. + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .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 +} \ No newline at end of file diff --git a/src/Lumina.Application/Common/Mapping/FileManagement/FileMappingConfig.cs b/src/Lumina.Application/Common/Mapping/FileManagement/FileMappingConfig.cs new file mode 100644 index 00000000..4c32babc --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/FileManagement/FileMappingConfig.cs @@ -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; + +/// +/// Mapping configuration for file system files between the domain object and the presentation object. +/// +public class FileMappingConfig : IRegister +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Registers the mapping configuration. + /// + /// The type adapter configuration. + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .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 +} \ No newline at end of file diff --git a/src/Lumina.Application/Common/Mapping/FileManagement/FileSystemTreeMappingConfig.cs b/src/Lumina.Application/Common/Mapping/FileManagement/FileSystemTreeMappingConfig.cs new file mode 100644 index 00000000..39d715e1 --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/FileManagement/FileSystemTreeMappingConfig.cs @@ -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; + +/// +/// Mapping configuration for file system trees between the domain object and the presentation object. +/// +public class FileSystemTreeMappingConfig : IRegister +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Registers the mapping configuration. + /// + /// The type adapter configuration. + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .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() + .MapWith(src => WindowsRootItem.Create( + src.Path, + src.Name, + FileSystemItemStatus.Accessible) + .Value); + + config.NewConfig() + .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() + .MapWith(src => UnixRootItem.Create( + FileSystemItemStatus.Accessible) + .Value); + + config.NewConfig() + .MapWith(src => new FileSystemTreeNodeResponse + { + Path = src.Id.Path, + Name = src.Name, + ItemType = src.Type, + IsExpanded = false, + ChildrenLoaded = false, + Children = new List() + }); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Common/Mapping/FileManagement/PathSegmentMappingConfig.cs b/src/Lumina.Application/Common/Mapping/FileManagement/PathSegmentMappingConfig.cs new file mode 100644 index 00000000..c49a5a05 --- /dev/null +++ b/src/Lumina.Application/Common/Mapping/FileManagement/PathSegmentMappingConfig.cs @@ -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; + +/// +/// Mapping configuration for file system paths between the domain object and the presentation object. +/// +public class PathSegmentMappingConfig : IRegister +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Registers the mapping configuration. + /// + /// The type adapter configuration. + public void Register(TypeAdapterConfig config) + { + config.NewConfig() + .Map(dest => dest.Path, src => src.Name) + .MapToConstructor(true); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs b/src/Lumina.Application/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs index 7d37376c..0661c9e5 100644 --- a/src/Lumina.Application/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs +++ b/src/Lumina.Application/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs @@ -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 /// The type adapter configuration. public void Register(TypeAdapterConfig config) { - config.NewConfig() + config.NewConfig() .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() + config.NewConfig() .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, BookRatingSource?>() .MapWith(src => src.HasValue ? src.Value : default); - // from BookDto to Book - config.NewConfig() + // from BookModel to Book + config.NewConfig() .MapWith(src => Book.Create( BookId.Create(src.Id), WrittenContentMetadata.Create( diff --git a/src/Lumina.Application/Common/Models/Books/BookRatingDto.cs b/src/Lumina.Application/Common/Models/Books/BookRatingDto.cs deleted file mode 100644 index ee3e8094..00000000 --- a/src/Lumina.Application/Common/Models/Books/BookRatingDto.cs +++ /dev/null @@ -1,16 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Common; -using Lumina.Domain.Common.Enums; -#endregion - -namespace Lumina.Application.Common.Models.Books; - -/// -/// Represents a book rating. -/// -public record BookRatingDto( - decimal? Value, - decimal? MaxValue, - BookRatingSource? Source, - int? VoteCount -) : RatingDto(Value, MaxValue, VoteCount); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Books/BookSeriesDto.cs b/src/Lumina.Application/Common/Models/Books/BookSeriesDto.cs deleted file mode 100644 index e1eed337..00000000 --- a/src/Lumina.Application/Common/Models/Books/BookSeriesDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Lumina.Application.Common.Models.Books; - -/// -/// Represents a request to get book series information. -/// -public record BookSeriesDto( - string? Title -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Books/IsbnDto.cs b/src/Lumina.Application/Common/Models/Books/IsbnDto.cs deleted file mode 100644 index 14b1420b..00000000 --- a/src/Lumina.Application/Common/Models/Books/IsbnDto.cs +++ /dev/null @@ -1,13 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; -#endregion - -namespace Lumina.Application.Common.Models.Books; - -/// -/// Represents a request to get ISBN information. -/// -public record IsbnDto( - string? Value, - IsbnFormat? Format -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Books/WrittenContentMetadataDto.cs b/src/Lumina.Application/Common/Models/Books/WrittenContentMetadataDto.cs deleted file mode 100644 index 34076bc4..00000000 --- a/src/Lumina.Application/Common/Models/Books/WrittenContentMetadataDto.cs +++ /dev/null @@ -1,21 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Common; -#endregion - -namespace Lumina.Application.Common.Models.Books; - -/// -/// Represents written content metadata. -/// -public record WrittenContentMetadataDto( - string? Title, - string? OriginalTitle, - string? Description, - ReleaseInfoDto? ReleaseInfo, - List? Genres, - List? Tags, - LanguageInfoDto? Language, - LanguageInfoDto? OriginalLanguage, - string? Publisher, - int? PageCount -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Common/GenreDto.cs b/src/Lumina.Application/Common/Models/Common/GenreDto.cs deleted file mode 100644 index 2ea9c42d..00000000 --- a/src/Lumina.Application/Common/Models/Common/GenreDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Lumina.Application.Common.Models.Common; - -/// -/// Represents a request to get genre information. -/// -public record GenreDto( - string? Name -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Common/LanguageInfoDto.cs b/src/Lumina.Application/Common/Models/Common/LanguageInfoDto.cs deleted file mode 100644 index d0129597..00000000 --- a/src/Lumina.Application/Common/Models/Common/LanguageInfoDto.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Lumina.Application.Common.Models.Common; - -/// -/// Represents a request to get language information. -/// -public record LanguageInfoDto( - string? LanguageCode, - string? LanguageName, - string? NativeName -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Common/RatingDto.cs b/src/Lumina.Application/Common/Models/Common/RatingDto.cs deleted file mode 100644 index 14acfe50..00000000 --- a/src/Lumina.Application/Common/Models/Common/RatingDto.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Lumina.Application.Common.Models.Common; - -/// -/// Represents a rating. -/// -public abstract record RatingDto( - decimal? Value, - decimal? MaxValue, - int? VoteCount -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Common/ReleaseInfoDto.cs b/src/Lumina.Application/Common/Models/Common/ReleaseInfoDto.cs deleted file mode 100644 index a11153de..00000000 --- a/src/Lumina.Application/Common/Models/Common/ReleaseInfoDto.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Lumina.Application.Common.Models.Common; - -/// -/// Represents a request to get release information. -/// -public record ReleaseInfoDto( - DateOnly? OriginalReleaseDate, - int? OriginalReleaseYear, - DateOnly? ReReleaseDate, - int? ReReleaseYear, - string? ReleaseCountry, - string? ReleaseVersion -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Common/TagDto.cs b/src/Lumina.Application/Common/Models/Common/TagDto.cs deleted file mode 100644 index 270c68c1..00000000 --- a/src/Lumina.Application/Common/Models/Common/TagDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Lumina.Application.Common.Models.Common; - -/// -/// Represents a request to get tag information. -/// -public record TagDto( - string? Name -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Contributors/MediaContributorDto.cs b/src/Lumina.Application/Common/Models/Contributors/MediaContributorDto.cs deleted file mode 100644 index 0d8f4039..00000000 --- a/src/Lumina.Application/Common/Models/Contributors/MediaContributorDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Lumina.Application.Common.Models.Contributors; - -/// -/// Represents a media contributor. -/// -public record MediaContributorDto( - MediaContributorNameDto? Name, - MediaContributorRoleDto? Role -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Contributors/MediaContributorNameDto.cs b/src/Lumina.Application/Common/Models/Contributors/MediaContributorNameDto.cs deleted file mode 100644 index 85373e6f..00000000 --- a/src/Lumina.Application/Common/Models/Contributors/MediaContributorNameDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Lumina.Application.Common.Models.Contributors; - -/// -/// Represents a media contributor name. -/// -public record MediaContributorNameDto( - string? DisplayName, - string? LegalName -); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Contributors/MediaContributorRoleDto.cs b/src/Lumina.Application/Common/Models/Contributors/MediaContributorRoleDto.cs deleted file mode 100644 index a7f42b52..00000000 --- a/src/Lumina.Application/Common/Models/Contributors/MediaContributorRoleDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Lumina.Application.Common.Models.Contributors; - -/// -/// Represents a media contributor role. -/// -public record MediaContributorRoleDto( - string? Name, - string? Category -); \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQuery.cs b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQuery.cs new file mode 100644 index 00000000..fd8bfa61 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQuery.cs @@ -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; + +/// +/// Query for retrieving the list of directories at a path. +/// +/// The path for which to retrieve the list of directories. +public record GetDirectoriesQuery(string Path) : IRequest>>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQueryHandler.cs new file mode 100644 index 00000000..e6a4e361 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get all directories. +/// +public class GetDirectoriesQueryHandler : IRequestHandler>> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IDirectoryService _directoryService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling directories. + public GetDirectoriesQueryHandler(IDirectoryService directoryService) + { + _directoryService = directoryService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the list of directories at the specified path. + /// + /// The query containing the requested path. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either a collection of , or an error message. + /// + public ValueTask>> Handle(GetDirectoriesQuery request, CancellationToken cancellationToken) + { + ErrorOr> result = _directoryService.GetSubdirectories(request.Path); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt>()), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQueryValidator.cs b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQueryValidator.cs new file mode 100644 index 00000000..42c2f57b --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoriesQueryValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Directories.Queries; + +/// +/// Validates the needed validation rules for . +/// +public class GetDirectoriesQueryValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public GetDirectoriesQueryValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQuery.cs b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQuery.cs new file mode 100644 index 00000000..aeaaa40e --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQuery.cs @@ -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; + +/// +/// Query for retrieving the tree of directories of a path. +/// +/// The path for which to retrieve the tree of directories. +public record GetDirectoryTreeQuery(string Path) : IRequest>>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQueryHandler.cs new file mode 100644 index 00000000..5df28bcf --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get a directory tree. +/// +public class GetDirectoryTreeQueryHandler : IRequestHandler>> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IDirectoryService _directoryService; + private readonly IFileService _fileService; + private readonly IPathService _pathService; + private readonly IDriveService _driveService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling file system drives. + /// Injected service for handling directories. + /// Injected service for handling files. + /// Injected service for handling file system paths. + public GetDirectoryTreeQueryHandler(IDriveService driveService, IDirectoryService directoryService, IFileService fileService, IPathService pathService) + { + _directoryService = directoryService; + _fileService = fileService; + _pathService = pathService; + _driveService = driveService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// 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. + /// + /// + /// An containing either a collection of , or an error message. + /// + public async ValueTask>> Handle(GetDirectoryTreeQuery request, CancellationToken cancellationToken) + { + List result = []; + // retrieve the list of drives + ErrorOr> getDrivesResult = GetDrives(); + if (getDrivesResult.IsError) + return getDrivesResult.Errors; + result.AddRange(getDrivesResult.Value); + + ErrorOr> pathPartsResults = _pathService.ParsePath(request.Path); + if (pathPartsResults.IsError) + return pathPartsResults.Errors; + + List pathParts = pathPartsResults.Value.ToList(); + string currentPath = pathParts[0].Name; + + ErrorOr> buildDirectoryTreeResult = BuildDirectoryTree(result, pathParts, out FileSystemTreeNodeResponse currentNode); + if (buildDirectoryTreeResult.IsError) + return buildDirectoryTreeResult.Errors; + + // add subdirectories of the last directory node + ErrorOr loadChildrenResult = LoadChildren(currentNode); + if (loadChildrenResult.IsError) + return loadChildrenResult.Errors; + return await ValueTask.FromResult(result); + } + + /// + /// Gets the root drives (on Windows), or an empty list on Unix-based systems. + /// + /// + /// An containing a list of , or an error message. + /// + private ErrorOr> GetDrives() + { + ErrorOr> driveResult = _driveService.GetDrives(); + if (driveResult.IsError) + return driveResult.Errors; + return ErrorOrFactory.From(driveResult.Value.Adapt>()); + } + + /// + /// Builds the tree of directories based on the parsed path parts. + /// + /// The list of available drives. + /// The list of parsed path segments (directories). + /// + /// An containing a list of representing the directory tree, or an error message. + /// + private ErrorOr> BuildDirectoryTree(List drives, List 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 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 { drive }; + } + + /// + /// Loads the child directories and files of the specified directory node. + /// + /// The directory node to load children for. + /// A result indicating a successful operation, or an error message. + private ErrorOr LoadChildren(FileSystemTreeNodeResponse node) + { + // get subdirectories under the current node's path + ErrorOr> 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> 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 +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQueryValidator.cs b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQueryValidator.cs new file mode 100644 index 00000000..aef350d2 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Directories/Queries/GetDirectoryTreeQueryValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Directories.Queries; + +/// +/// Validates the needed validation rules for . +/// +public class GetDirectoryTreeQueryValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public GetDirectoryTreeQueryValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Drives/Queries/GetDrivesQuery.cs b/src/Lumina.Application/Core/FileManagement/Drives/Queries/GetDrivesQuery.cs new file mode 100644 index 00000000..962fb4ac --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Drives/Queries/GetDrivesQuery.cs @@ -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; + +/// +/// Query for retrieving the list of drives. +/// +public record GetDrivesQuery() : IRequest>>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Drives/Queries/GetDrivesQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Drives/Queries/GetDrivesQueryHandler.cs new file mode 100644 index 00000000..87732e4d --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Drives/Queries/GetDrivesQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get all drives. +/// +public class GetDrivesQueryHandler : IRequestHandler>> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IDriveService _driveService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling file system drives. + public GetDrivesQueryHandler(IDriveService driveService) + { + _driveService = driveService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the list of file system drives. + /// + /// The query containing the requested path. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either a collection of , or an error message. + /// + public ValueTask>> Handle(GetDrivesQuery request, CancellationToken cancellationToken) + { + ErrorOr> result = _driveService.GetDrives(); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(values.Adapt>()), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/FileSystem/Queries/GetFileSystemQuery.cs b/src/Lumina.Application/Core/FileManagement/FileSystem/Queries/GetFileSystemQuery.cs new file mode 100644 index 00000000..affeeef1 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/FileSystem/Queries/GetFileSystemQuery.cs @@ -0,0 +1,11 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Responses.FileManagement; +using Mediator; +#endregion + +namespace Lumina.Application.Core.FileManagement.FileSystem.Queries; + +/// +/// Query for retrieving the file system type. +/// +public record GetFileSystemQuery() : IRequest; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/FileSystem/Queries/GetFileSystemQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/FileSystem/Queries/GetFileSystemQueryHandler.cs new file mode 100644 index 00000000..e9aa0473 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/FileSystem/Queries/GetFileSystemQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get the file system type. +/// +public class GetFileSystemQueryHandler : IRequestHandler +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPlatformContext _platformContext; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for managing platform contexts. + public GetFileSystemQueryHandler(IPlatformContextManager platformContextManager) + { + _platformContext = platformContextManager.GetCurrentContext(); + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the type of the file system. + /// + /// The query to be handled. + /// Cancellation token that can be used to stop the execution. + /// The type of the file system. + public ValueTask Handle(GetFileSystemQuery request, CancellationToken cancellationToken) + { + return ValueTask.FromResult(new FileSystemTypeResponse(_platformContext.Platform)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQuery.cs b/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQuery.cs new file mode 100644 index 00000000..6b799f36 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQuery.cs @@ -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; + +/// +/// Query for retrieving the list of files at a path. +/// +/// The path for which to retrieve the list of files. +public record GetFilesQuery(string Path) : IRequest>>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQueryHandler.cs new file mode 100644 index 00000000..3585fad7 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get all files. +/// +public class GetFilesQueryHandler : IRequestHandler>> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IFileService _fileService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling files. + public GetFilesQueryHandler(IFileService fileService) + { + _fileService = fileService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the list of files at the specified path. + /// + /// The query containing the requested path. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either a collection of , or an error message. + /// + public ValueTask>> Handle(GetFilesQuery request, CancellationToken cancellationToken) + { + ErrorOr> result = _fileService.GetFiles(request.Path); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt>()), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQueryValidator.cs b/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQueryValidator.cs new file mode 100644 index 00000000..4d7eea95 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Files/Queries/GetFilesQueryValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Files.Queries; + +/// +/// Validates the needed validation rules for . +/// +public class GetFilesQueryValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public GetFilesQueryValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommand.cs b/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommand.cs new file mode 100644 index 00000000..7a3ee5fb --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommand.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Responses.FileManagement; +using Mediator; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Commands; + +/// +/// Command for combining two file system path. +/// +/// The path to combine to. +/// The path to combine with. +public record CombinePathCommand( + string OriginalPath, string NewPath +) : IRequest>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommandHandler.cs b/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommandHandler.cs new file mode 100644 index 00000000..9125bd36 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommandHandler.cs @@ -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; + +/// +/// Handler for the command to split a file system path. +/// +public class CombinePathCommandHandler : IRequestHandler> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPathService _pathService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling file system paths. + public CombinePathCommandHandler(IPathService pathService) + { + _pathService = pathService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Combines two file system paths. + /// + /// The command containing the requested paths. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either a , or an error message. + /// + public ValueTask> Handle(CombinePathCommand request, CancellationToken cancellationToken) + { + ErrorOr result = _pathService.CombinePath(request.OriginalPath, request.NewPath); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(new PathSegmentResponse(result.Value)), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommandValidator.cs b/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommandValidator.cs new file mode 100644 index 00000000..84770cb9 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Commands/CombinePathCommandValidator.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Commands; + +/// +/// Validates the needed validation rules for . +/// +public class CombinePathCommandValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public CombinePathCommandValidator() + { + RuleFor(x => x.OriginalPath).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + RuleFor(x => x.NewPath).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommand.cs b/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommand.cs new file mode 100644 index 00000000..bd48d787 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommand.cs @@ -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; + +/// +/// Command for splitting a file system path. +/// +/// The path to split. +public record SplitPathCommand( + string Path +) : IRequest>>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommandHandler.cs b/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommandHandler.cs new file mode 100644 index 00000000..8532f507 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommandHandler.cs @@ -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; + +/// +/// Handler for the command to split a file system path. +/// +public class SplitPathCommandHandler : IRequestHandler>> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPathService _pathService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for handling file system paths. + public SplitPathCommandHandler(IPathService pathService) + { + _pathService = pathService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the path components of the specified path. + /// + /// The command containing the requested path. + /// Cancellation token that can be used to stop the execution. + /// + /// An containing either a collection of , or an error message. + /// + public ValueTask>> Handle(SplitPathCommand request, CancellationToken cancellationToken) + { + ErrorOr> result = _pathService.ParsePath(request.Path); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt>()), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommandValidator.cs b/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommandValidator.cs new file mode 100644 index 00000000..6932dd53 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Commands/SplitPathCommandValidator.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using FluentValidation; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Commands; + +/// +/// Validates the needed validation rules for . +/// +public class SplitPathCommandValidator : AbstractValidator +{ + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + public SplitPathCommandValidator() + { + RuleFor(x => x.Path).NotEmpty().WithMessage(Errors.FileManagement.PathCannotBeEmpty.Code); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQuery.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQuery.cs new file mode 100644 index 00000000..c7d45a8c --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQuery.cs @@ -0,0 +1,13 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Responses.FileManagement; +using Mediator; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Query for retrieving the root of a path. +/// +/// The path for which to get the path root. +public record GetPathRootQuery(string Path) : IRequest>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQueryHandler.cs new file mode 100644 index 00000000..e3633ad6 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathRootQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get the root of a file system path. +/// +public class GetPathRootQueryHandler : IRequestHandler> +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPathService _pathService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for managing file system paths. + public GetPathRootQueryHandler(IPathService pathService) + { + _pathService = pathService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the root of the specified file system path. + /// + /// The query containing the requested path. + /// Cancellation token that can be used to stop the execution. + /// The root of the specified path. + public ValueTask> Handle(GetPathRootQuery request, CancellationToken cancellationToken) + { + ErrorOr result = _pathService.GetPathRoot(request.Path); + return ValueTask.FromResult(result.Match(values => ErrorOrFactory.From(result.Value.Adapt()), errors => errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathSeparatorQuery.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathSeparatorQuery.cs new file mode 100644 index 00000000..f4459dc7 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathSeparatorQuery.cs @@ -0,0 +1,11 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Responses.FileManagement; +using Mediator; +#endregion + +namespace Lumina.Application.Core.FileManagement.Paths.Queries; + +/// +/// Query for retrieving the file system path separator. +/// +public record GetPathSeparatorQuery() : IRequest; \ No newline at end of file diff --git a/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathSeparatorQueryHandler.cs b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathSeparatorQueryHandler.cs new file mode 100644 index 00000000..41bdb8c1 --- /dev/null +++ b/src/Lumina.Application/Core/FileManagement/Paths/Queries/GetPathSeparatorQueryHandler.cs @@ -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; + +/// +/// Handler for the query to get the path separator character of a file system path. +/// +public class GetPathSeparatorQueryHandler : IRequestHandler +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IPathService _pathService; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for managing file system paths. + public GetPathSeparatorQueryHandler(IPathService pathService) + { + _pathService = pathService; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the path separator character of a file system path. + /// + /// The query containing the request. + /// Cancellation token that can be used to stop the execution. + /// The file system path separator character. + public ValueTask Handle(GetPathSeparatorQuery request, CancellationToken cancellationToken) + { + return ValueTask.FromResult(new PathSeparatorResponse(_pathService.PathSeparator.ToString())); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommand.cs b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommand.cs index c85e795e..d1cc4148 100644 --- a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommand.cs +++ b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommand.cs @@ -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 /// /// Command for adding a book. /// +/// Written content metadata of the book. +/// The format of the book (e.g., Hardcover, Paperback), if applicable. +/// The edition of the book, if applicable. +/// The volume or book number in the series, if applicable. +/// The series name, if the book is part of a series. +/// The ASIN (Amazon Standard Identification Number) of the book, if applicable. +/// The Goodreads ID of the book, if applicable. +/// The Library of Congress Control Number (LCCN) of the book, if applicable. +/// The OCLC Number (WorldCat identifier) of the book, if applicable. +/// The Open Library ID of the book, if applicable. +/// The LibraryThing ID of the book, if applicable. +/// The Google Books ID of the book, if applicable. +/// The Barnes & Noble ID of the book, if applicable. +/// The Apple Books ID of the book, if applicable. +/// The list of ISBN (International Standard Book Number) of the book. +/// The list of media contributors (actors, directors, etc) starring in this book. +/// The list of ratings for this book. 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 ISBNs, - List Contributors, - List Ratings + List ISBNs, + List Contributors, + List Ratings ) : IRequest>; \ No newline at end of file diff --git a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandler.cs b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandler.cs index aed72e0a..b7ff9eac 100644 --- a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandler.cs +++ b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandler.cs @@ -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 : IRequestHandlerThe request to be handled. /// Cancellation token that can be used to stop the execution. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public async ValueTask> Handle(AddBookCommand request, CancellationToken cancellationToken) { @@ -162,11 +167,11 @@ public class AddBookCommandHandler : IRequestHandler(); - var persistenceBook = _mapper.Map(createBookResult.Value); - var insertBookResult = await bookRepository.InsertAsync(persistenceBook, cancellationToken); + var persistenceBook = _mapper.Map(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; } diff --git a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidator.cs b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidator.cs index 8af5d2f7..c405a651 100644 --- a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidator.cs +++ b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidator.cs @@ -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; diff --git a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQuery.cs b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQuery.cs index c1fa4bb6..08b60f59 100644 --- a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQuery.cs +++ b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQuery.cs @@ -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; diff --git a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQueryHandler.cs b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQueryHandler.cs index ab81aa78..1d4cc017 100644 --- a/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQueryHandler.cs +++ b/src/Lumina.Application/Core/WrittenContentLibrary/BooksLibrary/Books/Queries/GetBooksQueryHandler.cs @@ -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 class. /// /// Injected unit of work for interacting with the data access layer repositories. - /// Injected service for mapping objects. - public GetBooksQueryHandler(IUnitOfWork unitOfWork, IMapper mapper) + public GetBooksQueryHandler(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; - _mapper = mapper; } #endregion @@ -39,15 +39,13 @@ public class GetBooksQueryHandler : IRequestHandlerThe request to be handled. /// Cancellation token that can be used to stop the execution. /// - /// An containing either a collection of , or an error message. + /// An containing either a collection of , or an error message. /// public async ValueTask>> Handle(GetBooksQuery request, CancellationToken cancellationToken) { var bookRepository = _unitOfWork.GetRepository(); var getBooksResult = await bookRepository.GetAllAsync(cancellationToken).ConfigureAwait(false); - if (getBooksResult.IsError) - return getBooksResult.Errors; - return ErrorOrFactory.From(getBooksResult.Value.Select(book => _mapper.Map(book))); + return getBooksResult.Match(values => ErrorOrFactory.From(values.Adapt>()), errors => errors); } #endregion -} +} \ No newline at end of file diff --git a/src/Lumina.Application/Lumina.Application.csproj b/src/Lumina.Application/Lumina.Application.csproj index 26e29432..73407fc8 100644 --- a/src/Lumina.Application/Lumina.Application.csproj +++ b/src/Lumina.Application/Lumina.Application.csproj @@ -2,9 +2,9 @@ net8.0 - enable + disable enable - ..\..\bin\ + $(SolutionDir)..\bin\server\ false @@ -13,6 +13,8 @@ + + diff --git a/src/Lumina.Contracts/Enums/AudioLibrary/AudioContentType.cs b/src/Lumina.Contracts/Enums/AudioLibrary/AudioContentType.cs new file mode 100644 index 00000000..d73fe365 --- /dev/null +++ b/src/Lumina.Contracts/Enums/AudioLibrary/AudioContentType.cs @@ -0,0 +1,57 @@ +namespace Lumina.Contracts.Enums.AudioLibrary; + +/// +/// Enumeration for the types of audio content libraries. +/// +public enum AudioContentType +{ + /// + /// A musical composition typically consisting of vocals and/or instruments. + /// + Music, + + /// + /// A recording of a book or other written work being read aloud. + /// + AudioBook, + + /// + /// An audio recording of a live musical or spoken word performance. + /// + LivePerformance, + + /// + /// A recorded conversation where one person asks questions and another provides answers. + /// + Interview, + + /// + /// A new performance or recording of a previously released song. + /// + Cover, + + /// + /// An alternative version of a recorded song, typically with altered instrumentation or structure. + /// + Remix, + + /// + /// An audio recording used to create a specific acoustic environment or impression. + /// + Soundeffect, + + /// + /// A digital audio file made available on the internet for downloading to a computer or mobile device. + /// + Podcast, + + /// + /// A regularly scheduled broadcast program consisting of music, talk, or other audio content. + /// + RadioShow, + + /// + /// A collection of music used as background sound for a movie, TV show, video game, or other media. + /// + Soundtrack, +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Enums/AudioRatingSource.cs b/src/Lumina.Contracts/Enums/AudioLibrary/AudioRatingSource.cs similarity index 93% rename from src/Lumina.Domain/Common/Enums/AudioRatingSource.cs rename to src/Lumina.Contracts/Enums/AudioLibrary/AudioRatingSource.cs index 2f0ae5df..6662b15a 100644 --- a/src/Lumina.Domain/Common/Enums/AudioRatingSource.cs +++ b/src/Lumina.Contracts/Enums/AudioLibrary/AudioRatingSource.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.AudioLibrary; /// /// Enumeration for the various sources of audio ratings. diff --git a/src/Lumina.Domain/Common/Enums/BookFormat.cs b/src/Lumina.Contracts/Enums/BookLibrary/BookFormat.cs similarity index 97% rename from src/Lumina.Domain/Common/Enums/BookFormat.cs rename to src/Lumina.Contracts/Enums/BookLibrary/BookFormat.cs index acb407c6..3f9354ff 100644 --- a/src/Lumina.Domain/Common/Enums/BookFormat.cs +++ b/src/Lumina.Contracts/Enums/BookLibrary/BookFormat.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.BookLibrary; /// /// Enumeration for various book formats. diff --git a/src/Lumina.Domain/Common/Enums/BookRatingSource.cs b/src/Lumina.Contracts/Enums/BookLibrary/BookRatingSource.cs similarity index 94% rename from src/Lumina.Domain/Common/Enums/BookRatingSource.cs rename to src/Lumina.Contracts/Enums/BookLibrary/BookRatingSource.cs index e62e4d00..2e2c50c4 100644 --- a/src/Lumina.Domain/Common/Enums/BookRatingSource.cs +++ b/src/Lumina.Contracts/Enums/BookLibrary/BookRatingSource.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.BookLibrary; /// /// Enumeration for the various sources of book ratings. diff --git a/src/Lumina.Domain/Common/Enums/IsbnFormat.cs b/src/Lumina.Contracts/Enums/BookLibrary/IsbnFormat.cs similarity index 90% rename from src/Lumina.Domain/Common/Enums/IsbnFormat.cs rename to src/Lumina.Contracts/Enums/BookLibrary/IsbnFormat.cs index dcb017df..977b6ff1 100644 --- a/src/Lumina.Domain/Common/Enums/IsbnFormat.cs +++ b/src/Lumina.Contracts/Enums/BookLibrary/IsbnFormat.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.BookLibrary; /// /// Enumeration for the different ISBN (International Standard Book Number) formats. diff --git a/src/Lumina.Contracts/Enums/BookLibrary/WrittenContentType.cs b/src/Lumina.Contracts/Enums/BookLibrary/WrittenContentType.cs new file mode 100644 index 00000000..329b3ed4 --- /dev/null +++ b/src/Lumina.Contracts/Enums/BookLibrary/WrittenContentType.cs @@ -0,0 +1,62 @@ +namespace Lumina.Contracts.Enums.BookLibrary; + +/// +/// Enumeration for the types of written content libraries. +/// +public enum WrittenContentType +{ + /// + /// A printed or written literary work. + /// + Book, + + /// + /// An electronic version of a printed book. + /// + EBook, + + /// + /// A set of related books published in succession. + /// + BookSeries, + + /// + /// A magazine or book containing sequential art in the form of a narrative. + /// + ComicBook, + + /// + /// A set of related comic books published in succession. + /// + ComicSeries, + + /// + /// A periodical publication containing articles, stories, and other content. + /// + Magazine, + + /// + /// A style of Japanese comic books and graphic novels. + /// + Manga, + + /// + /// A novel in comic-strip format, typically with sophisticated artwork and complex storylines. + /// + GraphicNovel, + + /// + /// A scholarly article presenting original research or analysis. + /// + AcademicPaper, + + /// + /// A handwritten or printed form of musical notation. + /// + SheetMusic, + + /// + /// A script for a film, television program, or other visual media. + /// + Screenplay, +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Enums/FileAccessMode.cs b/src/Lumina.Contracts/Enums/FileSystem/FileAccessMode.cs similarity index 94% rename from src/Lumina.Domain/Common/Enums/FileAccessMode.cs rename to src/Lumina.Contracts/Enums/FileSystem/FileAccessMode.cs index 458b1ca2..1861ac81 100644 --- a/src/Lumina.Domain/Common/Enums/FileAccessMode.cs +++ b/src/Lumina.Contracts/Enums/FileSystem/FileAccessMode.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.FileSystem; /// /// Enumeration for file access mode types. diff --git a/src/Lumina.Domain/Common/Enums/FileSystemItemStatus.cs b/src/Lumina.Contracts/Enums/FileSystem/FileSystemItemStatus.cs similarity index 91% rename from src/Lumina.Domain/Common/Enums/FileSystemItemStatus.cs rename to src/Lumina.Contracts/Enums/FileSystem/FileSystemItemStatus.cs index 8d61b550..04cb3480 100644 --- a/src/Lumina.Domain/Common/Enums/FileSystemItemStatus.cs +++ b/src/Lumina.Contracts/Enums/FileSystem/FileSystemItemStatus.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.FileSystem; /// /// Enumeration for file system item statuses types. diff --git a/src/Lumina.Domain/Common/Enums/FileSystemItemType.cs b/src/Lumina.Contracts/Enums/FileSystem/FileSystemItemType.cs similarity index 73% rename from src/Lumina.Domain/Common/Enums/FileSystemItemType.cs rename to src/Lumina.Contracts/Enums/FileSystem/FileSystemItemType.cs index 4325ad85..e34dad49 100644 --- a/src/Lumina.Domain/Common/Enums/FileSystemItemType.cs +++ b/src/Lumina.Contracts/Enums/FileSystem/FileSystemItemType.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.FileSystem; /// /// Enumeration for the types of file system elements. @@ -6,9 +6,9 @@ public enum FileSystemItemType { /// - /// Represents a drive, such as a hard disk, USB drive, or network drive. + /// Represents a file system root, which can be a drive on Windows, and a path separator on Unix. /// - Drive, + Root, /// /// Represents a directory, which is a directory that can contain other directories or files. diff --git a/src/Lumina.Domain/Common/Enums/PlatformType.cs b/src/Lumina.Contracts/Enums/FileSystem/PlatformType.cs similarity index 87% rename from src/Lumina.Domain/Common/Enums/PlatformType.cs rename to src/Lumina.Contracts/Enums/FileSystem/PlatformType.cs index 936f2d96..61857f54 100644 --- a/src/Lumina.Domain/Common/Enums/PlatformType.cs +++ b/src/Lumina.Contracts/Enums/FileSystem/PlatformType.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.FileSystem; /// /// Enumeration for platform types. diff --git a/src/Lumina.Contracts/Enums/Library/LibraryType.cs b/src/Lumina.Contracts/Enums/Library/LibraryType.cs new file mode 100644 index 00000000..13362213 --- /dev/null +++ b/src/Lumina.Contracts/Enums/Library/LibraryType.cs @@ -0,0 +1,32 @@ +namespace Lumina.Contracts.Enums.Library; + +/// +/// Enumeration for the types of libraries. +/// +public enum LibraryType +{ + /// + /// Content that is written, such as books, articles, or other written works. + /// + WrittenContent, + + /// + /// Content that is video, such as movies, TV shows, or other video works. + /// + VideoContent, + + /// + /// Content that is audio, such as podcasts, radio shows, or other audio works. + /// + AudioContent, + + /// + /// Content that is visual, such as images, paintings, or other visual works. + /// + VisualContent, + + /// + /// Content that is miscellaneous, such as lyrics, movie posters, or other miscellaneous works. + /// + MiscellaneousContent, +} \ No newline at end of file diff --git a/src/Lumina.Contracts/Enums/Library/MiscellaneousContentType.cs b/src/Lumina.Contracts/Enums/Library/MiscellaneousContentType.cs new file mode 100644 index 00000000..6eaf688a --- /dev/null +++ b/src/Lumina.Contracts/Enums/Library/MiscellaneousContentType.cs @@ -0,0 +1,12 @@ +namespace Lumina.Contracts.Enums.Library; + +/// +/// Enumeration for the types of miscellaneous content libraries. +/// +public enum MiscellaneousContentType +{ + /// + /// A collection of media that does not fit into any other category. + /// + Other, +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Enums/ImageType.cs b/src/Lumina.Contracts/Enums/PhotoLibrary/ImageType.cs similarity index 84% rename from src/Lumina.Domain/Common/Enums/ImageType.cs rename to src/Lumina.Contracts/Enums/PhotoLibrary/ImageType.cs index b9f4d423..22d4c4e0 100644 --- a/src/Lumina.Domain/Common/Enums/ImageType.cs +++ b/src/Lumina.Contracts/Enums/PhotoLibrary/ImageType.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.PhotoLibrary; /// /// Enumeration for known image types. diff --git a/src/Lumina.Contracts/Enums/PhotoLibrary/VisualContentType.cs b/src/Lumina.Contracts/Enums/PhotoLibrary/VisualContentType.cs new file mode 100644 index 00000000..3e4e8707 --- /dev/null +++ b/src/Lumina.Contracts/Enums/PhotoLibrary/VisualContentType.cs @@ -0,0 +1,12 @@ +namespace Lumina.Contracts.Enums.PhotoLibrary; + +/// +/// Enumeration for the types of visual content libraries. +/// +public enum VisualContentType +{ + /// + /// A collection of photographs organized together. + /// + PhotoAlbum, +} \ No newline at end of file diff --git a/src/Lumina.Contracts/Enums/VideoLibrary/VideoContentType.cs b/src/Lumina.Contracts/Enums/VideoLibrary/VideoContentType.cs new file mode 100644 index 00000000..2a72bbd4 --- /dev/null +++ b/src/Lumina.Contracts/Enums/VideoLibrary/VideoContentType.cs @@ -0,0 +1,62 @@ +namespace Lumina.Contracts.Enums.FileSystem.VideoLibrary; + +/// +/// Enumeration for the types of video content libraries. +/// +public enum VideoContentType +{ + /// + /// A series of related episodes broadcast on television or streaming platforms. + /// + TvShow, + + /// + /// A feature-length film produced for cinema or home viewing. + /// + Movie, + + /// + /// A collection of related films released in succession. + /// + FilmSeries, + + /// + /// A collection of related films, TV shows, and other media sharing a fictional universe. + /// + FilmFranchise, + + /// + /// A live musical performance recorded on video. + /// + Concert, + + /// + /// A non-fictional film or TV program presenting facts and information about a specific subject. + /// + Documentary, + + /// + /// An instructional video designed to teach a skill or provide information on a specific topic. + /// + Tutorial, + + /// + /// Privately recorded videos, often for personal use or sharing with friends and family. + /// + Personal, + + /// + /// Japanese animated productions, typically characterized by colorful graphics and vibrant characters. + /// + Anime, + + /// + /// Videos hosted on or originating from the YouTube platform. + /// + Youtube, + + /// + /// A short video, typically set to music, such as a music video or promotional clip. + /// + Videoclip, +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Enums/VideoRatingSource.cs b/src/Lumina.Contracts/Enums/VideoLibrary/VideoRatingSource.cs similarity index 94% rename from src/Lumina.Domain/Common/Enums/VideoRatingSource.cs rename to src/Lumina.Contracts/Enums/VideoLibrary/VideoRatingSource.cs index b8bf17b4..05c81e4f 100644 --- a/src/Lumina.Domain/Common/Enums/VideoRatingSource.cs +++ b/src/Lumina.Contracts/Enums/VideoLibrary/VideoRatingSource.cs @@ -1,4 +1,4 @@ -namespace Lumina.Domain.Common.Enums; +namespace Lumina.Contracts.Enums.VideoLibrary; /// /// Enumeration for the various sources of video ratings. diff --git a/src/Lumina.Contracts/Lumina.Contracts.csproj b/src/Lumina.Contracts/Lumina.Contracts.csproj new file mode 100644 index 00000000..ab6554a1 --- /dev/null +++ b/src/Lumina.Contracts/Lumina.Contracts.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + disable + enable + $(SolutionDir)..\bin\server\ + false + + + + + + + + + + + diff --git a/src/Lumina.Contracts/Models/Common/GenreModel.cs b/src/Lumina.Contracts/Models/Common/GenreModel.cs new file mode 100644 index 00000000..84ca2efc --- /dev/null +++ b/src/Lumina.Contracts/Models/Common/GenreModel.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.Common; + +/// +/// Represents a request to get genre information. +/// +/// Gets the name of the genre. +[DebuggerDisplay("{Name}")] +public record GenreModel( + string? Name +); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Common/IStorageEntity.cs b/src/Lumina.Contracts/Models/Common/IStorageEntity.cs similarity index 68% rename from src/Lumina.Application/Common/Models/Common/IStorageEntity.cs rename to src/Lumina.Contracts/Models/Common/IStorageEntity.cs index 1ee22c4c..d326d792 100644 --- a/src/Lumina.Application/Common/Models/Common/IStorageEntity.cs +++ b/src/Lumina.Contracts/Models/Common/IStorageEntity.cs @@ -1,7 +1,11 @@ -namespace Lumina.Application.Common.Models.Common; +#region ========================================================================= USING ===================================================================================== +using System; +#endregion + +namespace Lumina.Contracts.Models.Common; /// -/// Interface for storage DTOs, enforces Id. +/// Interface for storage models, enforces Id. /// public interface IStorageEntity { diff --git a/src/Lumina.Contracts/Models/Common/LanguageInfoModel.cs b/src/Lumina.Contracts/Models/Common/LanguageInfoModel.cs new file mode 100644 index 00000000..b3078fc5 --- /dev/null +++ b/src/Lumina.Contracts/Models/Common/LanguageInfoModel.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.Common; + +/// +/// Represents a request to get language information. +/// +/// Gets the ISO code of the language (e.g., "en" for English). +/// Gets the name of the language in English. +/// Gets the native name of the language (e.g., "Español" for Spanish). +[DebuggerDisplay("{LanguageName}")] +public record LanguageInfoModel( + string? LanguageCode, + string? LanguageName, + string? NativeName +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/Common/RatingModel.cs b/src/Lumina.Contracts/Models/Common/RatingModel.cs new file mode 100644 index 00000000..86398053 --- /dev/null +++ b/src/Lumina.Contracts/Models/Common/RatingModel.cs @@ -0,0 +1,18 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.Common; + +/// +/// Represents a rating. +/// +/// Gets the rating value. +/// Gets the maximum possible rating value. +/// Gets the number of votes that contributed to the rating. +[DebuggerDisplay("{Value}/{MaxValue}")] +public abstract record RatingModel( + decimal? Value, + decimal? MaxValue, + int? VoteCount +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/Common/ReleaseInfoModel.cs b/src/Lumina.Contracts/Models/Common/ReleaseInfoModel.cs new file mode 100644 index 00000000..1c8871b2 --- /dev/null +++ b/src/Lumina.Contracts/Models/Common/ReleaseInfoModel.cs @@ -0,0 +1,25 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.Common; + +/// +/// Represents a request to get release information. +/// +/// Gets the original release date of the content. +/// Gets the original release year of the content. +/// Gets the re-release date of the content, if applicable. +/// Gets the re-release year of the content, if applicable. +/// Gets the country where the content was released. +/// Gets the version or edition of the content's release. +[DebuggerDisplay("{OriginalReleaseDate}")] +public record ReleaseInfoModel( + DateOnly? OriginalReleaseDate, + int? OriginalReleaseYear, + DateOnly? ReReleaseDate, + int? ReReleaseYear, + string? ReleaseCountry, + string? ReleaseVersion +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/Common/TagModel.cs b/src/Lumina.Contracts/Models/Common/TagModel.cs new file mode 100644 index 00000000..85d90520 --- /dev/null +++ b/src/Lumina.Contracts/Models/Common/TagModel.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.Common; + +/// +/// Represents a request to get tag information. +/// +/// Gets the name of the tag. +[DebuggerDisplay("{Name}")] +public record TagModel( + string? Name +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/MediaContributors/MediaContributorModel.cs b/src/Lumina.Contracts/Models/MediaContributors/MediaContributorModel.cs new file mode 100644 index 00000000..3615ca58 --- /dev/null +++ b/src/Lumina.Contracts/Models/MediaContributors/MediaContributorModel.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.MediaContributors; + +/// +/// Represents a media contributor. +/// +/// Gets the name details of the media contributor, including display and legal names. +/// Gets the role details of the media contributor, including the role name and category. +[DebuggerDisplay("{Name} {Role}")] +public record MediaContributorModel( + MediaContributorNameModel? Name, + MediaContributorRoleModel? Role +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/MediaContributors/MediaContributorNameModel.cs b/src/Lumina.Contracts/Models/MediaContributors/MediaContributorNameModel.cs new file mode 100644 index 00000000..c7f77eaa --- /dev/null +++ b/src/Lumina.Contracts/Models/MediaContributors/MediaContributorNameModel.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.MediaContributors; + +/// +/// Represents a media contributor name. +/// +/// Gets the display name of the media contributor. +/// Gets the legal name of the media contributor. +[DebuggerDisplay("{DisplayName}")] +public record MediaContributorNameModel( + string? DisplayName, + string? LegalName +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/MediaContributors/MediaContributorRoleModel.cs b/src/Lumina.Contracts/Models/MediaContributors/MediaContributorRoleModel.cs new file mode 100644 index 00000000..d8693ae1 --- /dev/null +++ b/src/Lumina.Contracts/Models/MediaContributors/MediaContributorRoleModel.cs @@ -0,0 +1,16 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.MediaContributors; + +/// +/// Represents a media contributor role. +/// +/// Gets the name of the role assigned to the media contributor. +/// Gets the category of the role, which may describe the type or group of roles. +[DebuggerDisplay("{Name} {Category}")] +public record MediaContributorRoleModel( + string? Name, + string? Category +); \ No newline at end of file diff --git a/src/Lumina.Application/Common/Models/Books/BookDto.cs b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookModel.cs similarity index 90% rename from src/Lumina.Application/Common/Models/Books/BookDto.cs rename to src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookModel.cs index 5de751c7..2320c929 100644 --- a/src/Lumina.Application/Common/Models/Books/BookDto.cs +++ b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookModel.cs @@ -1,15 +1,22 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Models.Common; +using System; +using System.Collections.Generic; +using System.Diagnostics; #endregion -namespace Lumina.Application.Common.Models.Books; +namespace Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; /// /// Represents a book. /// -public class BookDto : IStorageEntity +[DebuggerDisplay("{Title}")] +public class BookModel : IStorageEntity { #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the Id of the media item. + /// public Guid Id { get; init; } /// @@ -91,12 +98,12 @@ public class BookDto : IStorageEntity /// /// Gets the list of tags associated with the media item. /// - public HashSet Tags { get; set; } = []; + public HashSet Tags { get; set; } = []; /// /// Gets the list of genres associated with the media item. /// - public HashSet Genres { get; set; } = []; + public HashSet Genres { get; set; } = []; /// /// Gets the publisher of the written content. @@ -176,17 +183,17 @@ public class BookDto : IStorageEntity /// /// Gets the list of ISBN (International Standard Book Number) of the book. /// - public List ISBNs { get; set; } = []; + public List ISBNs { get; set; } = []; /// /// Gets the list of media contributors (actors, directors, etc) starring in this book. /// - //public List ContributorIds { get; init; } = []; + //public List ContributorIds { get; init; } = []; /// /// Gets the list of ratings for this book. /// - public List Ratings { get; init; } = []; + public List Ratings { get; init; } = []; /// /// Gets the time and date when the entity was added. diff --git a/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookRatingModel.cs b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookRatingModel.cs new file mode 100644 index 00000000..4dadacfc --- /dev/null +++ b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookRatingModel.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.Common; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a book rating. +/// +/// Gets the rating value for the book. +/// Gets the maximum possible rating value for the book. +/// Gets the source of the book rating (e.g., a specific website or platform). +/// Gets the number of votes that contributed to the book rating. +[DebuggerDisplay("{Value}/{MaxValue}")] +public record BookRatingModel( + decimal? Value, + decimal? MaxValue, + BookRatingSource? Source, + int? VoteCount +) : RatingModel(Value, MaxValue, VoteCount); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookSeriesModel.cs b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookSeriesModel.cs new file mode 100644 index 00000000..a8b23fe0 --- /dev/null +++ b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/BookSeriesModel.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a request to get book series information. +/// +/// Gets the title of the book series. +[DebuggerDisplay("{Title}")] +public record BookSeriesModel( + string? Title +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/IsbnModel.cs b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/IsbnModel.cs new file mode 100644 index 00000000..fdb25a1e --- /dev/null +++ b/src/Lumina.Contracts/Models/WrittenContentLibrary/BookLibrary/IsbnModel.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Enums.BookLibrary; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a request to get ISBN information. +/// +/// Gets the ISBN value. +/// Gets the format of the ISBN (e.g., ISBN-10 or ISBN-13). +[DebuggerDisplay("{Value} ({Format})")] +public record IsbnModel( + string? Value, + IsbnFormat? Format +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Models/WrittenContentLibrary/WrittenContentMetadataModel.cs b/src/Lumina.Contracts/Models/WrittenContentLibrary/WrittenContentMetadataModel.cs new file mode 100644 index 00000000..5f5b4aaf --- /dev/null +++ b/src/Lumina.Contracts/Models/WrittenContentLibrary/WrittenContentMetadataModel.cs @@ -0,0 +1,34 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Models.Common; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Models.WrittenContentLibrary; + +/// +/// Represents written content metadata. +/// +/// Gets the title of the written content. +/// Gets the original title of the written content, if different from the current title. +/// Gets a brief description or summary of the written content. +/// Gets the release information, including release date and other relevant details. +/// Gets the list of genres associated with the written content. +/// Gets the list of tags that further describe or categorize the written content. +/// Gets the language in which the written content is written. +/// Gets the original language of the written content, if it has been translated. +/// Gets the name of the publisher of the written content. +/// Gets the number of pages in the written content. +[DebuggerDisplay("{Title}")] +public record WrittenContentMetadataModel( + string? Title, + string? OriginalTitle, + string? Description, + ReleaseInfoModel? ReleaseInfo, + List? Genres, + List? Tags, + LanguageInfoModel? Language, + LanguageInfoModel? OriginalLanguage, + string? Publisher, + int? PageCount +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Requests/WrittenContentLibrary/BookLibrary/AddBookRequest.cs b/src/Lumina.Contracts/Requests/WrittenContentLibrary/BookLibrary/AddBookRequest.cs new file mode 100644 index 00000000..806768e3 --- /dev/null +++ b/src/Lumina.Contracts/Requests/WrittenContentLibrary/BookLibrary/AddBookRequest.cs @@ -0,0 +1,49 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.MediaContributors; +using Lumina.Contracts.Models.WrittenContentLibrary; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; +using System.Collections.Generic; +#endregion + +namespace Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a request to add a book. +/// +/// Written content metadata of the book. +/// The format of the book (e.g., Hardcover, Paperback), if applicable. +/// The edition of the book, if applicable. +/// The volume or book number in the series, if applicable. +/// The series name, if the book is part of a series. +/// The ASIN (Amazon Standard Identification Number) of the book, if applicable. +/// The Goodreads ID of the book, if applicable. +/// The Library of Congress Control Number (LCCN) of the book, if applicable. +/// The OCLC Number (WorldCat identifier) of the book, if applicable. +/// The Open Library ID of the book, if applicable. +/// The LibraryThing ID of the book, if applicable. +/// The Google Books ID of the book, if applicable. +/// The Barnes & Noble ID of the book, if applicable. +/// The Apple Books ID of the book, if applicable. +/// The list of ISBN (International Standard Book Number) of the book. +/// The list of media contributors (actors, directors, etc) starring in this book. +/// The list of ratings for this book. +public record AddBookRequest( + WrittenContentMetadataModel? Metadata, + BookFormat? Format, + string? Edition, + int? VolumeNumber, + BookSeriesModel? Series, + string? ASIN, + string? GoodreadsId, + string? LCCN, + string? OCLCNumber, + string? OpenLibraryId, + string? LibraryThingId, + string? GoogleBooksId, + string? BarnesAndNobleId, + string? AppleBooksId, + List? ISBNs, + List? Contributors, + List? Ratings +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/FileSystemTreeNodeResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/FileSystemTreeNodeResponse.cs new file mode 100644 index 00000000..698a3b6a --- /dev/null +++ b/src/Lumina.Contracts/Responses/FileManagement/FileSystemTreeNodeResponse.cs @@ -0,0 +1,46 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Enums.FileSystem; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.Responses.FileManagement; + +/// +/// Generic file system node. +/// +[DebuggerDisplay("{Path}")] +public class FileSystemTreeNodeResponse +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the full path of the file or directory. + /// + public string Path { get; set; } = null!; + + /// + /// Gets or sets the name of the file or directory. + /// + public string Name { get; set; } = null!; + + /// + /// Gets or sets the type of the item, indicating whether it is a file, directory, or drive. + /// + public FileSystemItemType ItemType { get; set; } + + /// + /// Gets or sets a value indicating whether the node is expanded. + /// + public bool IsExpanded { get; set; } + + /// + /// Gets or sets a value indicating whether the child nodes have been loaded. + /// + public bool ChildrenLoaded { get; set; } + + /// + /// Gets or sets the list of child nodes. + /// + public List Children { get; set; } = []; + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs new file mode 100644 index 00000000..0e0ca42e --- /dev/null +++ b/src/Lumina.Contracts/Responses/FileManagement/FileSystemTypeResponse.cs @@ -0,0 +1,13 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Enums.FileSystem; +#endregion + +namespace Lumina.Contracts.Responses.FileManagement; + +/// +/// Represents a response containing the file system platform type. +/// +/// The returned file system platform type. +public record FileSystemTypeResponse( + PlatformType PlatformType +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs new file mode 100644 index 00000000..58e5827d --- /dev/null +++ b/src/Lumina.Contracts/Responses/FileManagement/PathSegmentResponse.cs @@ -0,0 +1,9 @@ +namespace Lumina.Contracts.Responses.FileManagement; + +/// +/// Represents a response containing a file system path. +/// +/// The returned path. +public record PathSegmentResponse( + string Path +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs new file mode 100644 index 00000000..f60fac5a --- /dev/null +++ b/src/Lumina.Contracts/Responses/FileManagement/PathSeparatorResponse.cs @@ -0,0 +1,9 @@ +namespace Lumina.Contracts.Responses.FileManagement; + +/// +/// Represents a response to the inquiry about the system's path separator. +/// +/// The system's path separator. +public record PathSeparatorResponse( + string Separator +); \ No newline at end of file diff --git a/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs b/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs new file mode 100644 index 00000000..49bfdc9d --- /dev/null +++ b/src/Lumina.Contracts/Responses/FileManagement/SplitPathResponse.cs @@ -0,0 +1,9 @@ +namespace Lumina.Contracts.Responses.FileManagement; + +/// +/// Represents a response containing the result of splitting a file system path. +/// +/// The returned path segments. +public record SplitPathResponse( + string[] PathSegments +); \ No newline at end of file diff --git a/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs index d905f636..8e8ea41a 100644 --- a/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/BookConfiguration.cs @@ -1,23 +1,24 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System.Collections.Generic; #endregion namespace Lumina.DataAccess.Common.Configuration; /// -/// Configures the entity mapping for the entity. +/// Configures the entity mapping for the entity. /// -public class BookConfiguration : IEntityTypeConfiguration +public class BookConfiguration : IEntityTypeConfiguration { #region ===================================================================== METHODS =================================================================================== /// - /// Configures the entity. + /// Configures the entity. /// /// The builder to be used to configure the entity. - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder.ToTable("Books"); builder.HasKey(book => book.Id); @@ -46,8 +47,8 @@ public class BookConfiguration : IEntityTypeConfiguration .WithMany() .UsingEntity>( "BookTags", - j => j.HasOne().WithMany().HasForeignKey("TagId"), - j => j.HasOne().WithMany().HasForeignKey("BookId"), + j => j.HasOne().WithMany().HasForeignKey("TagId"), + j => j.HasOne().WithMany().HasForeignKey("BookId"), j => { j.HasKey("BookId", "TagId"); @@ -58,8 +59,8 @@ public class BookConfiguration : IEntityTypeConfiguration .WithMany() .UsingEntity>( "BookGenres", - j => j.HasOne().WithMany().HasForeignKey("GenreId"), - j => j.HasOne().WithMany().HasForeignKey("BookId"), + j => j.HasOne().WithMany().HasForeignKey("GenreId"), + j => j.HasOne().WithMany().HasForeignKey("BookId"), j => { j.HasKey("BookId", "GenreId"); @@ -83,12 +84,12 @@ public class BookConfiguration : IEntityTypeConfiguration builder.Property(book => book.Created).HasColumnOrder(30); builder.Property(book => book.Updated).HasColumnOrder(31); - //builder.HasMany() + //builder.HasMany() //.WithMany() //.UsingEntity>( // "BookContributors", - // j => j.HasOne().WithMany().HasForeignKey("ContributorId"), - // j => j.HasOne().WithMany().HasForeignKey("BookId"), + // j => j.HasOne().WithMany().HasForeignKey("ContributorId"), + // j => j.HasOne().WithMany().HasForeignKey("BookId"), // j => // { // j.HasKey("BookId", "ContributorId"); @@ -150,9 +151,9 @@ public class BookConfiguration : IEntityTypeConfiguration #endregion } -//public class ContributorConfiguration : IEntityTypeConfiguration +//public class ContributorConfiguration : IEntityTypeConfiguration //{ -// public void Configure(EntityTypeBuilder builder) +// public void Configure(EntityTypeBuilder builder) // { // builder.ToTable("Contributors"); // builder.HasKey(c => c.Id); diff --git a/src/Lumina.DataAccess/Common/Configuration/GenreConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/GenreConfiguration.cs index 707ba145..0e2f1158 100644 --- a/src/Lumina.DataAccess/Common/Configuration/GenreConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/GenreConfiguration.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Models.Common; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; #endregion @@ -7,16 +7,16 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Lumina.DataAccess.Common.Configuration; /// -/// Configures the entity mapping for the entity. +/// Configures the entity mapping for the entity. /// -public class GenreConfiguration : IEntityTypeConfiguration +public class GenreConfiguration : IEntityTypeConfiguration { #region ===================================================================== METHODS =================================================================================== /// - /// Configures the entity. + /// Configures the entity. /// /// The builder to be used to configure the entity. - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder.ToTable("Genres"); builder.HasKey(genre => genre.Name); diff --git a/src/Lumina.DataAccess/Common/Configuration/TagConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/TagConfiguration.cs index 96c9606c..2cfb2b1b 100644 --- a/src/Lumina.DataAccess/Common/Configuration/TagConfiguration.cs +++ b/src/Lumina.DataAccess/Common/Configuration/TagConfiguration.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Models.Common; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; #endregion @@ -7,16 +7,16 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Lumina.DataAccess.Common.Configuration; /// -/// Configures the entity mapping for the entity. +/// Configures the entity mapping for the entity. /// -public class TagConfiguration : IEntityTypeConfiguration +public class TagConfiguration : IEntityTypeConfiguration { #region ===================================================================== METHODS =================================================================================== /// - /// Configures the entity. + /// Configures the entity. /// /// The builder to be used to configure the entity. - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder.ToTable("Tags"); builder.HasKey(tag => tag.Name); diff --git a/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs b/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs index 8b26ba7f..8596916f 100644 --- a/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs +++ b/src/Lumina.DataAccess/Common/DependencyInjection/DataAccessLayerServices.cs @@ -1,11 +1,15 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.DataAccess.Core.UoW; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.EntityFrameworkCore; -using System.Reflection; using Lumina.Application.Common.DataAccess.Repositories.Common.Base; -using Lumina.DataAccess.Core.Repositories.Common.Factory; using Lumina.Application.Common.DataAccess.UoW; +using Lumina.DataAccess.Core.Repositories.Common.Factory; +using Lumina.DataAccess.Core.UoW; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; #endregion namespace Lumina.DataAccess.Common.DependencyInjection; diff --git a/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs b/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs index 8c89d1b1..299e4588 100644 --- a/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs +++ b/src/Lumina.DataAccess/Common/Migrations/20240826201057_InitialMigration.Designer.cs @@ -50,7 +50,7 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("BookTags", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b => { b.Property("Id") .HasColumnType("TEXT") @@ -197,7 +197,7 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("Books", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreModel", b => { b.Property("Name") .HasMaxLength(50) @@ -208,7 +208,7 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("Genres", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagModel", b => { b.Property("Name") .HasMaxLength(50) @@ -221,13 +221,13 @@ namespace Lumina.DataAccess.Common.Migrations modelBuilder.Entity("BookGenres", b => { - b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null) + b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null) .WithMany() .HasForeignKey("BookId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null) + b.HasOne("Lumina.Application.Common.Models.Common.GenreModel", null) .WithMany() .HasForeignKey("GenreId") .OnDelete(DeleteBehavior.Cascade) @@ -236,22 +236,22 @@ namespace Lumina.DataAccess.Common.Migrations modelBuilder.Entity("BookTags", b => { - b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null) + b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null) .WithMany() .HasForeignKey("BookId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null) + b.HasOne("Lumina.Application.Common.Models.Common.TagModel", null) .WithMany() .HasForeignKey("TagId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b => { - b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 => + b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingModel", "Ratings", b1 => { b1.Property("Id") .ValueGeneratedOnAdd() @@ -284,7 +284,7 @@ namespace Lumina.DataAccess.Common.Migrations .HasForeignKey("BookId"); }); - b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 => + b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnModel", "ISBNs", b1 => { b1.Property("Id") .ValueGeneratedOnAdd() diff --git a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs index 9068a83e..1c5bbaa3 100644 --- a/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs +++ b/src/Lumina.DataAccess/Common/Migrations/LuminaDbContextModelSnapshot.cs @@ -47,7 +47,7 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("BookTags", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b => { b.Property("Id") .HasColumnType("TEXT") @@ -194,7 +194,7 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("Books", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreModel", b => { b.Property("Name") .HasMaxLength(50) @@ -205,7 +205,7 @@ namespace Lumina.DataAccess.Common.Migrations b.ToTable("Genres", (string)null); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagModel", b => { b.Property("Name") .HasMaxLength(50) @@ -218,13 +218,13 @@ namespace Lumina.DataAccess.Common.Migrations modelBuilder.Entity("BookGenres", b => { - b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null) + b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null) .WithMany() .HasForeignKey("BookId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null) + b.HasOne("Lumina.Application.Common.Models.Common.GenreModel", null) .WithMany() .HasForeignKey("GenreId") .OnDelete(DeleteBehavior.Cascade) @@ -233,22 +233,22 @@ namespace Lumina.DataAccess.Common.Migrations modelBuilder.Entity("BookTags", b => { - b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null) + b.HasOne("Lumina.Application.Common.Models.Books.BookModel", null) .WithMany() .HasForeignKey("BookId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null) + b.HasOne("Lumina.Application.Common.Models.Common.TagModel", null) .WithMany() .HasForeignKey("TagId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); - modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b => + modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookModel", b => { - b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 => + b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingModel", "Ratings", b1 => { b1.Property("Id") .ValueGeneratedOnAdd() @@ -281,7 +281,7 @@ namespace Lumina.DataAccess.Common.Migrations .HasForeignKey("BookId"); }); - b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 => + b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnModel", "ISBNs", b1 => { b1.Property("Id") .ValueGeneratedOnAdd() diff --git a/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs b/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs index 3d29ab6b..fd4fc02e 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Books/BookRepository.cs @@ -1,11 +1,15 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Application.Common.DataAccess.Repositories.Books; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; using Lumina.DataAccess.Core.UoW; using Lumina.Domain.Common.Errors; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.DataAccess.Core.Repositories.Books; @@ -36,25 +40,25 @@ internal sealed class BookRepository : IBookRepository /// /// The book to add. /// Cancellation token that can be used to stop the execution. - /// An representing either a successfull operation, or an error. - public async Task> InsertAsync(BookDto book, CancellationToken cancellationToken) + /// An representing either a successfull operation, or an error. + public async Task> InsertAsync(BookModel book, CancellationToken cancellationToken) { var jobExists = await _luminaDbContext.Books.AnyAsync(_book => _book.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false); if (jobExists) return Errors.WrittenContent.BookAlreadyExists; // fetch existing tags and genres - var existingTags = await _luminaDbContext.Set() + var existingTags = await _luminaDbContext.Set() .Where(t => book.Tags.Select(bt => bt.Name).Contains(t.Name)) - .ToListAsync(cancellationToken); + .ToListAsync(cancellationToken).ConfigureAwait(false); - var existingGenres = await _luminaDbContext.Set() + var existingGenres = await _luminaDbContext.Set() .Where(g => book.Genres.Select(bg => bg.Name).Contains(g.Name)) - .ToListAsync(cancellationToken); + .ToListAsync(cancellationToken).ConfigureAwait(false); // replace tags and genres in the book with existing ones - book.Tags = new HashSet(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag)); - book.Genres = new HashSet(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre)); + book.Tags = new HashSet(book.Tags.Select(tag => existingTags.FirstOrDefault(existingTag => existingTag.Name == tag.Name) ?? tag)); + book.Genres = new HashSet(book.Genres.Select(genre => existingGenres.FirstOrDefault(existingGenre => existingGenre.Name == genre.Name) ?? genre)); _luminaDbContext.Books.Add(book); return Result.Created; @@ -64,8 +68,8 @@ internal sealed class BookRepository : IBookRepository /// Gets all books. /// /// Cancellation token that can be used to stop the execution. - /// An containing either a collection of , or an error. - public async Task>> GetAllAsync(CancellationToken cancellationToken) + /// An containing either a collection of , or an error. + public async Task>> GetAllAsync(CancellationToken cancellationToken) { return await _luminaDbContext.Books .Include(book => book.Tags) diff --git a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs index a6e6a762..5903316c 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/IRepositoryFactory.cs @@ -1,7 +1,7 @@ namespace Lumina.DataAccess.Core.Repositories.Common.Factory; /// -/// Repositories abstract factory. +/// Interface for the repositories factory. /// public interface IRepositoryFactory { diff --git a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs index 6e0a1b4f..c9760531 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryDictionary.cs @@ -1,5 +1,8 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.DataAccess.Repositories.Common.Base; +using System; +using System.Collections.Generic; +using System.Linq; #endregion namespace Lumina.DataAccess.Core.Repositories.Common.Factory; @@ -14,6 +17,9 @@ public class RepositoryDictionary #endregion #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the number of added repositories. + /// public int Count { get { return _container.Count; } } #endregion diff --git a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs index 243eddfa..cf257b41 100644 --- a/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs +++ b/src/Lumina.DataAccess/Core/Repositories/Common/Factory/RepositoryFactory.cs @@ -1,11 +1,12 @@ #region ========================================================================= USING ===================================================================================== using Microsoft.Extensions.DependencyInjection; +using System; #endregion namespace Lumina.DataAccess.Core.Repositories.Common.Factory; /// -/// Concrete implementation for the repositories abstract factory. +/// Concrete implementation for the repositories factory. /// public class RepositoryFactory : IRepositoryFactory { @@ -15,7 +16,7 @@ public class RepositoryFactory : IRepositoryFactory #region ====================================================================== CTOR ===================================================================================== /// - /// Overload C-tor. + /// Initializes a new instance of the class. /// /// The service provider. public RepositoryFactory(IServiceProvider serviceProvider) diff --git a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs index 197ea781..be38c9c4 100644 --- a/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs +++ b/src/Lumina.DataAccess/Core/UoW/LuminaDbContext.cs @@ -1,8 +1,11 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; using Lumina.Domain.Common.Events; using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; #endregion namespace Lumina.DataAccess.Core.UoW; @@ -15,12 +18,12 @@ namespace Lumina.DataAccess.Core.UoW; public class LuminaDbContext : DbContext { #region ==================================================================== PROPERTIES ================================================================================= - public virtual DbSet Books { get; set; } = null!; + public virtual DbSet Books { get; set; } = null!; #endregion #region ====================================================================== CTOR ===================================================================================== /// - /// Overload C-tor. + /// Initializes a new instance of the class. /// /// The options for configuring the database context. public LuminaDbContext(DbContextOptions options) : base(options) diff --git a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs index d6d189f2..57aa02e3 100644 --- a/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs +++ b/src/Lumina.DataAccess/Core/UoW/UnitOfWork.cs @@ -2,7 +2,12 @@ using Lumina.Application.Common.DataAccess.Repositories.Common.Base; using Lumina.Application.Common.DataAccess.UoW; using Lumina.DataAccess.Core.Repositories.Common.Factory; +using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.DataAccess.Core.UoW; @@ -18,14 +23,17 @@ public class UnitOfWork : IUnitOfWork #endregion #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the collection of available repositories. + /// internal RepositoryDictionary Repositories { get; private set; } = new RepositoryDictionary(); #endregion #region ====================================================================== CTOR ===================================================================================== /// - /// Overload C-tor. + /// Initializes a new instance of the class. /// - /// The abstract factory used to generate repositories. + /// The factory used to generate repositories. /// Injected Entity Framework DbContext. public UnitOfWork(IRepositoryFactory repositoryFactory, LuminaDbContext luminaDbContext) { @@ -95,7 +103,7 @@ public class UnitOfWork : IUnitOfWork /// Cancellation token that can be used to stop the execution. public async Task SaveChangesAsync(CancellationToken cancellationToken) { - await _luminaDbContext.SaveChangesAsync(cancellationToken); + await _luminaDbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } /// diff --git a/src/Lumina.DataAccess/Lumina.DataAccess.csproj b/src/Lumina.DataAccess/Lumina.DataAccess.csproj index 737414e1..0ebac19e 100644 --- a/src/Lumina.DataAccess/Lumina.DataAccess.csproj +++ b/src/Lumina.DataAccess/Lumina.DataAccess.csproj @@ -2,9 +2,9 @@ net8.0 - enable + disable enable - ..\..\bin\ + $(SolutionDir)..\bin\server\ false diff --git a/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs b/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs index a2843039..4265cbd7 100644 --- a/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs +++ b/src/Lumina.Domain/Common/DependencyInjection/DomainLayerServices.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path; @@ -22,6 +23,7 @@ public static class DomainLayerServices /// The updated . public static IServiceCollection AddDomainLayerServices(this IServiceCollection services) { + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs b/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs index 0a567a26..40ce7831 100644 --- a/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs +++ b/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs @@ -12,22 +12,23 @@ public static partial class Errors public static class FileManagement { #region ==================================================================== PROPERTIES ================================================================================= + public static Error ParentNodeCannotBeNull => Error.Failure(nameof(ParentNodeCannotBeNull)); public static Error FileCopyError => Error.Failure(nameof(FileCopyError)); public static Error FileMoveError => Error.Failure(nameof(FileMoveError)); public static Error DirectoryCopyError => Error.Failure(nameof(DirectoryCopyError)); public static Error DirectoryMoveError => Error.Failure(nameof(DirectoryMoveError)); - public static Error FileNotFoundError => Error.NotFound(nameof(FileNotFoundError)); - public static Error InvalidPathError => Error.Validation(nameof(InvalidPathError)); + public static Error FileNotFound => Error.NotFound(nameof(FileNotFound)); + public static Error InvalidPath => Error.Validation(nameof(InvalidPath)); public static Error PathCannotBeEmpty => Error.Validation(nameof(PathCannotBeEmpty)); public static Error ExtensionCannotBeEmpty => Error.Validation(nameof(ExtensionCannotBeEmpty)); public static Error StreamIdCannotBeEmpty => Error.Validation(nameof(StreamIdCannotBeEmpty)); public static Error CodecCannotBeEmpty => Error.Validation(nameof(CodecCannotBeEmpty)); public static Error BitrateMustBeAPositiveNumber => Error.Validation(nameof(BitrateMustBeAPositiveNumber)); - public static Error CannotNavigateUpError => Error.Failure(nameof(CannotNavigateUpError)); - public static Error NameCannotBeEmptyError => Error.Validation(nameof(NameCannotBeEmptyError)); - public static Error FileAlreadyExistsError => Error.Conflict(nameof(FileAlreadyExistsError)); - public static Error DirectoryNotFoundError => Error.NotFound(nameof(DirectoryNotFoundError)); - public static Error DirectoryAlreadyExistsError => Error.Conflict(nameof(DirectoryAlreadyExistsError)); + public static Error CannotNavigateUp => Error.Failure(nameof(CannotNavigateUp)); + public static Error NameCannotBeEmpty => Error.Validation(nameof(NameCannotBeEmpty)); + public static Error FileAlreadyExists => Error.Conflict(nameof(FileAlreadyExists)); + public static Error DirectoryNotFound => Error.NotFound(nameof(DirectoryNotFound)); + public static Error DirectoryAlreadyExists => Error.Conflict(nameof(DirectoryAlreadyExists)); #endregion } } \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Events/IDomainEvent.cs b/src/Lumina.Domain/Common/Events/IDomainEvent.cs index d07ba628..01947f30 100644 --- a/src/Lumina.Domain/Common/Events/IDomainEvent.cs +++ b/src/Lumina.Domain/Common/Events/IDomainEvent.cs @@ -1,4 +1,8 @@ -namespace Lumina.Domain.Common.Events; +#region ========================================================================= USING ===================================================================================== +using System; +#endregion + +namespace Lumina.Domain.Common.Events; /// /// Interface defining a domain event. @@ -6,7 +10,14 @@ public interface IDomainEvent { #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the id of the domain event. + /// Guid Id { get; } + + /// + /// Gets the date and time when the domain event occurred. + /// DateTime OccurredOn { get; } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Models/Core/Entity.cs b/src/Lumina.Domain/Common/Models/Core/Entity.cs index dd06b854..f473976d 100644 --- a/src/Lumina.Domain/Common/Models/Core/Entity.cs +++ b/src/Lumina.Domain/Common/Models/Core/Entity.cs @@ -1,4 +1,8 @@ -namespace Lumina.Domain.Common.Models.Core; +#region ========================================================================= USING ===================================================================================== +using System; +#endregion + +namespace Lumina.Domain.Common.Models.Core; /// /// Base class for all domain Entities. diff --git a/src/Lumina.Domain/Common/Models/Core/EntityId.cs b/src/Lumina.Domain/Common/Models/Core/EntityId.cs index 65002631..1e64c714 100644 --- a/src/Lumina.Domain/Common/Models/Core/EntityId.cs +++ b/src/Lumina.Domain/Common/Models/Core/EntityId.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -12,12 +13,15 @@ namespace Lumina.Domain.Common.Models.Core; public abstract class EntityId : ValueObject { #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the value representing the entity identifier. + /// public TId Value { get; } #endregion #region ====================================================================== CTOR ===================================================================================== /// - /// Overload C-tor. + /// Initializes a new instance of the class. /// /// The value representing this object. protected EntityId(TId value) @@ -27,7 +31,7 @@ public abstract class EntityId : ValueObject #pragma warning disable CS8618 /// - /// Default C-tor. + /// Initializes a new instance of the class. /// protected EntityId() { diff --git a/src/Lumina.Domain/Common/Models/Core/ValueObject.cs b/src/Lumina.Domain/Common/Models/Core/ValueObject.cs index 05faef4c..b3b3fdd2 100644 --- a/src/Lumina.Domain/Common/Models/Core/ValueObject.cs +++ b/src/Lumina.Domain/Common/Models/Core/ValueObject.cs @@ -1,9 +1,14 @@ -namespace Lumina.Domain.Common.Models.Core; +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +using System.Linq; +#endregion + +namespace Lumina.Domain.Common.Models.Core; /// /// Base class for all domain Value Objects. /// -/// The type representing the unique identifier for the Entity. It should be a non-nullable type. public abstract class ValueObject : IEquatable { #region ===================================================================== METHODS =================================================================================== diff --git a/src/Lumina.Domain/Common/Primitives/Optional.cs b/src/Lumina.Domain/Common/Primitives/Optional.cs index d92fd2d7..c0c04098 100644 --- a/src/Lumina.Domain/Common/Primitives/Optional.cs +++ b/src/Lumina.Domain/Common/Primitives/Optional.cs @@ -4,11 +4,11 @@ namespace Lumina.Domain.Common.Primitives; /// Primitive struct for explicitly handling cases when a value might be unknown or not applicable, /// distinguishing between "not set" and "intentionally empty". /// -/// The type of the value represented by this structure. -public readonly struct Optional +/// The type of the value represented by this structure. +public readonly struct Optional { #region ================================================================== FIELD MEMBERS ================================================================================ - private readonly T? _value; + private readonly TValue? _value; #endregion #region ==================================================================== PROPERTIES ================================================================================= @@ -20,7 +20,7 @@ public readonly struct Optional /// /// Gets the value represented by this structure. /// - public T Value + public TValue Value { get { @@ -31,11 +31,11 @@ public readonly struct Optional #region ====================================================================== CTOR ===================================================================================== /// - /// Initializes a new instance of the structure. + /// Initializes a new instance of the structure. /// /// The value represented by this structure. /// if is not , otherwise. - private Optional(T? value, bool hasValue) + private Optional(TValue? value, bool hasValue) { _value = value; HasValue = hasValue; @@ -44,50 +44,50 @@ public readonly struct Optional #region ===================================================================== METHODS =================================================================================== /// - /// Custom implementation operator for converting to an . + /// Custom implementation operator for converting to an . /// /// The value to be converted. - public static implicit operator Optional(T value) + public static implicit operator Optional(TValue value) { return Some(value); } /// - /// Creates an with a value. + /// Creates an with a value. /// - /// The value to wrap in the . - /// An containing the specified value. - public static Optional Some(T value) + /// The value to wrap in the . + /// An containing the specified value. + public static Optional Some(TValue value) { - return new Optional(value, true); + return new Optional(value, true); } /// - /// Creates an with no value. + /// Creates an with no value. /// - /// An empty . - public static Optional None() + /// An empty . + public static Optional None() { return new(default, false); } /// - /// Creates an from a nullable reference type. + /// Creates an from a nullable reference type. /// /// The nullable value to convert. - /// An representing the nullable value. - public static Optional FromNullable(T? value) + /// An representing the nullable value. + public static Optional FromNullable(TValue? value) { return value is null ? None() : Some(value); } /// - /// Creates an from a nullable value type. + /// Creates an from a nullable value type. /// - /// The underlying value type. + /// The underlying value type. /// The nullable value to convert. - /// An representing the nullable value. - public static Optional FromNullable(TValue? value) where TValue : struct, T + /// An representing the nullable value. + public static Optional FromNullable(TNullableValue? value) where TNullableValue : struct, TValue { return value.HasValue ? Some(value.Value) : None(); } diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs index b8a7fdab..d9a90a1b 100644 --- a/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs @@ -1,7 +1,9 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.Primitives; +using System; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Common.ValueObjects.Metadata; diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs index c34b1b64..10138b69 100644 --- a/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Domain.Common.Models.Core; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -36,7 +37,7 @@ public class Genre : ValueObject /// /// The value of the genre. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create(string name) { diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs index cdbf9334..2218744f 100644 --- a/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs @@ -2,6 +2,7 @@ using ErrorOr; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.Primitives; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -53,7 +54,7 @@ public class LanguageInfo : ValueObject /// The full name of the language in English. /// The optional native name of the language. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create(string languageCode, string languageName, Optional nativeName) { diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs index fe1f463c..30e17d37 100644 --- a/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs @@ -2,6 +2,8 @@ using ErrorOr; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.Primitives; +using System; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -84,7 +86,7 @@ public class ReleaseInfo : ValueObject /// The optional country or region of release. /// The optional release version or edition. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( Optional originalReleaseDate, diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs index 7d54443d..abf923c5 100644 --- a/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Domain.Common.Models.Core; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -36,7 +37,7 @@ public class Tag : ValueObject /// /// The value of the tag. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create(string name) { diff --git a/src/Lumina.Domain/Core/Aggregates/AudioLibrary/AudioLibraryAggregate/ValueObjects/AudioMetadata.cs b/src/Lumina.Domain/Core/Aggregates/AudioLibrary/AudioLibraryAggregate/ValueObjects/AudioMetadata.cs index 6ec66e9f..4c108c84 100644 --- a/src/Lumina.Domain/Core/Aggregates/AudioLibrary/AudioLibraryAggregate/ValueObjects/AudioMetadata.cs +++ b/src/Lumina.Domain/Core/Aggregates/AudioLibrary/AudioLibraryAggregate/ValueObjects/AudioMetadata.cs @@ -2,6 +2,7 @@ using ErrorOr; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Common.ValueObjects.Metadata; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -106,7 +107,7 @@ public class AudioMetadata : BaseMetadata /// The genres of the audio. /// The tags associated with the audio. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( string title, diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/Directory.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/Directory.cs index b56211f3..e35e5721 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/Directory.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/Directory.cs @@ -1,4 +1,7 @@ #region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; @@ -11,13 +14,30 @@ namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.E /// Entity representing a file system directory. /// [DebuggerDisplay("{Id.Path}")] -public class Directory : FileSystemItem +public sealed class Directory : FileSystemItem { + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly List _items = []; + #endregion + #region ==================================================================== PROPERTIES ================================================================================= /// - /// Gets or sets the collection of file system items that are children to the current directory entity. + /// Gets or sets the creation date of the file system item. Can be optional if the information is not available. /// - public List Items { get; private set; } + public Optional DateCreated { get; private set; } + + /// + /// Gets or sets the last modification date of the file system item. Can be optional if the information is not available. + /// + public Optional DateModified { get; private set; } + + /// + /// Gets the collection of file system items that are children to the current directory entity. + /// + public IReadOnlyCollection Items + { + get { return _items.AsReadOnly(); } + } #endregion #region ====================================================================== CTOR ===================================================================================== @@ -26,31 +46,108 @@ public class Directory : FileSystemItem /// /// The unique identifier of the directory in the file system path. /// The name of the directory. - /// The date and time the directory was created. Can be if unknown. - /// The date and time the directory was last modified. Can be if unknown. - public Directory(FileSystemPathId id, string name, DateTime? dateCreated, DateTime? dateModified) : base(id, name, dateCreated, dateModified) + /// The date and time the directory was created. Can be optional if unknown. + /// The date and time the directory was last modified. Can be optional if unknown. + private Directory(FileSystemPathId id, string name, Optional dateCreated, Optional dateModified) : base(id, name, FileSystemItemType.Directory) { - Items = []; + DateCreated = dateCreated; + DateModified = dateModified; } #endregion #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of the class. + /// + /// The name of the directory. + /// The date and time the directory was created. Can be optional if unknown. + /// The date and time the directory was last modified. Can be optional if unknown. + /// The status of the file system item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + string path, + string name, + Optional dateCreated, + Optional dateModified, + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + // TODO: enforce invariants + ErrorOr createPathResult = FileSystemPathId.Create(path); + if (createPathResult.IsError) + return createPathResult.Errors; + Directory newDirectory = new Directory( + createPathResult.Value, + name, + dateCreated, + dateModified); + ErrorOr setStatusResult = newDirectory.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newDirectory; + } + + /// + /// Creates a new instance of the class. + /// + /// The name of the directory. + /// The date and time the directory was created. Can be optional if unknown. + /// The date and time the directory was last modified. Can be optional if unknown. + /// The status of the file system item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + FileSystemPathId id, + string name, + Optional dateCreated, + Optional dateModified, + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + // TODO: enforce invariants + Directory newDirectory = new Directory( + id, + name, + dateCreated, + dateModified); + ErrorOr setStatusResult = newDirectory.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newDirectory; + } + + /// + /// Updates the last modified date of the file system item. + /// + /// The new date and time of last modification. + /// An representing either a successfull operation, or an error. + public ErrorOr UpdateLastModified(DateTime date) + { + DateModified = date; + return Result.Updated; + } + /// /// Adds a file system item to the directory. /// /// The file system item to add. - public void AddItem(FileSystemItem item) + /// An representing either a successfull operation, or an error. + public ErrorOr AddItem(FileSystemItem item) { - Items.Add(item); + _items.Add(item); + return Result.Updated; } /// /// Removes a file system item from the directory. /// /// The file system item to remove. - public void RemoveItem(FileSystemItem item) + /// An representing either a successfull operation, or an error. + public ErrorOr RemoveItem(FileSystemItem item) { - Items.Remove(item); + _items.Remove(item); + return Result.Updated; } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/File.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/File.cs index 6f78e10b..ab230f43 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/File.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/File.cs @@ -1,4 +1,8 @@ #region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Diagnostics; @@ -10,9 +14,19 @@ namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.E /// Entity representing a file system file. /// [DebuggerDisplay("{Id.Path}")] -public class File : FileSystemItem +public sealed class File : FileSystemItem { #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the creation date of the file system item. Can be optional if the information is not available. + /// + public Optional DateCreated { get; private set; } + + /// + /// Gets or sets the last modification date of the file system item. Can be optional if the information is not available. + /// + public Optional DateModified { get; private set; } + /// /// Gets or sets the size in bytes of the current file entity. /// @@ -25,23 +39,119 @@ public class File : FileSystemItem /// /// The unique identifier of the file in the file system path. /// The name of the file. - /// The date and time the file was created. Can be if unknown. - /// The date and time the file was last modified. Can be if unknown. + /// The date and time the file was created. Can be optional if unknown. + /// The date and time the file was last modified. Can be optional if unknown. /// The size of the file in bytes. - public File(FileSystemPathId id, string name, DateTime? dateCreated, DateTime? dateModified, long size) : base(id, name, dateCreated, dateModified) + private File(FileSystemPathId id, string name, Optional dateCreated, Optional dateModified, long size) : base(id, name, FileSystemItemType.File) { + DateCreated = dateCreated; + DateModified = dateModified; Size = size; } #endregion #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of the class. + /// + /// The name of the file. + /// The date and time the file was created. Can be optional if unknown. + /// The date and time the file was last modified. Can be optional if unknown. + /// The size of the file in bytes. + /// The status of the file system item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + string path, + string name, + Optional dateCreated, + Optional dateModified, + long size, + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + // TODO: enforce invariants + ErrorOr createPathResult = FileSystemPathId.Create(path); + if (createPathResult.IsError) + return createPathResult.Errors; + File newFile = new File( + createPathResult.Value, + name, + dateCreated, + dateModified, + size); + ErrorOr setStatusResult = newFile.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newFile; + } + + /// + /// Creates a new instance of the class. + /// + /// The unique identifier of the file in the file system path. + /// The name of the file. + /// The date and time the file was created. Can be optional if unknown. + /// The date and time the file was last modified. Can be optional if unknown. + /// The size of the file in bytes. + /// The status of the file system item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + FileSystemPathId id, + string name, + Optional dateCreated, + Optional dateModified, + long size, + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + // TODO: enforce invariants + File newFile = new File( + id, + name, + dateCreated, + dateModified, + size); + ErrorOr setStatusResult = newFile.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newFile; + } + + /// + /// Updates the last modified date of the file system item. + /// + /// The new date and time of last modification. + /// An representing either a successfull operation, or an error. + public ErrorOr UpdateLastModified(DateTime date) + { + DateModified = date; + return Result.Updated; + } + /// /// Updates the size of the file. /// /// The new size, in bytes. - public void UpdateSize(long newSize) + /// An representing either a successfull operation, or an error. + public ErrorOr UpdateSize(long newSize) { Size = newSize; + return Result.Updated; + } + + /// + /// Renames the file system item to the specified new name. + /// + /// The new name for the file system item. + /// An representing either a successfull operation, or an error. + public ErrorOr Rename(string newName) + { + if (string.IsNullOrWhiteSpace(newName)) + return Errors.FileManagement.NameCannotBeEmpty; + Name = newName; + return Result.Updated; } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/UnixRootItem.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/UnixRootItem.cs new file mode 100644 index 00000000..c192b8a4 --- /dev/null +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/UnixRootItem.cs @@ -0,0 +1,66 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; + +/// +/// Entity representing a file system root item on Unix platforms. +/// +[DebuggerDisplay("{Id.Path}")] +public sealed class UnixRootItem : FileSystemItem +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly List _items = []; + private const string PATH = "/"; + #endregion + + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the collection of file system items that are children to the current file system root entity. + /// + public IReadOnlyCollection Items + { + get { return _items.AsReadOnly(); } + } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the root item in the file system path. + /// The name of the root item. + private UnixRootItem(FileSystemPathId id, string name) : base(id, name, FileSystemItemType.Root) + { + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of the class. + /// + /// The status of the file system root item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + ErrorOr createPathResult = FileSystemPathId.Create(PATH); + if (createPathResult.IsError) + return createPathResult.Errors; + UnixRootItem newRoot = new UnixRootItem( + createPathResult.Value, + PATH); + ErrorOr setStatusResult = newRoot.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newRoot; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/WindowsRootItem.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/WindowsRootItem.cs new file mode 100644 index 00000000..a2475ec8 --- /dev/null +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Entities/WindowsRootItem.cs @@ -0,0 +1,94 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; + +/// +/// Entity representing a file system root item on Windows platforms. +/// +[DebuggerDisplay("{Id.Path}")] +public sealed class WindowsRootItem : FileSystemItem +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly List _items = []; + #endregion + + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the collection of file system items that are children to the current file system root entity. + /// + public IReadOnlyCollection Items + { + get { return _items.AsReadOnly(); } + } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// The unique identifier of the root item in the file system path. + /// The name of the root item. + private WindowsRootItem(FileSystemPathId id, string name) : base(id, name, FileSystemItemType.Root) + { + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of the class. + /// + /// The path of the file system root item. + /// The name of the file system root item. + /// The status of the file system root item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + string path, + string name, + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + // TODO: enforce invariants + ErrorOr createPathResult = FileSystemPathId.Create(path); + if (createPathResult.IsError) + return createPathResult.Errors; + WindowsRootItem newRoot = new WindowsRootItem( + createPathResult.Value, + name); + ErrorOr setStatusResult = newRoot.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newRoot; + } + + /// + /// Creates a new instance of the class. + /// + /// The unique identifier of the file system root item in the file system path. + /// The name of the file system root item. + /// The status of the file system root item. + /// + /// An containing either a successfully created , or an error message. + /// + public static ErrorOr Create( + FileSystemPathId id, + string name, + FileSystemItemStatus status = FileSystemItemStatus.Accessible) + { + // TODO: enforce invariants + WindowsRootItem newFile = new WindowsRootItem( + id, + name); + ErrorOr setStatusResult = newFile.SetStatus(status); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return newFile; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/FileSystemItem.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/FileSystemItem.cs index f42319c0..b5efaf41 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/FileSystemItem.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/FileSystemItem.cs @@ -1,8 +1,10 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using ErrorOr; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; -using System; using System.Diagnostics; #endregion @@ -21,22 +23,19 @@ public abstract class FileSystemItem : AggregateRoot public string Name { get; protected set; } /// - /// Gets or sets the creation date of the file system item. - /// Can be if the information is not available. + /// Gets or sets the optional parent of the file system item. /// - public DateTime? DateCreated { get; protected set; } + public Optional Parent { get; protected set; } /// - /// Gets or sets the last modification date of the file system item. - /// Can be if the information is not available. - /// - public DateTime? DateModified { get; protected set; } - - /// - /// Gets or sets the current status of the file system item. - /// Defaults to Accessible. + /// Gets or sets the current status of the file system item. Defaults to Accessible. /// public FileSystemItemStatus Status { get; protected set; } = FileSystemItemStatus.Accessible; + + /// + /// Gets or sets the tpe of the file system item. + /// + public FileSystemItemType Type { get; protected set; } #endregion #region ====================================================================== CTOR ===================================================================================== @@ -45,45 +44,38 @@ public abstract class FileSystemItem : AggregateRoot /// /// The unique identifier for the file system path. /// The name of the file system item. - /// The date and time the file system item was last modified. Can be if unknown. - /// The date and time the file system item was created. Can be if unknown. - protected FileSystemItem(FileSystemPathId id, string name, DateTime? dateModified, DateTime? dateCreated) : base(id) + /// The type of the file system item. + protected FileSystemItem(FileSystemPathId id, string name, FileSystemItemType fileSystemItemType) : base(id) { Name = name; - DateCreated = dateCreated; - DateModified = dateModified; + Type = fileSystemItemType; } #endregion #region ===================================================================== METHODS =================================================================================== - /// - /// Renames the file system item to the specified new name. - /// - /// The new name for the file system item. - /// Thrown if the new name is null or whitespace. - public void Rename(string newName) - { - if (string.IsNullOrWhiteSpace(newName)) - throw new ArgumentException("New name cannot be empty", nameof(newName)); - Name = newName; - } - - /// - /// Updates the last modified date of the file system item. - /// - /// The new date and time of last modification. - public void UpdateLastModified(DateTime date) - { - DateModified = date; - } - /// /// Sets the status of the filesystem item. /// /// The status to be set. - public void SetStatus(FileSystemItemStatus status) + /// An representing either a successfull operation, or an error. + public ErrorOr SetStatus(FileSystemItemStatus status) { Status = status; + return Result.Updated; + } + + /// + /// Sets the parent of the filesystem item. + /// + /// The file system item to be set as parent. + /// An representing either a successfull operation, or an error. + public ErrorOr SetParent(FileSystemItem parent) + { + if (parent is not null) + Parent = parent; + else + return Errors.FileManagement.ParentNodeCannotBeNull; + return Result.Updated; } #endregion -} +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryProviderService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryProviderService.cs index c03c9d07..9fa35e3f 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryProviderService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryProviderService.cs @@ -1,13 +1,13 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -37,21 +37,21 @@ internal class DirectoryProviderService : IDirectoryProviderService #region ===================================================================== METHODS =================================================================================== /// - /// Retrieves a list of subdirectory paths from the specified path, asynchronously. + /// Retrieves a list of subdirectory paths from the specified path. /// /// The path from which to retrieve the subdirectory paths. - /// An containing either a task representing the asynchronous operation for retrieving a collection of directory paths or an error. - public ErrorOr>> GetSubdirectoryPathsAsync(FileSystemPathId path) + /// An containing either a collection of directory paths or an error. + public ErrorOr> GetSubdirectoryPaths(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory, false)) return Errors.Permission.UnauthorizedAccess; - return Task.Run(() => _fileSystem.Directory.GetDirectories(path.Path) - .OrderBy(p => p) - .Select(p => FileSystemPathId.Create(p)) - .Where(errorOrPathId => !errorOrPathId.IsError) - .Select(errorOrPathId => errorOrPathId.Value) - .AsEnumerable()); + return ErrorOrFactory.From(_fileSystem.Directory.GetDirectories(path.Path) + .OrderBy(path => path) + .Select(path => FileSystemPathId.Create(path)) + .Where(errorOrPathId => !errorOrPathId.IsError) + .Select(errorOrPathId => errorOrPathId.Value) + .AsEnumerable()); } /// @@ -79,26 +79,26 @@ internal class DirectoryProviderService : IDirectoryProviderService /// Gets the last write time of a specific path. /// /// The path to retrieve the last write time for. - /// An containing either the last write time of , or null if not available, or an error. - public ErrorOr GetLastWriteTime(FileSystemPathId path) + /// An containing either the optional last write time of if available, or an error. + public ErrorOr> GetLastWriteTime(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false)) return Errors.Permission.UnauthorizedAccess; - return _fileSystem.Directory.GetLastWriteTime(path.Path); + return Optional.FromNullable(_fileSystem.Directory.GetLastWriteTime(path.Path)); } /// /// Gets the creation time of a specific path. /// /// The path to retrieve the creation time for. - /// An containing either the creation time of , or null if not available, or an error. - public ErrorOr GetCreationTime(FileSystemPathId path) + /// An containing the optional creation time of if available, or an error. + public ErrorOr> GetCreationTime(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false)) return Errors.Permission.UnauthorizedAccess; - return _fileSystem.Directory.GetCreationTime(path.Path); + return Optional.FromNullable(_fileSystem.Directory.GetCreationTime(path.Path)); } /// @@ -128,7 +128,7 @@ internal class DirectoryProviderService : IDirectoryProviderService { // check if the source directory exists if (!_fileSystem.Directory.Exists(sourcePath.Path)) - return Errors.FileManagement.DirectoryNotFoundError; + return Errors.FileManagement.DirectoryNotFound; string destPath = CreateUniqueDirectoryPath(destinationPath.Path); try { @@ -191,7 +191,7 @@ internal class DirectoryProviderService : IDirectoryProviderService { // check if the source directory exists if (!_fileSystem.Directory.Exists(sourcePath.Path)) - return Errors.FileManagement.DirectoryNotFoundError; + return Errors.FileManagement.DirectoryNotFound; try { // if the destination directory does not exist, perform a simple move @@ -280,10 +280,10 @@ internal class DirectoryProviderService : IDirectoryProviderService return newDirectoryPathResult.Value; } else - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; } else - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; } /// @@ -291,13 +291,13 @@ internal class DirectoryProviderService : IDirectoryProviderService /// /// The path of the directory to be deleted. /// An containing either the result of deleting a directory, or an error. - public ErrorOr DeleteDirectory(FileSystemPathId path) + public ErrorOr DeleteDirectory(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete, false)) return Errors.Permission.UnauthorizedAccess; _fileSystem.DirectoryInfo.New(path.Path).Delete(true); - return true; + return Result.Deleted; } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryService.cs index 5c1c5b96..d942fba7 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DirectoryService.cs @@ -1,14 +1,14 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -25,7 +25,7 @@ public class DirectoryService : IDirectoryService #region ====================================================================== CTOR ===================================================================================== /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Injected facade service for environment contextual services. /// Injected facade service for platform contextual services. @@ -42,12 +42,12 @@ public class DirectoryService : IDirectoryService /// /// String representation of the file path. /// An containing either a collection of subdirectories or an error. - public async Task>> GetSubdirectoriesAsync(string path) + public ErrorOr> GetSubdirectories(string path) { - var fileSystemPathIdResult = FileSystemPathId.Create(path); + ErrorOr fileSystemPathIdResult = FileSystemPathId.Create(path); if (fileSystemPathIdResult.IsError) return fileSystemPathIdResult.Errors; - return await GetSubdirectoriesAsync(fileSystemPathIdResult.Value).ConfigureAwait(false); + return GetSubdirectories(fileSystemPathIdResult.Value); } /// @@ -55,9 +55,9 @@ public class DirectoryService : IDirectoryService /// /// Directory object to retrieve subdirectories for. /// An containing either a collection of subdirectories or an error. - public async Task>> GetSubdirectoriesAsync(Directory directory) + public ErrorOr> GetSubdirectories(Directory directory) { - return await GetSubdirectoriesAsync(directory.Id).ConfigureAwait(false); + return GetSubdirectories(directory.Id); } /// @@ -65,33 +65,40 @@ public class DirectoryService : IDirectoryService /// /// Identifier for the file path. /// An containing either a collection of subdirectories or an error. - public async Task>> GetSubdirectoriesAsync(FileSystemPathId path) + public ErrorOr> GetSubdirectories(FileSystemPathId path) { // retrieve the list of subdirectories - ErrorOr>> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPathsAsync(path); + ErrorOr> subdirectoryPathsResult = _environmentContext.DirectoryProviderService.GetSubdirectoryPaths(path); if (subdirectoryPathsResult.IsError) return subdirectoryPathsResult.Errors; - List result = new(); - IEnumerable subdirectoryPaths = await subdirectoryPathsResult.Value.ConfigureAwait(false); + List result = []; + IEnumerable subdirectoryPaths = subdirectoryPathsResult.Value; foreach (FileSystemPathId subPath in subdirectoryPaths) { // extract directory details ErrorOr dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(subPath); - ErrorOr dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath); - ErrorOr dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath); + ErrorOr> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath); + ErrorOr> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath); // if any error occurred, mark directory as Inaccessible if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - Directory errorDir = new(subPath, !dirNameResult.IsError ? dirNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null); - errorDir.SetStatus(FileSystemItemStatus.Inaccessible); - result.Add(errorDir); + ErrorOr errorDirResult = Directory.Create(subPath, !dirNameResult.IsError ? dirNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None()); + if(errorDirResult.IsError) + return errorDirResult.Errors; + ErrorOr setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + result.Add(errorDirResult.Value); } else { - Directory subDirectory = new(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value); - result.Add(subDirectory); + ErrorOr subDirectoryResult = Directory.Create(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value); + if (subDirectoryResult.IsError) + return subDirectoryResult.Errors; + result.Add(subDirectoryResult.Value); } } return result; @@ -105,7 +112,7 @@ public class DirectoryService : IDirectoryService /// An containing either the result of creating a directory, or an error. public ErrorOr CreateDirectory(string path, string name) { - var fileSystemPathIdResult = FileSystemPathId.Create(path); + ErrorOr fileSystemPathIdResult = FileSystemPathId.Create(path); if (fileSystemPathIdResult.IsError) return fileSystemPathIdResult.Errors; return CreateDirectory(fileSystemPathIdResult.Value, name); @@ -120,14 +127,14 @@ public class DirectoryService : IDirectoryService public ErrorOr CreateDirectory(FileSystemPathId path, string name) { // first, check if the directory about to be created does not already exist - var combinedPath = _platformContext.PathStrategy.CombinePath(path, name); + ErrorOr combinedPath = _platformContext.PathStrategy.CombinePath(path, name); if (combinedPath.IsError) return combinedPath.Errors; - var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value); + ErrorOr directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value); if (directoryExists.IsError) return directoryExists.Errors; else if (directoryExists.Value == true) - return Errors.FileManagement.DirectoryAlreadyExistsError; + return Errors.FileManagement.DirectoryAlreadyExists; else { // create the new directory @@ -135,18 +142,23 @@ public class DirectoryService : IDirectoryService if (newDirectoryPathResult.IsError) return newDirectoryPathResult.Errors; ErrorOr dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(path); - ErrorOr dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(path); - ErrorOr dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(path); + ErrorOr> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(path); + ErrorOr> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(path); // if any error occurred, mark directory as Inaccessible if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - Directory errorDir = new(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null); - errorDir.SetStatus(FileSystemItemStatus.Inaccessible); - return errorDir; + ErrorOr errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None()); + if (errorDirResult.IsError) + return errorDirResult.Errors; + ErrorOr setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return errorDirResult; } else - return new Directory(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value); + return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value); } } @@ -164,10 +176,10 @@ public class DirectoryService : IDirectoryService sourcePath += _platformContext.PathStrategy.PathSeparator; if (!destinationPath.EndsWith(_platformContext.PathStrategy.PathSeparator)) destinationPath += _platformContext.PathStrategy.PathSeparator; - var fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath); + ErrorOr fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath); if (fileSystemSourcePathIdResult.IsError) return fileSystemSourcePathIdResult.Errors; - var fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath); + ErrorOr fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath); if (fileSystemDestinationPathIdResult.IsError) return fileSystemDestinationPathIdResult.Errors; return CopyDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false); @@ -182,11 +194,11 @@ public class DirectoryService : IDirectoryService /// An containing either the copied directory, or an error. public ErrorOr CopyDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting) { - var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath); + ErrorOr directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath); if (directoryExists.IsError) return directoryExists.Errors; else if (directoryExists.Value == false) - return Errors.FileManagement.DirectoryNotFoundError; + return Errors.FileManagement.DirectoryNotFound; else { // copy the directory @@ -210,10 +222,10 @@ public class DirectoryService : IDirectoryService sourcePath += _platformContext.PathStrategy.PathSeparator; if (!destinationPath.EndsWith(_platformContext.PathStrategy.PathSeparator)) destinationPath += _platformContext.PathStrategy.PathSeparator; - var fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath); + ErrorOr fileSystemSourcePathIdResult = FileSystemPathId.Create(sourcePath); if (fileSystemSourcePathIdResult.IsError) return fileSystemSourcePathIdResult.Errors; - var fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath); + ErrorOr fileSystemDestinationPathIdResult = FileSystemPathId.Create(destinationPath); if (fileSystemDestinationPathIdResult.IsError) return fileSystemDestinationPathIdResult.Errors; return MoveDirectory(fileSystemSourcePathIdResult.Value, fileSystemDestinationPathIdResult.Value, overrideExisting ?? false); @@ -228,11 +240,11 @@ public class DirectoryService : IDirectoryService /// An containing either the moved directory, or an error. public ErrorOr MoveDirectory(FileSystemPathId sourcePath, FileSystemPathId destinationPath, bool overrideExisting) { - var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath); + ErrorOr directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(sourcePath); if (directoryExists.IsError) return directoryExists.Errors; else if (directoryExists.Value == false) - return Errors.FileManagement.DirectoryNotFoundError; + return Errors.FileManagement.DirectoryNotFound; else { // move the directory @@ -250,7 +262,7 @@ public class DirectoryService : IDirectoryService /// An containing either the renamed directory, or an error. public ErrorOr RenameDirectory(string path, string name) { - var fileSystemPathIdResult = FileSystemPathId.Create(path); + ErrorOr fileSystemPathIdResult = FileSystemPathId.Create(path); if (fileSystemPathIdResult.IsError) return fileSystemPathIdResult.Errors; return RenameDirectory(fileSystemPathIdResult.Value, name); @@ -265,14 +277,14 @@ public class DirectoryService : IDirectoryService public ErrorOr RenameDirectory(FileSystemPathId path, string name) { // first, check if the directory about to be created does not already exist - var combinedPath = _platformContext.PathStrategy.CombinePath(path, name); + ErrorOr combinedPath = _platformContext.PathStrategy.CombinePath(path, name); if (combinedPath.IsError) return combinedPath.Errors; - var directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value); + ErrorOr directoryExists = _environmentContext.DirectoryProviderService.DirectoryExists(combinedPath.Value); if (directoryExists.IsError) return directoryExists.Errors; else if (directoryExists.Value == true) - return Errors.FileManagement.DirectoryAlreadyExistsError; + return Errors.FileManagement.DirectoryAlreadyExists; else { // rename the directory @@ -280,18 +292,23 @@ public class DirectoryService : IDirectoryService if (newDirectoryPathResult.IsError) return newDirectoryPathResult.Errors; ErrorOr dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value); - ErrorOr dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value); - ErrorOr dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value); + ErrorOr> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value); + ErrorOr> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value); // if any error occurred, mark directory as Inaccessible if (dirNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - Directory errorDir = new(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null); - errorDir.SetStatus(FileSystemItemStatus.Inaccessible); - return errorDir; + ErrorOr errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsError ? dirNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None()); + if (errorDirResult.IsError) + return errorDirResult.Errors; + ErrorOr setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return errorDirResult; } else - return new Directory(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value); + return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value); } } @@ -300,9 +317,9 @@ public class DirectoryService : IDirectoryService /// /// String representation of the directory path. /// An containing either the result of deleting a directory, or an error. - public ErrorOr DeleteDirectory(string path) + public ErrorOr DeleteDirectory(string path) { - var fileSystemPathIdResult = FileSystemPathId.Create(path); + ErrorOr fileSystemPathIdResult = FileSystemPathId.Create(path); if (fileSystemPathIdResult.IsError) return fileSystemPathIdResult.Errors; return DeleteDirectory(fileSystemPathIdResult.Value); @@ -313,7 +330,7 @@ public class DirectoryService : IDirectoryService /// /// Identifier for the directory path. /// An containing either the result of deleting a directory, or an error. - public ErrorOr DeleteDirectory(FileSystemPathId path) + public ErrorOr DeleteDirectory(FileSystemPathId path) { return _environmentContext.DirectoryProviderService.DeleteDirectory(path); } diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DriveService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DriveService.cs new file mode 100644 index 00000000..3e998e43 --- /dev/null +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/DriveService.cs @@ -0,0 +1,68 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; +using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform; +using System.Collections.Generic; +using System.IO.Abstractions; +using System.Linq; +#endregion + +namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; + +/// +/// Service for handling drives. +/// +public class DriveService : IDriveService +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IFileSystem _fileSystem; + private readonly IPlatformContext _platformContext; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service used to interact with the local filesystem. + public DriveService(IFileSystem fileSystem, IPlatformContextManager platformContextManager) + { + _fileSystem = fileSystem; + _platformContext = platformContextManager.GetCurrentContext(); + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Retrieves the list of drives. + /// + /// An containing either a collection of drives or an error. + public ErrorOr> GetDrives() + { + if (_platformContext.Platform == PlatformType.Unix) + { + var unixRootResult = UnixRootItem.Create(FileSystemItemStatus.Accessible); + if (unixRootResult.IsError) + return unixRootResult.Errors; + return new List() { unixRootResult.Value }; + } + else + return ErrorOrFactory.From(_fileSystem.DriveInfo.GetDrives() + .OrderBy(driveInfo => driveInfo.Name) + .Where(driveInfo => driveInfo.IsReady) + .Select(driveInfo => + { + ErrorOr root; + var windowsRootResult = WindowsRootItem.Create(driveInfo.Name, driveInfo.Name); + if (windowsRootResult.IsError) + return windowsRootResult.Errors; + else + root = windowsRootResult.Value; + return root; + }) + .Where(errorOrDrive => !errorOrDrive.IsError) + .Select(errorOrDrive => errorOrDrive.Value) + .AsEnumerable()); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileProviderService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileProviderService.cs index ae924ffd..e5a6e068 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileProviderService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileProviderService.cs @@ -1,13 +1,13 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; -using System.Threading.Tasks; -using Lumina.Domain.Common.Errors; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -40,18 +40,18 @@ internal class FileProviderService : IFileProviderService /// Retrieves a list of file paths at the specified path. /// /// The path for which to retrieve the list of files. - /// An containing either a task representing the asynchronous operation for retrieving a collection of file paths or an error. - public ErrorOr>> GetFilePathsAsync(FileSystemPathId path) + /// An containing either a collection of file paths or an error. + public ErrorOr> GetFilePaths(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ListDirectory)) return Errors.Permission.UnauthorizedAccess; - return Task.Run(() => _fileSystem.Directory.GetFiles(path.Path) - .OrderBy(p => p) - .Select(p => FileSystemPathId.Create(p)) - .Where(errorOrPathId => !errorOrPathId.IsError) - .Select(errorOrPathId => errorOrPathId.Value) - .AsEnumerable()); + return ErrorOrFactory.From(_fileSystem.Directory.GetFiles(path.Path) + .OrderBy(p => p) + .Select(p => FileSystemPathId.Create(p)) + .Where(errorOrPathId => !errorOrPathId.IsError) + .Select(errorOrPathId => errorOrPathId.Value) + .AsEnumerable()); } /// @@ -78,39 +78,39 @@ internal class FileProviderService : IFileProviderService /// Retrieves the contents of a file at the specified path. /// /// The path for which to retrieve the file contents. - /// An containing either a task representing the asynchronous operation for retrieving the contents of a file at the specified path, or an error. - public ErrorOr> GetFileAsync(FileSystemPathId path) + /// An containing either the contents of a file at the specified path, or an error. + public ErrorOr GetFileAsync(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents)) return Errors.Permission.UnauthorizedAccess; - return Task.Run(() => System.IO.File.ReadAllBytes(path.Path)); + return System.IO.File.ReadAllBytes(path.Path); } /// /// Gets the last write time of a file at the specified path. /// /// The path of the file to retrieve the last write time for. - /// An containing either the last write time of , or null if not available, or an error. - public ErrorOr GetLastWriteTime(FileSystemPathId path) + /// An containing either the optional last write time of if available, or an error. + public ErrorOr> GetLastWriteTime(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties)) return Errors.Permission.UnauthorizedAccess; - return _fileSystem.File.GetLastWriteTime(path.Path); + return Optional.FromNullable(_fileSystem.File.GetLastWriteTime(path.Path)); } /// /// Gets the creation time of a file at the specified path. /// /// The path of the file to retrieve the creation time for. - /// An containing either the creation time of , or null if not available, or an error. - public ErrorOr GetCreationTime(FileSystemPathId path) + /// An containing either the optional creation time of if available, or an error. + public ErrorOr> GetCreationTime(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties)) return Errors.Permission.UnauthorizedAccess; - return _fileSystem.File.GetCreationTime(path.Path); + return Optional.FromNullable(_fileSystem.File.GetCreationTime(path.Path)); } /// @@ -137,7 +137,7 @@ internal class FileProviderService : IFileProviderService { // check if the source file exists if (!_fileSystem.File.Exists(sourceFilePath.Path)) - return Errors.FileManagement.FileNotFoundError; + return Errors.FileManagement.FileNotFound; string destinationFilePath; string fileName = _fileSystem.Path.GetFileName(sourceFilePath.Path); // when copying a file to the same location, just copy it with a new name @@ -148,7 +148,7 @@ internal class FileProviderService : IFileProviderService // check if there is already a file with the same name as the copied file, in the destination directory if (_fileSystem.File.Exists(destinationDirectoryPath.Path + fileName)) if (!overrideExisting) - return Errors.FileManagement.FileAlreadyExistsError; + return Errors.FileManagement.FileAlreadyExists; destinationFilePath = destinationDirectoryPath.Path + fileName; } try @@ -193,7 +193,7 @@ internal class FileProviderService : IFileProviderService { // check if the source file exists if (!_fileSystem.File.Exists(sourceFilePath.Path)) - return Errors.FileManagement.FileNotFoundError; + return Errors.FileManagement.FileNotFound; try { string fileName = _fileSystem.Path.GetFileName(sourceFilePath.Path); @@ -206,7 +206,7 @@ internal class FileProviderService : IFileProviderService if (overrideExisting) _fileSystem.File.Move(sourceFilePath.Path, destinationFilePath, overrideExisting); else - return Errors.FileManagement.FileAlreadyExistsError; + return Errors.FileManagement.FileAlreadyExists; } return FileSystemPathId.Create(destinationFilePath); } @@ -245,10 +245,10 @@ internal class FileProviderService : IFileProviderService return newFilePathResult; } else - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; } else - return Errors.FileManagement.CannotNavigateUpError; + return Errors.FileManagement.CannotNavigateUp; } /// @@ -256,13 +256,13 @@ internal class FileProviderService : IFileProviderService /// /// The path of the file to be deleted. /// An containing either the result of deleting a file, or an error. - public ErrorOr DeleteFile(FileSystemPathId path) + public ErrorOr DeleteFile(FileSystemPathId path) { // check if the user has access permissions to the provided path if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete)) return Errors.Permission.UnauthorizedAccess; _fileSystem.File.Delete(path.Path); - return true; + return Result.Deleted; } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileService.cs index 2cc34a21..abd1d105 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileService.cs @@ -1,14 +1,14 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -42,12 +42,12 @@ public class FileService : IFileService /// /// String representation of the file path. /// An containing either a collection of files or an error. - public async Task>> GetFilesAsync(string path) + public ErrorOr> GetFiles(string path) { var fileSystemPathIdResult = FileSystemPathId.Create(path); if (fileSystemPathIdResult.IsError) return fileSystemPathIdResult.Errors; - return await GetFilesAsync(fileSystemPathIdResult.Value).ConfigureAwait(false); + return GetFiles(fileSystemPathIdResult.Value); } /// @@ -55,9 +55,9 @@ public class FileService : IFileService /// /// The file object. /// An containing either a collection of files or an error. - public async Task>> GetFilesAsync(File file) + public ErrorOr> GetFiles(File file) { - return await GetFilesAsync(file.Id).ConfigureAwait(false); + return GetFiles(file.Id); } /// @@ -65,34 +65,41 @@ public class FileService : IFileService /// /// Identifier for the file path. /// An containing either a collection of files or an error. - public async Task>> GetFilesAsync(FileSystemPathId path) + public ErrorOr> GetFiles(FileSystemPathId path) { // retrieve the list of files - ErrorOr>> filePathsResult = _environmentContext.FileProviderService.GetFilePathsAsync(path); + ErrorOr> filePathsResult = _environmentContext.FileProviderService.GetFilePaths(path); if (filePathsResult.IsError) return filePathsResult.Errors; List result = new(); - IEnumerable filePaths = await filePathsResult.Value.ConfigureAwait(false); + IEnumerable filePaths = filePathsResult.Value; foreach (FileSystemPathId filePath in filePaths) { // extract file details and add to the result list ErrorOr fileNameResult = _environmentContext.FileProviderService.GetFileName(filePath); - ErrorOr dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(filePath); - ErrorOr dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath); + ErrorOr> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(filePath); + ErrorOr> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath); ErrorOr sizeResult = _environmentContext.FileProviderService.GetSize(filePath); long size = sizeResult.Value ?? 0; // if any of the details returned an error, set inaccessible status if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - File errorFile = new(filePath, !fileNameResult.IsError ? fileNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size); - errorFile.SetStatus(FileSystemItemStatus.Inaccessible); - result.Add(errorFile); + ErrorOr errorFileResult = File.Create(filePath, !fileNameResult.IsError ? fileNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None(), size); + if (errorFileResult.IsError) + return errorFileResult.Errors; + ErrorOr setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + result.Add(errorFileResult.Value); } else { - File file = new(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); - result.Add(file); + var fileResult = File.Create(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); + if (fileResult.IsError) + return fileResult.Errors; + result.Add(fileResult.Value); } } return result; @@ -132,7 +139,7 @@ public class FileService : IFileService if (fileExists.IsError) return fileExists.Errors; else if (fileExists.Value == false) - return Errors.FileManagement.FileNotFoundError; + return Errors.FileManagement.FileNotFound; else { // copy the file @@ -140,20 +147,25 @@ public class FileService : IFileService if (copyFileResult.IsError) return copyFileResult.Errors; ErrorOr fileNameResult = _environmentContext.FileProviderService.GetFileName(copyFileResult.Value); - ErrorOr dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(copyFileResult.Value); - ErrorOr dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(copyFileResult.Value); + ErrorOr> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(copyFileResult.Value); + ErrorOr> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(copyFileResult.Value); ErrorOr sizeResult = _environmentContext.FileProviderService.GetSize(copyFileResult.Value); long size = sizeResult.Value ?? 0; // if any of the details returned an error, set inaccessible status if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - File errorFile = new(copyFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size); - errorFile.SetStatus(FileSystemItemStatus.Inaccessible); - return errorFile; + ErrorOr errorFileResult = File.Create(copyFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None(), size); + if (errorFileResult.IsError) + return errorFileResult.Errors; + ErrorOr setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return errorFileResult; } else - return new File(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); + return File.Create(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); } } @@ -191,7 +203,7 @@ public class FileService : IFileService if (fileExists.IsError) return fileExists.Errors; else if (fileExists.Value == false) - return Errors.FileManagement.FileNotFoundError; + return Errors.FileManagement.FileNotFound; else { // move the file @@ -199,20 +211,25 @@ public class FileService : IFileService if (moveFileResult.IsError) return moveFileResult.Errors; ErrorOr fileNameResult = _environmentContext.FileProviderService.GetFileName(moveFileResult.Value); - ErrorOr dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(moveFileResult.Value); - ErrorOr dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(moveFileResult.Value); + ErrorOr> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(moveFileResult.Value); + ErrorOr> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(moveFileResult.Value); ErrorOr sizeResult = _environmentContext.FileProviderService.GetSize(moveFileResult.Value); long size = sizeResult.Value ?? 0; // if any of the details returned an error, set inaccessible status if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - File errorFile = new(moveFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size); - errorFile.SetStatus(FileSystemItemStatus.Inaccessible); - return errorFile; + ErrorOr errorFileResult = File.Create(moveFileResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None(), size); + if (errorFileResult.IsError) + return errorFileResult.Errors; + ErrorOr setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return errorFileResult; } else - return new File(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); + return File.Create(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); } } @@ -246,7 +263,7 @@ public class FileService : IFileService if (fileExists.IsError) return fileExists.Errors; else if (fileExists.Value == true) - return Errors.FileManagement.FileAlreadyExistsError; + return Errors.FileManagement.FileAlreadyExists; else { // rename the file @@ -254,20 +271,25 @@ public class FileService : IFileService if (newFilePathResult.IsError) return newFilePathResult.Errors; ErrorOr fileNameResult = _environmentContext.FileProviderService.GetFileName(newFilePathResult.Value); - ErrorOr dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(newFilePathResult.Value); - ErrorOr dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(newFilePathResult.Value); + ErrorOr> dateModifiedResult = _environmentContext.FileProviderService.GetLastWriteTime(newFilePathResult.Value); + ErrorOr> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(newFilePathResult.Value); ErrorOr sizeResult = _environmentContext.FileProviderService.GetSize(newFilePathResult.Value); long size = sizeResult.Value ?? 0; // if any of the details returned an error, set inaccessible status if (fileNameResult.IsError || dateModifiedResult.IsError || dateCreatedResult.IsError) { - File errorFile = new(newFilePathResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!, - !dateCreatedResult.IsError ? dateCreatedResult.Value : null, !dateModifiedResult.IsError ? dateModifiedResult.Value : null, size); - errorFile.SetStatus(FileSystemItemStatus.Inaccessible); - return errorFile; + ErrorOr errorFileResult = File.Create(newFilePathResult.Value, !fileNameResult.IsError ? fileNameResult.Value : null!, + !dateCreatedResult.IsError ? dateCreatedResult.Value : Optional.None(), + !dateModifiedResult.IsError ? dateModifiedResult.Value : Optional.None(), size); + if (errorFileResult.IsError) + return errorFileResult.Errors; + ErrorOr setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible); + if (setStatusResult.IsError) + return setStatusResult.Errors; + return errorFileResult; } else - return new File(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); + return File.Create(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size); } } @@ -276,7 +298,7 @@ public class FileService : IFileService /// /// String representation of the file path. /// An containing either the result of deleting a file, or an error. - public ErrorOr DeleteFile(string path) + public ErrorOr DeleteFile(string path) { var fileSystemPathIdResult = FileSystemPathId.Create(path); if (fileSystemPathIdResult.IsError) @@ -289,7 +311,7 @@ public class FileService : IFileService /// /// Identifier for the file path. /// An containing either the result of deleting a file, or an error. - public ErrorOr DeleteFile(FileSystemPathId path) + public ErrorOr DeleteFile(FileSystemPathId path) { return _environmentContext.FileProviderService.DeleteFile(path); } diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileSystemPermissionsService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileSystemPermissionsService.cs index 88249cd0..8f2451a5 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileSystemPermissionsService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileSystemPermissionsService.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using Mono.Unix; diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileTypeService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileTypeService.cs index c33fc661..a4e36bc6 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileTypeService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/FileTypeService.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; +using Lumina.Contracts.Enums.PhotoLibrary; using Lumina.Domain.Common.Errors; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; @@ -156,4 +157,4 @@ public class FileTypeService : IFileTypeService return ImageType.None; } #endregion -} +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryProviderService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryProviderService.cs index 5de743c7..c9b72796 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryProviderService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryProviderService.cs @@ -1,9 +1,9 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -15,11 +15,11 @@ public interface IDirectoryProviderService { #region ===================================================================== METHODS =================================================================================== /// - /// Retrieves a list of subdirectory paths from the specified path, asynchronously. + /// Retrieves a list of subdirectory paths from the specified path. /// /// The path from which to retrieve the subdirectory paths. - /// An containing either a task representing the asynchronous operation for retrieving a collection of directory paths or an error. - ErrorOr>> GetSubdirectoryPathsAsync(FileSystemPathId path); + /// An containing either a collection of directory paths or an error. + ErrorOr> GetSubdirectoryPaths(FileSystemPathId path); /// /// Checks if a directory with the specified path exists. @@ -40,15 +40,15 @@ public interface IDirectoryProviderService /// /// The path to retrieve the last write time for. /// The last write time for the specified path, or null if unavailable. - /// An containing either the last write time of , or null if not available, or an error. - ErrorOr GetLastWriteTime(FileSystemPathId path); + /// An containing either the optional last write time of if available, or an error. + ErrorOr> GetLastWriteTime(FileSystemPathId path); /// /// Gets the creation time of a specific path. /// /// The path to retrieve the creation time for. - /// An containing either the creation time of , or null if not available, or an error. - ErrorOr GetCreationTime(FileSystemPathId path); + /// An containing the optional creation time of if available, or an error. + ErrorOr> GetCreationTime(FileSystemPathId path); /// /// Creates a new directory with the specified name, at the specified path. @@ -89,6 +89,6 @@ public interface IDirectoryProviderService /// /// The path of the directory to be deleted. /// An containing either the result of deleting a directory, or an error. - ErrorOr DeleteDirectory(FileSystemPathId path); + ErrorOr DeleteDirectory(FileSystemPathId path); #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryService.cs index 98accfbe..dff966f3 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDirectoryService.cs @@ -3,7 +3,6 @@ using ErrorOr; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System.Collections.Generic; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -19,21 +18,21 @@ public interface IDirectoryService /// /// String representation of the file path. /// An containing either a collection of subdirectories or an error. - Task>> GetSubdirectoriesAsync(string path); + ErrorOr> GetSubdirectories(string path); /// /// Retrieves subdirectories for the given directory. /// /// Directory object to retrieve subdirectories for. /// An containing either a collection of subdirectories or an error. - Task>> GetSubdirectoriesAsync(Directory directory); + ErrorOr> GetSubdirectories(Directory directory); /// /// Retrieves subdirectories for the specified file system path. /// /// Identifier for the file path. /// An containing either a collection of subdirectories or an error. - Task>> GetSubdirectoriesAsync(FileSystemPathId path); + ErrorOr> GetSubdirectories(FileSystemPathId path); /// /// Creates a directory with the specified , at the specified . @@ -74,6 +73,6 @@ public interface IDirectoryService /// /// String representation of the directory path. /// An containing either the result of deleting a directory, or an error. - ErrorOr DeleteDirectory(string path); + ErrorOr DeleteDirectory(string path); #endregion -} +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDriveService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDriveService.cs new file mode 100644 index 00000000..ce9d1ca1 --- /dev/null +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IDriveService.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; + +/// +/// Interface for the service for handling drives. +/// +public interface IDriveService +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Retrieves the list of drives. + /// + /// An containing either a collection of drives or an error. + ErrorOr> GetDrives(); + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileProviderService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileProviderService.cs index 3e3e3943..1dee213d 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileProviderService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileProviderService.cs @@ -1,9 +1,9 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; +using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System; using System.Collections.Generic; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -18,15 +18,15 @@ public interface IFileProviderService /// Retrieves a list of files at the specified path. /// /// The path for which to retrieve the list of files. - /// An containing either a task representing the asynchronous operation for retrieving a collection of file paths, or an error. - ErrorOr>> GetFilePathsAsync(FileSystemPathId path); + /// An containing either a collection of file paths, or an error. + ErrorOr> GetFilePaths(FileSystemPathId path); /// /// Retrieves the contents of a file at the specified path. /// /// The path for which to retrieve the file contents. - /// An containing either a task representing the asynchronous operation for retrieving the contents of a file at the specified path, or an error. - ErrorOr> GetFileAsync(FileSystemPathId path); + /// An containing either the contents of a file at the specified path, or an error. + ErrorOr GetFileAsync(FileSystemPathId path); /// /// Checks if a file with the specified path exists. @@ -46,15 +46,15 @@ public interface IFileProviderService /// Gets the last write time of a file at the specified path. /// /// The path of the file to retrieve the last write time for. - /// An containing either the last write time of , or null if not available, or an error. - ErrorOr GetLastWriteTime(FileSystemPathId path); + /// An containing either the optional last write time of if available, or an error. + ErrorOr> GetLastWriteTime(FileSystemPathId path); /// /// Gets the creation time of a file at the specified path. /// /// The path of the file to retrieve the creation time for. - /// An containing either the creation time of , or null if not available, or an error. - ErrorOr GetCreationTime(FileSystemPathId path); + /// An containing either the otional creation time of if available, or an error. + ErrorOr> GetCreationTime(FileSystemPathId path); /// /// Gets the size of a file at the specified path. @@ -94,6 +94,6 @@ public interface IFileProviderService /// /// The path of the file to be deleted. /// An containing either the result of deleting a file, or an error. - ErrorOr DeleteFile(FileSystemPathId path); + ErrorOr DeleteFile(FileSystemPathId path); #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileService.cs index d9d8780a..b54932f0 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileService.cs @@ -3,7 +3,6 @@ using ErrorOr; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System.Collections.Generic; -using System.Threading.Tasks; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; @@ -19,21 +18,21 @@ public interface IFileService /// /// String representation of the file path. /// An containing either a collection of files or an error. - Task>> GetFilesAsync(string path); + ErrorOr> GetFiles(string path); /// /// Retrieves files associated with a given file. /// /// The file object. /// An containing either a collection of files or an error. - Task>> GetFilesAsync(File file); + ErrorOr> GetFiles(File file); /// /// Retrieves files for a specified file path ID. /// /// Identifier for the file path. /// An containing either a collection of files or an error. - Task>> GetFilesAsync(FileSystemPathId path); + ErrorOr> GetFiles(FileSystemPathId path); /// /// Copies a file located at to . @@ -66,6 +65,6 @@ public interface IFileService /// /// String representation of the file path. /// An containing either the result of deleting a file, or an error. - ErrorOr DeleteFile(string path); + ErrorOr DeleteFile(string path); #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileSystemPermissionsService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileSystemPermissionsService.cs index 35d01d64..4fa61533 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileSystemPermissionsService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileSystemPermissionsService.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileTypeService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileTypeService.cs index da7a1a9f..6ff3f5c7 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileTypeService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IFileTypeService.cs @@ -1,6 +1,6 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.PhotoLibrary; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using System.Threading.Tasks; diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IPathService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IPathService.cs index f49a8e5e..aafc1119 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IPathService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/IPathService.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; +using System; using System.Collections.Generic; #endregion @@ -53,5 +54,12 @@ public interface IPathService /// /// A collection of characters that are invalid in the context of paths. char[] GetInvalidPathCharsForPlatform(); + + /// + /// Returns the root portion of the given path. + /// + /// The path for which to get the root. + /// An containing the root of , or an error. + ErrorOr GetPathRoot(string path); #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/PathService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/PathService.cs index a02a1ec9..74c3a6a7 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/PathService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/PathService.cs @@ -102,5 +102,18 @@ public class PathService : IPathService { return _platformContext.PathStrategy.GetInvalidPathCharsForPlatform(); } + + /// + /// Returns the root portion of the given path. + /// + /// The path for which to get the root. + /// An containing the root of , or an error. + public ErrorOr GetPathRoot(string path) + { + ErrorOr newPathResult = FileSystemPathId.Create(path); + if (newPathResult.IsError) + return newPathResult.Errors; + return _platformContext.PathStrategy.GetPathRoot(newPathResult.Value); + } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/ThumbnailService.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/ThumbnailService.cs index a1aa3c72..9bfb310b 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/ThumbnailService.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Services/ThumbnailService.cs @@ -1,8 +1,7 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.PhotoLibrary; using Lumina.Domain.Common.Errors; -using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Services; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Environment; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; using SixLabors.ImageSharp; @@ -69,7 +68,7 @@ public class ThumbnailService : IThumbnailService var resultFileContents = _environmentContext.FileProviderService.GetFileAsync(path); if (resultFileContents.IsError) return resultFileContents.Errors; - byte[] fileContents = await resultFileContents.Value; + byte[] fileContents = resultFileContents.Value; // finally, resize or adjust quality based on image type byte[]? adjustedImage = null; if (imageTypeResult.Value == ImageType.JPEG || imageTypeResult.Value == ImageType.JPEG_CANON || imageTypeResult.Value == ImageType.JPEG2000 diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/IPathStrategy.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/IPathStrategy.cs index d56164b1..ea850094 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/IPathStrategy.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/IPathStrategy.cs @@ -50,5 +50,12 @@ public interface IPathStrategy /// /// A collection of characters that are invalid in the context of paths char[] GetInvalidPathCharsForPlatform(); + + /// + /// Returns the root portion of the given path. + /// + /// The path for which to get the root. + /// An containing the root of , or an error. + ErrorOr GetPathRoot(FileSystemPathId path); #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/UnixPathStrategy.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/UnixPathStrategy.cs index f1e23e11..329b785c 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/UnixPathStrategy.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/UnixPathStrategy.cs @@ -50,7 +50,7 @@ public class UnixPathStrategy : IUnixPathStrategy public ErrorOr CombinePath(FileSystemPathId path, string name) { if (string.IsNullOrWhiteSpace(name)) - return Errors.FileManagement.NameCannotBeEmptyError; + return Errors.FileManagement.NameCannotBeEmpty; // trim any directory separator characters from the end of the path string subpath = path.Path.TrimEnd(PathSeparator); // if the name begins with a directory separator, remove it @@ -68,9 +68,9 @@ public class UnixPathStrategy : IUnixPathStrategy { // if path starts with anything other than '/', it's considered relative and invalid for this parser if (!path.Path.StartsWith(PathSeparator)) - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; // get the path segments - var splitSegments = path.Path.Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries).ToList(); + List splitSegments = [.. path.Path.Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries)]; IEnumerable segments = splitSegments.Select((segment, index) => { bool isDirectory; @@ -79,7 +79,7 @@ public class UnixPathStrategy : IUnixPathStrategy else isDirectory = true; return new PathSegment(segment, isDirectory, isDrive: false); - }); + }).Prepend(new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true)); // UNIX paths have '/' as "root drive" return ErrorOrFactory.From(segments); } @@ -92,7 +92,7 @@ public class UnixPathStrategy : IUnixPathStrategy { // validation: ensure the path is not null or empty if (!IsValidPath(path)) - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; // trim trailing slash for consistent processing string tempPath = path.Path; if (tempPath.EndsWith("/")) @@ -101,7 +101,7 @@ public class UnixPathStrategy : IUnixPathStrategy var lastIndex = tempPath.LastIndexOf(PathSeparator); // if there's no slash found (shouldn't happen due to previous steps), or if we are at the root level after trimming, return error if (lastIndex < 0) - return Errors.FileManagement.CannotNavigateUpError; + return Errors.FileManagement.CannotNavigateUp; // return the path up to the last slash, or, if there's only the root slash, return that one instead ErrorOr newPathResult = FileSystemPathId.Create(lastIndex > 0 ? tempPath[..lastIndex] : tempPath[..1]); if (newPathResult.IsError) @@ -117,5 +117,21 @@ public class UnixPathStrategy : IUnixPathStrategy { return ['\0']; } + + /// + /// Returns the root portion of the given path. + /// + /// The path for which to get the root. + /// An containing the root of , or an error. + public ErrorOr GetPathRoot(FileSystemPathId path) + { + if (!IsValidPath(path)) + return Errors.FileManagement.InvalidPath; + + // On Unix-like systems, the root is always "/" + if (path.Path.StartsWith(PathSeparator)) + return new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true); + return Errors.FileManagement.InvalidPath; + } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/WindowsPathStrategy.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/WindowsPathStrategy.cs index cce1f4d0..5926a83e 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/WindowsPathStrategy.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Path/WindowsPathStrategy.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using Lumina.Domain.Common.Errors; using System.Text.RegularExpressions; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects; +using System.Linq; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path; @@ -48,7 +49,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy public ErrorOr CombinePath(FileSystemPathId path, string name) { if (name == null) - return Errors.FileManagement.NameCannotBeEmptyError; + return Errors.FileManagement.NameCannotBeEmpty; // trim any directory separator characters from the end of the path string subpath = path.Path.TrimEnd(PathSeparator); // if the name begins with a directory separator, remove it @@ -66,7 +67,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy { // Windows paths usually start with a drive letter and colon, e.g., "C:" if (!path.Path.Contains(':') || !path.Path.Contains(PathSeparator) || !char.IsLetter(path.Path[0]) || path.Path[1] != ':' || path.Path[2] != PathSeparator) - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; return ErrorOrFactory.From(GetPathSegments()); IEnumerable GetPathSegments() { @@ -96,19 +97,19 @@ public class WindowsPathStrategy : IWindowsPathStrategy { // validation: ensure the path is not null or empty if (!IsValidPath(path)) - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; // if path is just a drive letter followed by ":\", return null if (Regex.IsMatch(path.Path, @"^[a-zA-Z]:\\?$")) - return Errors.FileManagement.CannotNavigateUpError; + return Errors.FileManagement.CannotNavigateUp; // trim trailing slash for consistent processing string tempPath = path.Path; - if (tempPath.EndsWith("\\")) + if (tempPath.EndsWith('\\')) tempPath = tempPath.TrimEnd(PathSeparator); // find the last occurrence of a slash var lastIndex = tempPath.LastIndexOf(PathSeparator); // if there's no slash found (shouldn't happen due to previous steps), or if we are at the root level after trimming, return error if (lastIndex < 0) - return Errors.FileManagement.CannotNavigateUpError; + return Errors.FileManagement.CannotNavigateUp; // if we are at the drive root level after trimming, return drive root, otherwise, return the path up to the last slash ErrorOr newPathResult = FileSystemPathId.Create(lastIndex == 2 && tempPath[1] == ':' ? tempPath[..3] : tempPath[..lastIndex]); if (newPathResult.IsError) @@ -124,5 +125,39 @@ public class WindowsPathStrategy : IWindowsPathStrategy { return ['<', '>', '"', '/', '|', '?', '*']; } + + /// + /// Returns the root portion of the given path. + /// + /// The path for which to get the root. + /// An containing the root of , or an error. + public ErrorOr GetPathRoot(FileSystemPathId path) + { + if (!IsValidPath(path)) + return Errors.FileManagement.InvalidPath; + // check if the path starts with a drive letter (e.g., "C:") + if (path.Path.Length >= 2 && char.IsLetter(path.Path[0]) && path.Path[1] == ':') + { + string root = path.Path[..2]; + if (path.Path.Length > 2 && path.Path[2] == PathSeparator) + root += PathSeparator; + return new PathSegment(root, isDirectory: true, isDrive: true); + } + // check for UNC paths (e.g., "\\server\share") + if (path.Path.StartsWith('\\')) + { + var parseResult = ParsePath(path); + if (parseResult.IsError) + return parseResult.Errors; + + var segments = parseResult.Value.ToList(); + if (segments.Count >= 2) + { + string root = $@"\\{segments[0].Name}\{segments[1].Name}\"; + return new PathSegment(root, isDirectory: true, isDrive: false); + } + } + return Errors.FileManagement.InvalidPath; + } #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContext.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContext.cs index 1cf3adde..e309b93b 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContext.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContext.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path; #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContextManager.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContextManager.cs index 527249fd..c3240a80 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContextManager.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/IPlatformContextManager.cs @@ -1,6 +1,6 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Contracts.Enums.FileSystem; using System; -using Lumina.Domain.Common.Enums; #endregion namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Platform; diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/PlatformContextManager.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/PlatformContextManager.cs index 1a0c1c38..d3eb8446 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/PlatformContextManager.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/PlatformContextManager.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using System; using System.Runtime.InteropServices; #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/UnixPlatformContext.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/UnixPlatformContext.cs index dee7629a..75e5e7b2 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/UnixPlatformContext.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/UnixPlatformContext.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path; #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/WindowsPlatformContext.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/WindowsPlatformContext.cs index 3f67c41a..b8193c2b 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/WindowsPlatformContext.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/Strategies/Platform/WindowsPlatformContext.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.FileSystem; using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Strategies.Path; #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/FileSystemPathId.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/FileSystemPathId.cs index 8d3dd05a..94ccc366 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/FileSystemPathId.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/FileSystemPathId.cs @@ -49,7 +49,7 @@ public sealed class FileSystemPathId : ValueObject public static ErrorOr Create(string path) { if (string.IsNullOrWhiteSpace(path)) - return Errors.FileManagement.InvalidPathError; + return Errors.FileManagement.InvalidPath; return new FileSystemPathId(path); } #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/Thumbnail.cs b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/Thumbnail.cs index 12cb98ed..836c2598 100644 --- a/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/Thumbnail.cs +++ b/src/Lumina.Domain/Core/Aggregates/FileManagement/FileManagementAggregate/ValueObjects/Thumbnail.cs @@ -1,5 +1,5 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.PhotoLibrary; using Lumina.Domain.Common.Models.Core; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/MediaContributor.cs b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/MediaContributor.cs index 00cb0ddc..64345de3 100644 --- a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/MediaContributor.cs +++ b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/MediaContributor.cs @@ -1,10 +1,10 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using ErrorOr; -using Lumina.Domain.Common.Enums; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; +using System; +using System.Diagnostics; #endregion @@ -71,7 +71,6 @@ public class MediaContributor : AggregateRoot /// /// Creates a new instance of the class. /// - /// The unique identifier of the contributor. /// The name of the contributor. /// The created instance. public static ErrorOr Create(MediaContributorName name) diff --git a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/ContributorName.cs b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/ContributorName.cs index f58b98bb..f4e126d7 100644 --- a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/ContributorName.cs +++ b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/ContributorName.cs @@ -1,8 +1,9 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using ErrorOr; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.Primitives; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; diff --git a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorId.cs b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorId.cs index 0f67a94b..b17c5585 100644 --- a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorId.cs +++ b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorId.cs @@ -1,5 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; #endregion namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; diff --git a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorRole.cs b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorRole.cs index 170f5202..b8049abc 100644 --- a/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorRole.cs +++ b/src/Lumina.Domain/Core/Aggregates/MediaContributor/MediaContributorAggregate/ValueObjects/MediaContributorRole.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using Lumina.Domain.Common.Models.Core; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Movie.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Movie.cs index f68f4cec..0fd35d76 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Movie.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Movie.cs @@ -1,10 +1,11 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using ErrorOr; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.ValueObjects.Metadata; using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; using Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate; diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/IMovieLibraryService.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/IMovieLibraryService.cs index 5d69dd83..34d20101 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/IMovieLibraryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/IMovieLibraryService.cs @@ -1,7 +1,11 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +#endregion + namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services; /// -/// Service for managing movie libraries. +/// Interface for the service for managing movie libraries. /// public interface IMovieLibraryService { diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/MovieLibraryService.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/MovieLibraryService.cs index 31864f70..9b524a6f 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/MovieLibraryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/Services/MovieLibraryService.cs @@ -1,5 +1,13 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +#endregion + namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services; +/// +/// Service for managing movie libraries. +/// public sealed class MovieLibraryService : IMovieLibraryService { #region ==================================================================== PROPERTIES ================================================================================= diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/MovieId.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/MovieId.cs index dd166fbb..9b80e714 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/MovieId.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/MovieId.cs @@ -1,5 +1,8 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects; @@ -7,20 +10,16 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Value /// /// Value Object for the Id of a movie. /// -public sealed class MovieId : ValueObject -{ - #region ==================================================================== PROPERTIES ================================================================================= - public Guid Value { get; } - #endregion - +[DebuggerDisplay("{Value}")] +public sealed class MovieId : EntityId +{ #region ====================================================================== CTOR ===================================================================================== /// /// Initializes a new instance of the class. /// /// The value representing this object. - private MovieId(Guid value) + private MovieId(Guid value) : base(value) { - Value = value; } #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/VideoMetadata.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/VideoMetadata.cs index 0425e784..8c3ca07b 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/VideoMetadata.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/MovieLibraryAggregate/ValueObjects/VideoMetadata.cs @@ -2,6 +2,8 @@ using ErrorOr; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Common.ValueObjects.Metadata; +using System; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -98,9 +100,8 @@ public class VideoMetadata : BaseMetadata /// The optional audio codec used. /// The genres of the video. /// The tags associated with the video. - /// The list of contributors for this video. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( string title, diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/ITvShowLibraryService.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/ITvShowLibraryService.cs index c5827631..15f0fbb1 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/ITvShowLibraryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/ITvShowLibraryService.cs @@ -1,15 +1,18 @@ -namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +#endregion + +namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services; + +/// +/// Interface for the service for managing TV show libraries. +/// +public interface ITvShowLibraryService { + #region ==================================================================== PROPERTIES ================================================================================= /// - /// Interface for the service for managing TV show libraries. + /// Gets the collection of TV shows in the library. /// - public interface ITvShowLibraryService - { - #region ==================================================================== PROPERTIES ================================================================================= - /// - /// Gets the collection of TV shows in the library. - /// - public ICollection TvShows { get; } - #endregion - } + public ICollection TvShows { get; } + #endregion } \ No newline at end of file diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/TvShowLibraryService.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/TvShowLibraryService.cs index 364ef76d..595d7018 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/TvShowLibraryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/Services/TvShowLibraryService.cs @@ -1,3 +1,8 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +#endregion + namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services; /// diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs index b08ee983..f033a790 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/EpisodeId.cs @@ -1,5 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; #endregion namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects; @@ -7,20 +9,15 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Valu /// /// Value Object for the Id of an episode. /// -public sealed class EpisodeId : ValueObject +public sealed class EpisodeId : EntityId { - #region ==================================================================== PROPERTIES ================================================================================= - public Guid Value { get; } - #endregion - #region ====================================================================== CTOR ===================================================================================== /// /// Initializes a new instance of the class. /// /// The value representing this object. - private EpisodeId(Guid value) + private EpisodeId(Guid value) : base(value) { - Value = value; } #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/SeasonId.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/SeasonId.cs index 775b649d..65292632 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/SeasonId.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/SeasonId.cs @@ -1,5 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; #endregion namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects; @@ -7,20 +9,15 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Valu /// /// Value Object for the Id of a season. /// -public sealed class SeasonId : ValueObject +public sealed class SeasonId : EntityId { - #region ==================================================================== PROPERTIES ================================================================================= - public Guid Value { get; } - #endregion - #region ====================================================================== CTOR ===================================================================================== /// /// Initializes a new instance of the class. /// /// The value representing this object. - private SeasonId(Guid value) + private SeasonId(Guid value) : base(value) { - Value = value; } #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/TvShowId.cs b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/TvShowId.cs index 6ec9ccd6..50ade7c2 100644 --- a/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/TvShowId.cs +++ b/src/Lumina.Domain/Core/Aggregates/VideoLibrary/TvShowLibraryAggregate/ValueObjects/TvShowId.cs @@ -1,5 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; #endregion namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects; @@ -7,20 +9,15 @@ namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Valu /// /// Value Object for the Id of a TV show. /// -public sealed class TvShowId : ValueObject +public sealed class TvShowId : EntityId { - #region ==================================================================== PROPERTIES ================================================================================= - public Guid Value { get; } - #endregion - #region ====================================================================== CTOR ===================================================================================== /// /// Initializes a new instance of the class. /// /// The value representing this object. - private TvShowId(Guid value) + private TvShowId(Guid value) : base(value) { - Value = value; } #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Book.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Book.cs index 8059ef8d..d1588074 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Book.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Book.cs @@ -1,11 +1,13 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.BookLibrary; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; +using System; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -50,47 +52,47 @@ public sealed class Book : AggregateRoot public Optional Series { get; private set; } /// - /// Gets the ASIN (Amazon Standard Identification Number) of the book. + /// Gets the ASIN (Amazon Standard Identification Number) of the book, if applicable. /// public Optional ASIN { get; private set; } /// - /// Gets the Goodreads ID of the book. + /// Gets the Goodreads ID of the book, if applicable. /// public Optional GoodreadsId { get; private set; } /// - /// Gets the Library of Congress Control Number (LCCN) of the book. + /// Gets the Library of Congress Control Number (LCCN) of the book, if applicable. /// public Optional LCCN { get; private set; } /// - /// Gets the OCLC Number (WorldCat identifier) of the book. + /// Gets the OCLC Number (WorldCat identifier) of the book, if applicable. /// public Optional OCLCNumber { get; private set; } /// - /// Gets the Open Library ID of the book. + /// Gets the Open Library ID of the book, if applicable. /// public Optional OpenLibraryId { get; private set; } /// - /// Gets the LibraryThing ID of the book. + /// Gets the LibraryThing ID of the book, if applicable. /// public Optional LibraryThingId { get; private set; } /// - /// Gets the Google Books ID of the book. + /// Gets the Google Books ID of the book, if applicable. /// public Optional GoogleBooksId { get; private set; } /// - /// Gets the Barnes & Noble ID of the book. + /// Gets the Barnes & Noble ID of the book, if applicable. /// public Optional BarnesAndNobleId { get; private set; } /// - /// Gets the Apple Books ID of the book. + /// Gets the Apple Books ID of the book, if applicable. /// public Optional AppleBooksId { get; private set; } @@ -220,7 +222,7 @@ public sealed class Book : AggregateRoot /// The list of media contributors of the book. /// The list of ratings for the book. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( WrittenContentMetadata metadata, @@ -289,7 +291,7 @@ public sealed class Book : AggregateRoot /// The list of media contributors of the book. /// The list of ratings for the book. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( BookId id, diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Entities/BookSeries.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Entities/BookSeries.cs index 2f9822ab..1b8ca4c0 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Entities/BookSeries.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Entities/BookSeries.cs @@ -1,9 +1,10 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using ErrorOr; using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Models.Core; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities; @@ -65,7 +66,7 @@ public sealed class BookSeries : Entity /// The current status of the book series. /// The books of the book series. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( BookSeriesId id, @@ -89,7 +90,7 @@ public sealed class BookSeries : Entity /// The current status of the book series. /// The books of the book series. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( WrittenContentMetadata metadata, @@ -108,7 +109,7 @@ public sealed class BookSeries : Entity /// Adds a book to the series. /// /// The book to be added. - /// An representing either a successful operation, or an error. + /// An representing either a successful operation, or an error. public ErrorOr AddBook(Book book) { if (_books.Contains(book)) @@ -121,7 +122,7 @@ public sealed class BookSeries : Entity /// Removes a book from the series. /// /// The book to be removed. - /// An representing either a successful operation, or an error. + /// An representing either a successful operation, or an error. public ErrorOr RemoveBook(Book book) { if (!_books.Contains(book)) diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/BookLibraryService.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/BookLibraryService.cs index 1973e39f..2a4fcc98 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/BookLibraryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/BookLibraryService.cs @@ -1,3 +1,8 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Collections.Generic; +#endregion + namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services; /// diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/IBookLibraryService.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/IBookLibraryService.cs index d3eb478b..d0299042 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/IBookLibraryService.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/Services/IBookLibraryService.cs @@ -1,7 +1,11 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +#endregion + namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services; /// -/// Service for managing book libraries. +/// Interface for the service for managing book libraries. /// public interface IBookLibraryService { diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookId.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookId.cs index f1e90d40..10c239ed 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookId.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookId.cs @@ -1,5 +1,8 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; @@ -7,6 +10,7 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega /// /// Value Object for the Id of a book. /// +[DebuggerDisplay("{Value}")] public sealed class BookId : EntityId { #region ====================================================================== CTOR ===================================================================================== diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookLibraryId.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookLibraryId.cs index a54b0b0e..d5d31d0c 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookLibraryId.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookLibraryId.cs @@ -1,6 +1,9 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; @@ -8,20 +11,16 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega /// /// Value Object for the Id of a book library. /// -public sealed class BookLibraryId : ValueObject +[DebuggerDisplay("{Value}")] +public sealed class BookLibraryId : EntityId { - #region ==================================================================== PROPERTIES ================================================================================= - public Guid Value { get; } - #endregion - #region ====================================================================== CTOR ===================================================================================== /// /// Initializes a new instance of the class. /// /// The value representing this object. - private BookLibraryId(Guid value) + private BookLibraryId(Guid value) : base(value) { - Value = value; } #endregion diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookRating.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookRating.cs index f05f4d54..b8eff9c4 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookRating.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookRating.cs @@ -1,10 +1,11 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics; using ErrorOr; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Common.ValueObjects.Metadata; -using Lumina.Domain.Common.Errors; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; @@ -46,7 +47,7 @@ public class BookRating : Rating /// The optional source of the rating. /// The optional number of votes or reviews. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create(decimal value, decimal maxValue, Optional source, Optional voteCount) { diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookSeriesId.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookSeriesId.cs index 63f7bc37..f78024f4 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookSeriesId.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/BookSeriesId.cs @@ -1,5 +1,8 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Domain.Common.Models.Core; +using System; +using System.Collections.Generic; +using System.Diagnostics; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; @@ -7,6 +10,7 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega /// /// Value Object for the Id of a book series. /// +[DebuggerDisplay("{Value}")] public sealed class BookSeriesId : ValueObject { #region ==================================================================== PROPERTIES ================================================================================= diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/Isbn.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/Isbn.cs index 242d8a3b..95a6f82f 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/Isbn.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/Isbn.cs @@ -1,9 +1,11 @@ #region ========================================================================= USING ===================================================================================== -using System.Text.RegularExpressions; using ErrorOr; -using Lumina.Domain.Common.Enums; -using Lumina.Domain.Common.Models.Core; +using Lumina.Contracts.Enums.BookLibrary; using Lumina.Domain.Common.Errors; +using Lumina.Domain.Common.Models.Core; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text.RegularExpressions; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; @@ -11,6 +13,7 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega /// /// Value Object for the ISBN of a book. /// +[DebuggerDisplay("{Value} ({Format})")] public sealed class Isbn : ValueObject { #region ================================================================== FIELD MEMBERS ================================================================================ diff --git a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/WrittenContentMetadata.cs b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/WrittenContentMetadata.cs index c498248c..b6c0ec80 100644 --- a/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/WrittenContentMetadata.cs +++ b/src/Lumina.Domain/Core/Aggregates/WrittenContentLibrary/BookLibraryAggregate/ValueObjects/WrittenContentMetadata.cs @@ -1,9 +1,10 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; +using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Common.ValueObjects.Metadata; +using System.Collections.Generic; using System.Diagnostics; -using Lumina.Domain.Common.Errors; #endregion namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; @@ -73,7 +74,7 @@ public class WrittenContentMetadata : BaseMetadata /// The publisher of the written content. /// The number of pages in the written content. /// - /// An containing either a successfully created , or an error message. + /// An containing either a successfully created , or an error message. /// public static ErrorOr Create( string title, diff --git a/src/Lumina.Domain/Lumina.Domain.csproj b/src/Lumina.Domain/Lumina.Domain.csproj index cf0f9fd9..852c7da2 100644 --- a/src/Lumina.Domain/Lumina.Domain.csproj +++ b/src/Lumina.Domain/Lumina.Domain.csproj @@ -4,7 +4,7 @@ net8.0 disable enable - ..\..\bin\ + $(SolutionDir)..\bin\server\ false @@ -22,7 +22,7 @@ - + diff --git a/src/Lumina.Infrastructure/Common/DependencyInjection/SharedConfiguration.cs b/src/Lumina.Infrastructure/Common/DependencyInjection/SharedConfiguration.cs index 45267055..1b2250f5 100644 --- a/src/Lumina.Infrastructure/Common/DependencyInjection/SharedConfiguration.cs +++ b/src/Lumina.Infrastructure/Common/DependencyInjection/SharedConfiguration.cs @@ -1,9 +1,10 @@ #region ========================================================================= USING ===================================================================================== -using System.Reflection; using Lumina.Infrastructure.Common.Models.Configuration; using Lumina.Infrastructure.Common.Utilities; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using System.IO; +using System.Reflection; #endregion namespace Lumina.Infrastructure.Common.DependencyInjection; diff --git a/src/Lumina.Infrastructure/Common/Validation/FluentValidationOptions.cs b/src/Lumina.Infrastructure/Common/Validation/FluentValidationOptions.cs index 913c38f0..e7d828fd 100644 --- a/src/Lumina.Infrastructure/Common/Validation/FluentValidationOptions.cs +++ b/src/Lumina.Infrastructure/Common/Validation/FluentValidationOptions.cs @@ -1,6 +1,8 @@ #region ========================================================================= USING ===================================================================================== using FluentValidation; using Microsoft.Extensions.Options; +using System; +using System.Linq; #endregion namespace Lumina.Infrastructure.Common.Validation; @@ -8,7 +10,7 @@ namespace Lumina.Infrastructure.Common.Validation; /// /// Provides options for fluent validation of a specific options type. /// -/// The type of options being validated +/// The type of options being validated. public class FluentValidationOptions : IValidateOptions where TOptions : class { #region ================================================================== FIELD MEMBERS ================================================================================ diff --git a/src/Lumina.Infrastructure/Lumina.Infrastructure.csproj b/src/Lumina.Infrastructure/Lumina.Infrastructure.csproj index 4b26f513..318a9632 100644 --- a/src/Lumina.Infrastructure/Lumina.Infrastructure.csproj +++ b/src/Lumina.Infrastructure/Lumina.Infrastructure.csproj @@ -2,9 +2,9 @@ net8.0 - enable + disable enable - ..\..\bin\ + $(SolutionDir)..\bin\server\ false diff --git a/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs b/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs index dbafc65b..b00573e2 100644 --- a/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs +++ b/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; diff --git a/src/Lumina.Presentation.Api/Common/Contracts/Books/AddBookRequest.cs b/src/Lumina.Presentation.Api/Common/Contracts/Books/AddBookRequest.cs deleted file mode 100644 index f97fe46f..00000000 --- a/src/Lumina.Presentation.Api/Common/Contracts/Books/AddBookRequest.cs +++ /dev/null @@ -1,30 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Contributors; -using Lumina.Domain.Common.Enums; -#endregion - -namespace Lumina.Presentation.Api.Common.Contracts.Books; - -/// -/// Represents a request to add a book. -/// -public record AddBookRequest( - WrittenContentMetadataDto? Metadata, - BookFormat? Format, - string? Edition, - int? VolumeNumber, - BookSeriesDto? Series, - string? ASIN, - string? GoodreadsId, - string? LCCN, - string? OCLCNumber, - string? OpenLibraryId, - string? LibraryThingId, - string? GoogleBooksId, - string? BarnesAndNobleId, - string? AppleBooksId, - List? ISBNs, - List? Contributors, - List? Ratings -); \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Common/Converters/OptionalJsonConverterFactory.cs b/src/Lumina.Presentation.Api/Common/Converters/OptionalJsonConverterFactory.cs deleted file mode 100644 index e69de29b..00000000 diff --git a/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs b/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs index b662c601..2166147e 100644 --- a/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs +++ b/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerConfiguration.cs @@ -1,4 +1,7 @@ #region ========================================================================= USING ===================================================================================== +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System.IO; using System.Reflection; #endregion @@ -26,7 +29,6 @@ internal static class PresentationApiLayerConfiguration configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); configuration.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true); - return services; } #endregion diff --git a/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerServices.cs b/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerServices.cs index a4298d23..657d5a21 100644 --- a/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerServices.cs +++ b/src/Lumina.Presentation.Api/Common/DependencyInjection/PresentationApiLayerServices.cs @@ -1,5 +1,4 @@ #region ========================================================================= USING ===================================================================================== -using System.Text.Json.Serialization; using Lumina.Application.Common.Converters; using Lumina.Presentation.Api.Common.Configuration; using Lumina.Presentation.Api.Common.Errors; @@ -7,6 +6,8 @@ using Mapster; using MapsterMapper; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Infrastructure; +using Microsoft.Extensions.DependencyInjection; +using System.Text.Json.Serialization; #endregion namespace Lumina.Presentation.Api.Common.DependencyInjection; diff --git a/src/Lumina.Presentation.Api/Common/Errors/CustomProblemDetailsFactory.cs b/src/Lumina.Presentation.Api/Common/Errors/CustomProblemDetailsFactory.cs index df06cf75..cc2189e9 100644 --- a/src/Lumina.Presentation.Api/Common/Errors/CustomProblemDetailsFactory.cs +++ b/src/Lumina.Presentation.Api/Common/Errors/CustomProblemDetailsFactory.cs @@ -1,39 +1,40 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; using Lumina.Presentation.Api.Common.Http; -using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Infrastructure; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; #endregion namespace Lumina.Presentation.Api.Common.Errors; /// -/// Problem details abstract factory which adds custom properties to the default implementation provided by Microsoft +/// Problem details factory which adds custom properties to the default implementation provided by Microsoft. /// -/// -/// Creation Date: 14th of July, 2023 -/// public class CustomProblemDetailsFactory : ProblemDetailsFactory { #region ================================================================== FIELD MEMBERS ================================================================================ - private readonly ApiBehaviorOptions options; - private readonly Action? configure; + private readonly ApiBehaviorOptions _options; + private readonly Action? _configure; #endregion #region ====================================================================== CTOR ===================================================================================== /// - /// Overload C-tor + /// Initializes a new instance of the class. /// - /// Injected service for retrieving ApiBehaviorOptions - /// Injected service for retrieving ProblemDetailsOptions - /// Thrown when the value of options (if any) is null + /// Injected service for retrieving . + /// Injected service for retrieving . + /// Thrown when the value of options (if any) is . public CustomProblemDetailsFactory(IOptions options, IOptions? problemDetailsOptions = null) { - this.options = options?.Value ?? throw new ArgumentNullException(nameof(options)); - configure = problemDetailsOptions?.Value?.CustomizeProblemDetails; + _options = options?.Value ?? throw new ArgumentNullException(nameof(options)); + _configure = problemDetailsOptions?.Value?.CustomizeProblemDetails; } #endregion @@ -103,7 +104,7 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory private void ApplyProblemDetailsDefaults(HttpContext httpContext, ProblemDetails problemDetails, int statusCode) { problemDetails.Status ??= statusCode; - if (options.ClientErrorMapping.TryGetValue(statusCode, out var clientErrorData)) + if (_options.ClientErrorMapping.TryGetValue(statusCode, out var clientErrorData)) { problemDetails.Title ??= clientErrorData.Title; problemDetails.Type ??= clientErrorData.Link; @@ -116,13 +117,13 @@ public class CustomProblemDetailsFactory : ProblemDetailsFactory // add any extra custom properties if (errors is not null) { - problemDetails.Extensions.Add("errors", errors.Select(e => + problemDetails.Extensions.Add("errors", errors.Select(error => { - return e.Code; + return error.Code; })); } //problemDetails.Extensions.Add("errorCodes", errors.Select(e => e.Type.ToString())); - configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails }); + _configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails }); } #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Common/Mapping/BookMappingConfig.cs b/src/Lumina.Presentation.Api/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs similarity index 88% rename from src/Lumina.Presentation.Api/Common/Mapping/BookMappingConfig.cs rename to src/Lumina.Presentation.Api/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs index 0f72be94..74399f98 100644 --- a/src/Lumina.Presentation.Api/Common/Mapping/BookMappingConfig.cs +++ b/src/Lumina.Presentation.Api/Common/Mapping/WrittenContentLibrary/BookLibrary/BookMappingConfig.cs @@ -1,10 +1,10 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; -using Lumina.Presentation.Api.Common.Contracts.Books; +using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; using Mapster; #endregion -namespace Lumina.Presentation.Api.Common.Mapping; +namespace Lumina.Presentation.Api.Common.Mapping.WrittenContentLibrary.BookLibrary; /// /// Mapping configuration for books between the API request object and the command object. @@ -24,7 +24,6 @@ public class BookMappingConfig : IRegister .Map(dest => dest.LCCN, src => src.LCCN) .Map(dest => dest.OCLCNumber, src => src.OCLCNumber) .MapToConstructor(true); - } #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Common/ModelBinders/UrlStringBinder.cs b/src/Lumina.Presentation.Api/Common/ModelBinders/UrlStringBinder.cs new file mode 100644 index 00000000..de4ab200 --- /dev/null +++ b/src/Lumina.Presentation.Api/Common/ModelBinders/UrlStringBinder.cs @@ -0,0 +1,41 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.AspNetCore.Mvc.ModelBinding; +using System; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Common.ModelBinders; + +/// +/// Custom model binder for URL parameters. For some reason, the default binder converts "%20" to "+", instead of " ". +/// +public class UrlStringBinder : IModelBinder +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Binds a model to a value by using the specified controller context and binding context. + /// + /// The context within which to bind the model. + /// A task representing the bind operation. + public Task BindModelAsync(ModelBindingContext bindingContext) + { + if (bindingContext is null) + throw new ArgumentNullException(nameof(bindingContext)); + string modelName = bindingContext.ModelName; + // try to fetch the value of the argument by name + var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName); + if (valueProviderResult == ValueProviderResult.None) + return Task.CompletedTask; + string? value = valueProviderResult.FirstValue; + if (value is null) + { + bindingContext.Result = ModelBindingResult.Failed(); + return Task.CompletedTask; + } + // do the custom decoding here + value = Uri.UnescapeDataString(value); + bindingContext.Result = ModelBindingResult.Success(value); + return Task.CompletedTask; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/Common/ApiController.cs b/src/Lumina.Presentation.Api/Core/Controllers/Common/ApiController.cs index fbd10685..487fd5e9 100644 --- a/src/Lumina.Presentation.Api/Core/Controllers/Common/ApiController.cs +++ b/src/Lumina.Presentation.Api/Core/Controllers/Common/ApiController.cs @@ -1,8 +1,11 @@ #region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Presentation.Api.Common.Http; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; +using System.Collections.Generic; +using System.Linq; #endregion namespace Lumina.Presentation.Api.Core.Controllers.Common; diff --git a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/DirectoriesController.cs b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/DirectoriesController.cs new file mode 100644 index 00000000..87b89865 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/DirectoriesController.cs @@ -0,0 +1,79 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Application.Core.FileManagement.Directories.Queries; +using Lumina.Contracts.Responses.FileManagement; +using Lumina.Presentation.Api.Common.ModelBinders; +using Lumina.Presentation.Api.Core.Controllers.Common; +using Mediator; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Threading; +#endregion + +namespace Lumina.Presentation.Api.Core.Controllers.FileManagement; + +/// +/// Controller for managing file system directories. +/// +[ApiVersion("1.0")] +[Route("api/v{version:apiVersion}/[controller]")] +public class DirectoriesController : ApiController +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly ISender _mediator; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for mediating commands and queries. + public DirectoriesController(ISender mediator) + { + _mediator = mediator; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the tree of expanded directories leading up to , with the additional list of drives, and children of the last child directory. + /// + /// The path for which to get the directory tree. + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-directory-tree")] + public async IAsyncEnumerable GetDirectoryTree([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken) + { + ErrorOr> result = await _mediator.Send(new GetDirectoryTreeQuery(path), cancellationToken).ConfigureAwait(false); + if (!result.IsError && result.Value is not null) + { + foreach (var treeNode in result.Value) + { + if (cancellationToken.IsCancellationRequested) + yield break; + yield return treeNode; + } + } + } + + /// + /// Gets the directories of . + /// + /// The path for which to get the directories. + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-directories")] + public async IAsyncEnumerable GetDirectories([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken) + { + ErrorOr> result = await _mediator.Send(new GetDirectoriesQuery(path), cancellationToken).ConfigureAwait(false); + if (!result.IsError && result.Value is not null) + { + foreach (var directory in result.Value) + { + if (cancellationToken.IsCancellationRequested) + yield break; + yield return directory; + } + } + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/DrivesController.cs b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/DrivesController.cs new file mode 100644 index 00000000..ee7ad06b --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/DrivesController.cs @@ -0,0 +1,49 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Application.Core.FileManagement.Drives.Queries; +using Lumina.Contracts.Responses.FileManagement; +using Lumina.Presentation.Api.Core.Controllers.Common; +using Mediator; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Core.Controllers.FileManagement; + +/// +/// Controller for managing file system drives. +/// +[ApiVersion("1.0")] +[Route("api/v{version:apiVersion}/[controller]")] +public class DrivesController : ApiController +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly ISender _mediator; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for mediating commands and queries. + public DrivesController(ISender mediator) + { + _mediator = mediator; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Controller action for getting the list of all file system drives. + /// + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-drives")] + public async Task GetDrives(CancellationToken cancellationToken) + { + ErrorOr> result = await _mediator.Send(new GetDrivesQuery(), cancellationToken).ConfigureAwait(false); + return result.Match(result => Ok(result), errors => Problem(errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/FileSystemController.cs b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/FileSystemController.cs new file mode 100644 index 00000000..e9460516 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/FileSystemController.cs @@ -0,0 +1,46 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Core.FileManagement.FileSystem.Queries; +using Lumina.Presentation.Api.Core.Controllers.Common; +using Mediator; +using Microsoft.AspNetCore.Mvc; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Core.Controllers.FileManagement; + +/// +/// Controller for managing file systems. +/// +[ApiVersion("1.0")] +[Route("api/v{version:apiVersion}/file-system")] +public class FileSystemController : ApiController +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly ISender _mediator; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for mediating commands and queries. + public FileSystemController(ISender mediator) + { + _mediator = mediator; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the type of the file system. + /// + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-type")] + public async Task GetType(CancellationToken cancellationToken) + { + var platformType = await _mediator.Send(new GetFileSystemQuery(), cancellationToken).ConfigureAwait(false); + return Ok(platformType); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/FilesController.cs b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/FilesController.cs new file mode 100644 index 00000000..b5b925a2 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/FilesController.cs @@ -0,0 +1,56 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Core.FileManagement.Files.Queries; +using Lumina.Contracts.Responses.FileManagement; +using Lumina.Presentation.Api.Common.ModelBinders; +using Lumina.Presentation.Api.Core.Controllers.Common; +using MapsterMapper; +using Mediator; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Threading; +#endregion + +namespace Lumina.Presentation.Api.Core.Controllers.FileManagement; + +/// +/// Controller for managing file system files. +/// +[ApiVersion("1.0")] +[Route("api/v{version:apiVersion}/[controller]")] +public class FilesController : ApiController +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly ISender _mediator; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for mediating commands and queries. + public FilesController(ISender mediator, IMapper mapper) + { + _mediator = mediator; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the files of . + /// + /// The path for which to get the files. + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-files")] + public async IAsyncEnumerable GetFiles([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, [EnumeratorCancellation] CancellationToken cancellationToken) + { + var result = await _mediator.Send(new GetFilesQuery(path), cancellationToken).ConfigureAwait(false); + foreach (var file in result.Value) + { + if (cancellationToken.IsCancellationRequested) + yield break; + yield return file; + } + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs new file mode 100644 index 00000000..4bf7ab83 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Controllers/FileManagement/PathController.cs @@ -0,0 +1,89 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Application.Core.FileManagement.Paths.Commands; +using Lumina.Application.Core.FileManagement.Paths.Queries; +using Lumina.Contracts.Responses.FileManagement; +using Lumina.Presentation.Api.Common.ModelBinders; +using Lumina.Presentation.Api.Core.Controllers.Common; +using MapsterMapper; +using Mediator; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Core.Controllers.FileManagement; + +/// +/// Controller for managing file system paths. +/// +[ApiVersion("1.0")] +[Route("api/v{version:apiVersion}/[controller]")] +public class PathController : ApiController +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly ISender _mediator; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Injected service for mediating commands and queries. + public PathController(ISender mediator) + { + _mediator = mediator; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Gets the root of . + /// + /// The path for which to get the root. + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-path-root")] + public async Task GetPathRoot([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken) + { + ErrorOr result = await _mediator.Send(new GetPathRootQuery(path), cancellationToken).ConfigureAwait(false); + return result.Match(result => Ok(result), errors => Problem(errors)); + } + + /// + /// Combines with . + /// + /// The path to combine to. + /// The path to combine with. + /// Cancellation token that can be used to stop the execution. + [HttpGet("combine")] + public async Task CombinePath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string originalPath, [FromQuery, ModelBinder(typeof(UrlStringBinder))] string newPath, CancellationToken cancellationToken) + { + ErrorOr result = await _mediator.Send(new CombinePathCommand(originalPath, newPath), cancellationToken).ConfigureAwait(false); + return result.Match(result => Ok(result), errors => Problem(errors)); + } + + /// + /// Gets the path separator character of the file system. + /// + /// Cancellation token that can be used to stop the execution. + [HttpGet("get-path-separator")] + public async Task GetPathSeparator(CancellationToken cancellationToken) + { + PathSeparatorResponse result = await _mediator.Send(new GetPathSeparatorQuery(), cancellationToken).ConfigureAwait(false); + return Ok(result); + } + + /// + /// Gets the path components of . + /// + /// The path for which to get the path segments. + /// Cancellation token that can be used to stop the execution. + [HttpGet("split")] + public async Task SplitPath([FromQuery, ModelBinder(typeof(UrlStringBinder))] string path, CancellationToken cancellationToken) + { + ErrorOr> result = await _mediator.Send(new SplitPathCommand(path), cancellationToken).ConfigureAwait(false); + return result.Match(result => Ok(result), errors => Problem(errors)); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Api/Core/Controllers/Maintenance/HealthController.cs b/src/Lumina.Presentation.Api/Core/Controllers/Maintenance/HealthController.cs new file mode 100644 index 00000000..15f9b0d9 --- /dev/null +++ b/src/Lumina.Presentation.Api/Core/Controllers/Maintenance/HealthController.cs @@ -0,0 +1,26 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Api.Core.Controllers.Common; +using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; +#endregion + +namespace Lumina.Presentation.Api.Core.Controllers.Maintenance; + +/// +/// Controller for health checks. +/// +[Route("[controller]")] +public class HealthController : ApiController +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Checks if the application is healthy. + /// + [HttpGet("check-health")] + public async Task CheckHealth() + { + // TODO: to be implemented + return Ok(); + } + #endregion +} diff --git a/src/Lumina.Presentation.Api/Core/Controllers/WrittenContentLibrary/BookLibrary/Books/BooksController.cs b/src/Lumina.Presentation.Api/Core/Controllers/WrittenContentLibrary/BookLibrary/Books/BooksController.cs index e962ebe8..7cbdf4a8 100644 --- a/src/Lumina.Presentation.Api/Core/Controllers/WrittenContentLibrary/BookLibrary/Books/BooksController.cs +++ b/src/Lumina.Presentation.Api/Core/Controllers/WrittenContentLibrary/BookLibrary/Books/BooksController.cs @@ -1,11 +1,12 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Queries; -using Lumina.Presentation.Api.Common.Contracts.Books; +using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; using Lumina.Presentation.Api.Core.Controllers.Common; using MapsterMapper; using Mediator; using Microsoft.AspNetCore.Mvc; +using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Api.Core.Controllers.WrittenContentLibrary.BookLibrary.Books; @@ -26,7 +27,7 @@ public class BooksController : ApiController /// /// Initializes a new instance of the class. /// - /// Injecting service for mediating commands and queries. + /// Injected service for mediating commands and queries. /// Injected service for mapping objects. public BooksController(ISender mediator, IMapper mapper) { @@ -42,7 +43,7 @@ public class BooksController : ApiController [HttpGet()] public async Task GetBooks() { - var result = await _mediator.Send(new GetBooksQuery()); + var result = await _mediator.Send(new GetBooksQuery()).ConfigureAwait(false); return result.Match(result => Ok(result), errors => Problem(errors)); } @@ -53,7 +54,7 @@ public class BooksController : ApiController [HttpPost()] public async Task AddBook(AddBookRequest request) { - var result = await _mediator.Send(_mapper.Map(request)); + var result = await _mediator.Send(_mapper.Map(request)).ConfigureAwait(false); return result.Match(result => Created($"/api/v1/books/{result.Id}", result), errors => Problem(errors)); } #endregion diff --git a/src/Lumina.Presentation.Api/Dockerfile b/src/Lumina.Presentation.Api/Dockerfile index 710c6ca3..8d78a4ec 100644 --- a/src/Lumina.Presentation.Api/Dockerfile +++ b/src/Lumina.Presentation.Api/Dockerfile @@ -15,6 +15,7 @@ WORKDIR /src COPY ["AssemblyInfo_Shared.cs", "."] COPY ["Lumina.Presentation.Api/Lumina.Presentation.Api.csproj", "Lumina.Presentation.Api/"] COPY ["Lumina.Application/Lumina.Application.csproj", "Lumina.Application/"] +COPY ["Lumina.Contracts/Lumina.Contracts.csproj", "Lumina.Contracts/"] COPY ["Lumina.Domain/Lumina.Domain.csproj", "Lumina.Domain/"] COPY ["Lumina.Infrastructure/Lumina.Infrastructure.csproj", "Lumina.Infrastructure/"] COPY ["Lumina.DataAccess/Lumina.DataAccess.csproj", "Lumina.DataAccess/"] @@ -24,6 +25,7 @@ RUN dotnet restore "./Lumina.Presentation.Api/Lumina.Presentation.Api.csproj" /p # build the project COPY ["Lumina.Presentation.Api/", "Lumina.Presentation.Api/"] COPY ["Lumina.Application/", "Lumina.Application/"] +COPY ["Lumina.Contracts/", "Lumina.Contracts/"] COPY ["Lumina.Domain/", "Lumina.Domain/"] COPY ["Lumina.Infrastructure/", "Lumina.Infrastructure/"] COPY ["Lumina.DataAccess/", "Lumina.DataAccess/"] diff --git a/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj b/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj index 505eb995..55eae991 100644 --- a/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj +++ b/src/Lumina.Presentation.Api/Lumina.Presentation.Api.csproj @@ -48,7 +48,9 @@ + + diff --git a/src/Lumina.Presentation.Api/Lumina.Presentation.Api.http b/src/Lumina.Presentation.Api/Lumina.Presentation.Api.http deleted file mode 100644 index cdd659ca..00000000 --- a/src/Lumina.Presentation.Api/Lumina.Presentation.Api.http +++ /dev/null @@ -1,6 +0,0 @@ -@Lumina.Presentation.Api_HostAddress = http://localhost:5214 - -GET {{Lumina.Presentation.Api_HostAddress}}/weatherforecast/ -Accept: application/json - -### diff --git a/src/Lumina.Presentation.Api/Program.cs b/src/Lumina.Presentation.Api/Program.cs index 0a6c3d00..2de42179 100644 --- a/src/Lumina.Presentation.Api/Program.cs +++ b/src/Lumina.Presentation.Api/Program.cs @@ -1,8 +1,12 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Api.Common.DependencyInjection; using Lumina.Application.Common.DependencyInjection; +using Lumina.DataAccess.Common.DependencyInjection; using Lumina.Infrastructure.Common.DependencyInjection; -using Lumina.DataAccess.Common.DependencyInjection; +using Lumina.Presentation.Api.Common.DependencyInjection; +using Lumina.Domain.Common.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Api; @@ -17,17 +21,18 @@ public class Program /// Application entry point. /// /// Optional command line arguments. - static void Main(string[] args) + public static async Task Main(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.Services.BindSharedConfiguration(builder.Configuration); builder.Services.BindPresentationApiLayerConfiguration(builder.Configuration); - builder.Services.AddApplicationLayerServices(); builder.Services.AddPresentationApiLayerServices(); + builder.Services.AddApplicationLayerServices(); builder.Services.AddInfrastructureLayerServices(); builder.Services.AddDataAccessLayerServices(); + builder.Services.AddDomainLayerServices(); var app = builder.Build(); @@ -42,11 +47,11 @@ public class Program app.UseSwaggerUI(); } - app.UseHttpsRedirection(); + //app.UseHttpsRedirection(); app.MapControllers(); - app.Run(); + await app.RunAsync().ConfigureAwait(false); } #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs b/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs index 2200aaf1..8ca404aa 100644 --- a/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs +++ b/src/Lumina.Presentation.Web/Common/Api/ApiHttpClient.cs @@ -2,12 +2,19 @@ using Lumina.Presentation.Web.Common.Exceptions; using Lumina.Presentation.Web.Common.Models.Common; using Lumina.Presentation.Web.Common.Models.Configuration; -using Lumina.Presentation.Web.Common.Models.FileSystem; +using Lumina.Presentation.Web.Common.Models.FileManagement; +using Microsoft.AspNetCore.Components.WebAssembly.Http; using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Net.Http; using System.Net.Http.Headers; +using System.Runtime.CompilerServices; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Web.Common.Api; @@ -33,12 +40,13 @@ public class ApiHttpClient : IApiHttpClient _httpClient = httpClient; // read the API server configuration values from the configuration, and assign them to the injected client var serverConfigurationModel = serverConfigurationOptions.Value; - httpClient.BaseAddress = new Uri(serverConfigurationModel.BaseAddress + ":" + serverConfigurationModel.Port + "/api/v1/"); + httpClient.BaseAddress = new Uri($"{serverConfigurationModel.BaseAddress}:{serverConfigurationModel.Port}/api/v{serverConfigurationModel.ApiVersion}/"); _jsonOptions = new JsonSerializerOptions { PropertyNameCaseInsensitive = true, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, + Converters = { new JsonStringEnumConverter() } }; } #endregion @@ -57,7 +65,39 @@ public class ApiHttpClient : IApiHttpClient using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); if (!string.IsNullOrEmpty(token)) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); - return await SendRequestAsync(request, cancellationToken); + return await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + } + + /// + /// Sends a GET request to the specified as an asynchronous operation and returns the result as a streamable response. + /// + /// The expected type of the response content. + /// The API endpoint where the request is being sent. + /// The token used for authentication with the API. + /// Cancellation token that can be used to stop the execution. + /// An object, which allows for asynchronous iteration over the deserialized items. + public async IAsyncEnumerable GetAsyncEnumerable(string endpoint, string? token = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) + { + using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); + // HttpClient is implemented differently in Blazor WASM, because there are no sockets in the browser, so its BrowserHttpHandler is implemented on top of Fetch API, + // which can provide response content in one of two forms: BrowserHttpContent, which is based on arrayBuffer method (this means that it will always read the response stream to its completion, + // before making the content available), and StreamContent that is wrapping WasmHttpReadStream, which is based on readable streams (this one allows for reading response as it comes). + // WasmHttpReadStream can only work when WebAssemblyEnableStreamingResponse is enabled on request, and only on browsers that support it + request.SetBrowserResponseStreamingEnabled(true); + + if (!string.IsNullOrEmpty(token)) + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); + // send the request and expect only headers initially - this prevents the client from buffering the entire response + using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + response.EnsureSuccessStatusCode(); + await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); + // Deserialize the JSON content asynchronously as an enumerable of TResponse items + await foreach (var item in JsonSerializer.DeserializeAsyncEnumerable(stream, _jsonOptions, cancellationToken).ConfigureAwait(false)) + { + if (cancellationToken.IsCancellationRequested) + yield break; + yield return item; + } } /// @@ -72,11 +112,11 @@ public class ApiHttpClient : IApiHttpClient using var request = new HttpRequestMessage(HttpMethod.Get, endpoint); if (!string.IsNullOrEmpty(token)) request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); - using var response = await _httpClient.SendAsync(request, cancellationToken); + using var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { // read the content as a string, for error messages - var content = await response.Content.ReadAsStringAsync(cancellationToken); + var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); ProblemDetailsModel? problemDetails = null; try { @@ -86,7 +126,7 @@ public class ApiHttpClient : IApiHttpClient throw new ApiException(problemDetails, response.StatusCode); } // if the response is successful, read it as a byte array - byte[] responseContent = await response.Content.ReadAsByteArrayAsync(cancellationToken); + byte[] responseContent = await response.Content.ReadAsByteArrayAsync(cancellationToken).ConfigureAwait(false); string contentType = response.Content.Headers.ContentType?.ToString() ?? "application/octet-stream"; return new BlobDataModel { Data = responseContent, ContentType = contentType }; } @@ -104,7 +144,7 @@ public class ApiHttpClient : IApiHttpClient using var request = new HttpRequestMessage(HttpMethod.Delete, endpoint); if (!string.IsNullOrEmpty(token)) _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - return await SendRequestAsync(request, cancellationToken); + return await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); } /// @@ -123,7 +163,7 @@ public class ApiHttpClient : IApiHttpClient if (!string.IsNullOrEmpty(token)) _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json"); - return await SendRequestAsync(request, cancellationToken); + return await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); } /// @@ -142,23 +182,23 @@ public class ApiHttpClient : IApiHttpClient if (!string.IsNullOrEmpty(token)) _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); request.Content = new StringContent(JsonSerializer.Serialize(data, _jsonOptions), Encoding.UTF8, "application/json"); - return await SendRequestAsync(request, cancellationToken); + return await SendRequestAsync(request, cancellationToken).ConfigureAwait(false); } - + /// /// Sends an HTTP request and deserializes the response into the specified type if the request is successful. /// If the request fails, it attempts to deserialize the response content into a and throws an . /// /// The expected type of the response content. /// The to be sent. - /// A token to cancel the operation. + /// Cancellation token that can be used to stop the execution. /// The deserialized response content as an object of type . /// Thrown if the response is not successful, with the if available. private async Task SendRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // send the HTTP request and read the response - var response = await _httpClient.SendAsync(request, cancellationToken); - var content = await response.Content.ReadAsStringAsync(cancellationToken); + var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); + var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); // if the response is successful, deserialize the content to TResponse and return it if (response.IsSuccessStatusCode) return JsonSerializer.Deserialize(content, _jsonOptions)!; diff --git a/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs b/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs index 12c004a0..c33b457b 100644 --- a/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs +++ b/src/Lumina.Presentation.Web/Common/Api/IApiHttpClient.cs @@ -1,5 +1,8 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.FileSystem; +using Lumina.Presentation.Web.Common.Models.FileManagement; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Web.Common.Api; @@ -20,6 +23,16 @@ public interface IApiHttpClient /// The deserialized response containing the result of the GET request. Task GetAsync(string endpoint, string? token = null, CancellationToken cancellationToken = default); + /// + /// Sends a GET request to the specified as an asynchronous operation and returns the result as a streamable response. + /// + /// The expected type of the response content. + /// The API endpoint where the request is being sent. + /// The token used for authentication with the API. + /// Cancellation token that can be used to stop the execution. + /// An object, which allows for asynchronous iteration over the deserialized items. + IAsyncEnumerable GetAsyncEnumerable(string endpoint, string? token = null, CancellationToken cancellationToken = default); + /// /// Sends a GET request to the specified as an asynchronous operation and returns the result. /// diff --git a/src/Lumina.Presentation.Web/Common/Contracts/Books/AddBookRequest.cs b/src/Lumina.Presentation.Web/Common/Contracts/Books/AddBookRequest.cs deleted file mode 100644 index c86890a5..00000000 --- a/src/Lumina.Presentation.Web/Common/Contracts/Books/AddBookRequest.cs +++ /dev/null @@ -1,33 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.Books; -using Lumina.Presentation.Web.Common.Models.Contributors; -using Lumina.Presentation.Web.Common.Enums; -#endregion - -namespace Lumina.Presentation.Web.Common.Contracts.Books; - -/// -/// Represents a request to add a book. -/// -public class AddBookRequest -{ - #region ==================================================================== PROPERTIES ================================================================================= - public WrittenContentMetadataDto? Metadata { get; set; } - public BookFormat? Format { get; set; } - public string? Edition { get; set; } - public int? VolumeNumber { get; set; } - public BookSeriesDto? Series { get; set; } - public string? ASIN { get; set; } - public string? GoodreadsId { get; set; } - public string? LCCN { get; set; } - public string? OCLCNumber { get; set; } - public string? OpenLibraryId { get; set; } - public string? LibraryThingId { get; set; } - public string? GoogleBooksId { get; set; } - public string? BarnesAndNobleId { get; set; } - public string? AppleBooksId { get; set; } - public List? ISBNs { get; set; } - public List? Contributors { get; set; } - public List? Ratings { get; set; } - #endregion -} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs index a5d777ce..fc07f3d9 100644 --- a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs +++ b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerConfiguration.cs @@ -1,7 +1,8 @@ using Lumina.Presentation.Web.Common.Models.Configuration; using Lumina.Presentation.Web.Common.Utilities; -using Lumina.Presentation.Web.Common.Validators; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; namespace Lumina.Presentation.Web.Common.DependencyInjection; diff --git a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs index 860c8141..62fec8ba 100644 --- a/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs +++ b/src/Lumina.Presentation.Web/Common/DependencyInjection/PresentationWebLayerServices.cs @@ -1,9 +1,12 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Core.Services.UI; -using Lumina.Presentation.Web.Common.Api; -using Polly; -using System.Net; using FluentValidation; +using Lumina.Presentation.Web.Common.Api; +using Lumina.Presentation.Web.Core.Services.UI; +using Microsoft.Extensions.DependencyInjection; +using Polly; +using System; +using System.Net; +using System.Net.Http; #endregion namespace Lumina.Presentation.Web.Common.DependencyInjection; diff --git a/src/Lumina.Presentation.Web/Common/Enums/AudioLibrary/AudioContentType.cs b/src/Lumina.Presentation.Web/Common/Enums/AudioLibrary/AudioContentType.cs new file mode 100644 index 00000000..b87391dd --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/AudioLibrary/AudioContentType.cs @@ -0,0 +1,57 @@ +namespace Lumina.Presentation.Web.Common.Enums.AudioLibrary; + +/// +/// Enumeration for the types of audio content libraries. +/// +public enum AudioContentType +{ + /// + /// A musical composition typically consisting of vocals and/or instruments. + /// + Music, + + /// + /// A recording of a book or other written work being read aloud. + /// + AudioBook, + + /// + /// An audio recording of a live musical or spoken word performance. + /// + LivePerformance, + + /// + /// A recorded conversation where one person asks questions and another provides answers. + /// + Interview, + + /// + /// A new performance or recording of a previously released song. + /// + Cover, + + /// + /// An alternative version of a recorded song, typically with altered instrumentation or structure. + /// + Remix, + + /// + /// An audio recording used to create a specific acoustic environment or impression. + /// + Soundeffect, + + /// + /// A digital audio file made available on the internet for downloading to a computer or mobile device. + /// + Podcast, + + /// + /// A regularly scheduled broadcast program consisting of music, talk, or other audio content. + /// + RadioShow, + + /// + /// A collection of music used as background sound for a movie, TV show, video game, or other media. + /// + Soundtrack, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/AudioRatingSource.cs b/src/Lumina.Presentation.Web/Common/Enums/AudioLibrary/AudioRatingSource.cs similarity index 91% rename from src/Lumina.Presentation.Web/Common/Enums/AudioRatingSource.cs rename to src/Lumina.Presentation.Web/Common/Enums/AudioLibrary/AudioRatingSource.cs index 96ac24bf..cc3d2f79 100644 --- a/src/Lumina.Presentation.Web/Common/Enums/AudioRatingSource.cs +++ b/src/Lumina.Presentation.Web/Common/Enums/AudioLibrary/AudioRatingSource.cs @@ -1,4 +1,4 @@ -namespace Lumina.Presentation.Web.Common.Enums; +namespace Lumina.Presentation.Web.Common.Enums.AudioLibrary; /// /// Enumeration for the various sources of audio ratings. diff --git a/src/Lumina.Presentation.Web/Common/Enums/BookFormat.cs b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/BookFormat.cs similarity index 96% rename from src/Lumina.Presentation.Web/Common/Enums/BookFormat.cs rename to src/Lumina.Presentation.Web/Common/Enums/BookLibrary/BookFormat.cs index 90badca1..75c117fd 100644 --- a/src/Lumina.Presentation.Web/Common/Enums/BookFormat.cs +++ b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/BookFormat.cs @@ -1,4 +1,4 @@ -namespace Lumina.Presentation.Web.Common.Enums; +namespace Lumina.Presentation.Web.Common.Enums.BookLibrary; /// /// Enumeration for various book formats. diff --git a/src/Lumina.Presentation.Web/Common/Enums/BookRatingSource.cs b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/BookRatingSource.cs similarity index 92% rename from src/Lumina.Presentation.Web/Common/Enums/BookRatingSource.cs rename to src/Lumina.Presentation.Web/Common/Enums/BookLibrary/BookRatingSource.cs index a00aca2b..67206970 100644 --- a/src/Lumina.Presentation.Web/Common/Enums/BookRatingSource.cs +++ b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/BookRatingSource.cs @@ -1,4 +1,4 @@ -namespace Lumina.Presentation.Web.Common.Enums; +namespace Lumina.Presentation.Web.Common.Enums.BookLibrary; /// /// Enumeration for the various sources of book ratings. diff --git a/src/Lumina.Presentation.Web/Common/Enums/IsbnFormat.cs b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/IsbnFormat.cs similarity index 88% rename from src/Lumina.Presentation.Web/Common/Enums/IsbnFormat.cs rename to src/Lumina.Presentation.Web/Common/Enums/BookLibrary/IsbnFormat.cs index 312f9d5c..13f9e3b8 100644 --- a/src/Lumina.Presentation.Web/Common/Enums/IsbnFormat.cs +++ b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/IsbnFormat.cs @@ -1,4 +1,4 @@ -namespace Lumina.Presentation.Web.Common.Enums; +namespace Lumina.Presentation.Web.Common.Enums.BookLibrary; /// /// Enumeration for the different ISBN (International Standard Book Number) formats. diff --git a/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/WrittenContentType.cs b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/WrittenContentType.cs new file mode 100644 index 00000000..4f257b4d --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/BookLibrary/WrittenContentType.cs @@ -0,0 +1,62 @@ +namespace Lumina.Presentation.Web.Common.Enums.BookLibrary; + +/// +/// Enumeration for the types of written content libraries. +/// +public enum WrittenContentType +{ + /// + /// A printed or written literary work. + /// + Book, + + /// + /// An electronic version of a printed book. + /// + EBook, + + /// + /// A set of related books published in succession. + /// + BookSeries, + + /// + /// A magazine or book containing sequential art in the form of a narrative. + /// + ComicBook, + + /// + /// A set of related comic books published in succession. + /// + ComicSeries, + + /// + /// A periodical publication containing articles, stories, and other content. + /// + Magazine, + + /// + /// A style of Japanese comic books and graphic novels. + /// + Manga, + + /// + /// A novel in comic-strip format, typically with sophisticated artwork and complex storylines. + /// + GraphicNovel, + + /// + /// A scholarly article presenting original research or analysis. + /// + AcademicPaper, + + /// + /// A handwritten or printed form of musical notation. + /// + SheetMusic, + + /// + /// A script for a film, television program, or other visual media. + /// + Screenplay, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/FileSystem/FileSystemItemType.cs b/src/Lumina.Presentation.Web/Common/Enums/FileSystem/FileSystemItemType.cs new file mode 100644 index 00000000..6cb874c5 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/FileSystem/FileSystemItemType.cs @@ -0,0 +1,22 @@ +namespace Lumina.Presentation.Web.Common.Enums.FileSystem; + +/// +/// Enumeration for the types of file system elements. +/// +public enum FileSystemItemType +{ + /// + /// Represents a file system root, which can be a drive on Windows, and a path separator on Unix. + /// + Root, + + /// + /// Represents a directory, which is a directory that can contain other directories or files. + /// + Directory, + + /// + /// Represents a file, which is a document, executable, or other data stored on the file system. + /// + File +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/FileSystem/PlatformType.cs b/src/Lumina.Presentation.Web/Common/Enums/FileSystem/PlatformType.cs new file mode 100644 index 00000000..1802b28b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/FileSystem/PlatformType.cs @@ -0,0 +1,17 @@ +namespace Lumina.Presentation.Web.Common.Enums.FileSystem; + +/// +/// Enumeration for platform types. +/// +public enum PlatformType +{ + /// + /// Represents Unix-based operating systems, including Linux and macOS. + /// + Unix, + + /// + /// Represents Microsoft Windows operating systems. + /// + Windows, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/Library/LibraryType.cs b/src/Lumina.Presentation.Web/Common/Enums/Library/LibraryType.cs new file mode 100644 index 00000000..763a2b66 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/Library/LibraryType.cs @@ -0,0 +1,32 @@ +namespace Lumina.Presentation.Web.Common.Enums.Library; + +/// +/// Enumeration for the types of libraries. +/// +public enum LibraryType +{ + /// + /// Content that is written, such as books, articles, or other written works. + /// + WrittenContent, + + /// + /// Content that is video, such as movies, TV shows, or other video works. + /// + VideoContent, + + /// + /// Content that is audio, such as podcasts, radio shows, or other audio works. + /// + AudioContent, + + /// + /// Content that is visual, such as images, paintings, or other visual works. + /// + VisualContent, + + /// + /// Content that is miscellaneous, such as lyrics, movie posters, or other miscellaneous works. + /// + MiscellaneousContent, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/Library/MiscellaneousContentType.cs b/src/Lumina.Presentation.Web/Common/Enums/Library/MiscellaneousContentType.cs new file mode 100644 index 00000000..aeb9f9df --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/Library/MiscellaneousContentType.cs @@ -0,0 +1,12 @@ +namespace Lumina.Presentation.Web.Common.Enums.Library; + +/// +/// Enumeration for the types of miscellaneous content libraries. +/// +public enum MiscellaneousContentType +{ + /// + /// A collection of media that does not fit into any other category. + /// + Other, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/PhotoLibrary/VisualContentType.cs b/src/Lumina.Presentation.Web/Common/Enums/PhotoLibrary/VisualContentType.cs new file mode 100644 index 00000000..d8861e58 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/PhotoLibrary/VisualContentType.cs @@ -0,0 +1,12 @@ +namespace Lumina.Presentation.Web.Common.Enums.PhotoLibrary; + +/// +/// Enumeration for the types of visual content libraries. +/// +public enum VisualContentType +{ + /// + /// A collection of photographs organized together. + /// + PhotoAlbum, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/VideoLibrary/VideoContentType.cs b/src/Lumina.Presentation.Web/Common/Enums/VideoLibrary/VideoContentType.cs new file mode 100644 index 00000000..36e054ca --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Enums/VideoLibrary/VideoContentType.cs @@ -0,0 +1,62 @@ +namespace Lumina.Presentation.Web.Common.Enums.VideoLibrary; + +/// +/// Enumeration for the types of video content libraries. +/// +public enum VideoContentType +{ + /// + /// A series of related episodes broadcast on television or streaming platforms. + /// + TvShow, + + /// + /// A feature-length film produced for cinema or home viewing. + /// + Movie, + + /// + /// A collection of related films released in succession. + /// + FilmSeries, + + /// + /// A collection of related films, TV shows, and other media sharing a fictional universe. + /// + FilmFranchise, + + /// + /// A live musical performance recorded on video. + /// + Concert, + + /// + /// A non-fictional film or TV program presenting facts and information about a specific subject. + /// + Documentary, + + /// + /// An instructional video designed to teach a skill or provide information on a specific topic. + /// + Tutorial, + + /// + /// Privately recorded videos, often for personal use or sharing with friends and family. + /// + Personal, + + /// + /// Japanese animated productions, typically characterized by colorful graphics and vibrant characters. + /// + Anime, + + /// + /// Videos hosted on or originating from the YouTube platform. + /// + Youtube, + + /// + /// A short video, typically set to music, such as a music video or promotional clip. + /// + Videoclip, +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Enums/VideoRatingSource.cs b/src/Lumina.Presentation.Web/Common/Enums/VideoLibrary/VideoRatingSource.cs similarity index 93% rename from src/Lumina.Presentation.Web/Common/Enums/VideoRatingSource.cs rename to src/Lumina.Presentation.Web/Common/Enums/VideoLibrary/VideoRatingSource.cs index a80b3859..9bfc66a5 100644 --- a/src/Lumina.Presentation.Web/Common/Enums/VideoRatingSource.cs +++ b/src/Lumina.Presentation.Web/Common/Enums/VideoLibrary/VideoRatingSource.cs @@ -1,4 +1,4 @@ -namespace Lumina.Presentation.Web.Common.Enums; +namespace Lumina.Presentation.Web.Common.Enums.VideoLibrary; /// /// Enumeration for the various sources of video ratings. diff --git a/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs b/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs index 51da0043..a658737a 100644 --- a/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs +++ b/src/Lumina.Presentation.Web/Common/Exceptions/ApiException.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Presentation.Web.Common.Models.Common; +using System; using System.Net; #endregion diff --git a/src/Lumina.Presentation.Web/Common/Models/Books/WrittenContentMetadataDto.cs b/src/Lumina.Presentation.Web/Common/Models/Books/WrittenContentMetadataDto.cs deleted file mode 100644 index a8a9602b..00000000 --- a/src/Lumina.Presentation.Web/Common/Models/Books/WrittenContentMetadataDto.cs +++ /dev/null @@ -1,63 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Models.Common; -#endregion - -namespace Lumina.Presentation.Web.Common.Models.Books; - -/// -/// Represents written content metadata. -/// -public class WrittenContentMetadataDto -{ - #region ==================================================================== PROPERTIES ================================================================================= - /// - /// Gets the title of the media item. - /// - public string? Title { get; set; } - - /// - /// Gets the original title of the media item. - /// - public string? OriginalTitle { get; set; } - - /// - /// Gets the optional description of the media item. - /// - public string? Description { get; set; } - - /// - /// Gets the release information of the media item. - /// - public ReleaseInfoDto? ReleaseInfo { get; set; } - - /// - /// Gets the list of genres associated with the media item. - /// - public List? Genres { get; set; } - - /// - /// Gets the list of tags associated with the media item. - /// - public List? Tags { get; set; } - - /// - /// Gets the optional language of the media item. - /// - public LanguageInfoDto? Language { get; set; } - - /// - /// Gets the optional original language of the media item. - /// - public LanguageInfoDto? OriginalLanguage { get; set; } - - /// - /// Gets the publisher of the written content. - /// - public string? Publisher { get; set; } - - /// - /// Gets the number of pages in the written content. - /// - public int? PageCount { get; set; } - #endregion -} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Common/GenreDto.cs b/src/Lumina.Presentation.Web/Common/Models/Common/GenreModel.cs similarity index 63% rename from src/Lumina.Presentation.Web/Common/Models/Common/GenreDto.cs rename to src/Lumina.Presentation.Web/Common/Models/Common/GenreModel.cs index 5f52f3f7..cd110fa9 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Common/GenreDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/Common/GenreModel.cs @@ -1,9 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + namespace Lumina.Presentation.Web.Common.Models.Common; /// /// Represents a request to get genre information. /// -public class GenreDto +[DebuggerDisplay("{Name}")] +public class GenreModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Common/LanguageInfoDto.cs b/src/Lumina.Presentation.Web/Common/Models/Common/LanguageInfoModel.cs similarity index 72% rename from src/Lumina.Presentation.Web/Common/Models/Common/LanguageInfoDto.cs rename to src/Lumina.Presentation.Web/Common/Models/Common/LanguageInfoModel.cs index edd58d9f..6b8d26ea 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Common/LanguageInfoDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/Common/LanguageInfoModel.cs @@ -1,9 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + namespace Lumina.Presentation.Web.Common.Models.Common; /// /// Represents a request to get language information. /// -public class LanguageInfoDto +[DebuggerDisplay("{LanguageName}")] +public class LanguageInfoModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Common/ProblemDetailsModel.cs b/src/Lumina.Presentation.Web/Common/Models/Common/ProblemDetailsModel.cs new file mode 100644 index 00000000..7466e2cc --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/Common/ProblemDetailsModel.cs @@ -0,0 +1,54 @@ +#region ========================================================================= USING ===================================================================================== +using System.Collections.Generic; +using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Serialization; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.Common; + +/// +/// Model that follows the RFC 7807 standard for problem details in HTTP APIs. +/// +[DebuggerDisplay("{Title} ({Status})")] +public class ProblemDetailsModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the URI reference that identifies the problem type. + /// + [JsonPropertyName("type")] + public string? Type { get; set; } + + /// + /// Gets or sets a short, human-readable summary of the problem type. + /// + [JsonPropertyName("title")] + public string? Title { get; set; } + + /// + /// Gets or sets the HTTP status code generated by the server for this occurrence of the problem. + /// + [JsonPropertyName("status")] + public int? Status { get; set; } + + /// + /// Gets or sets a detailed explanation specific to this occurrence of the problem. + /// + [JsonPropertyName("detail")] + public string? Detail { get; set; } + + /// + /// Gets or sets a URI reference that identifies the specific occurrence of the problem. + /// + [JsonPropertyName("instance")] + public string? Instance { get; set; } + + /// + /// Gets or sets additional extension data that may be included with the problem details. + /// This allows for including extra, non-standard fields in the problem details. + /// + [JsonExtensionData] + public IDictionary? Extensions { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Common/RatingDto.cs b/src/Lumina.Presentation.Web/Common/Models/Common/RatingModel.cs similarity index 71% rename from src/Lumina.Presentation.Web/Common/Models/Common/RatingDto.cs rename to src/Lumina.Presentation.Web/Common/Models/Common/RatingModel.cs index 7393b25d..23d7ed8e 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Common/RatingDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/Common/RatingModel.cs @@ -1,9 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + namespace Lumina.Presentation.Web.Common.Models.Common; /// /// Represents a rating. /// -public abstract class RatingDto +[DebuggerDisplay("{Value}/{MaxValue}")] +public abstract class RatingModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Common/ReleaseInfoDto.cs b/src/Lumina.Presentation.Web/Common/Models/Common/ReleaseInfoModel.cs similarity index 81% rename from src/Lumina.Presentation.Web/Common/Models/Common/ReleaseInfoDto.cs rename to src/Lumina.Presentation.Web/Common/Models/Common/ReleaseInfoModel.cs index 50e3210f..b6c7470f 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Common/ReleaseInfoDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/Common/ReleaseInfoModel.cs @@ -1,9 +1,15 @@ +#region ========================================================================= USING ===================================================================================== +using System; +using System.Diagnostics; +#endregion + namespace Lumina.Presentation.Web.Common.Models.Common; /// /// Represents a request to get release information. /// -public class ReleaseInfoDto +[DebuggerDisplay("{OriginalReleaseDate}")] +public class ReleaseInfoModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Common/TagDto.cs b/src/Lumina.Presentation.Web/Common/Models/Common/TagModel.cs similarity index 63% rename from src/Lumina.Presentation.Web/Common/Models/Common/TagDto.cs rename to src/Lumina.Presentation.Web/Common/Models/Common/TagModel.cs index b0158858..bb71a72a 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Common/TagDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/Common/TagModel.cs @@ -1,9 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + namespace Lumina.Presentation.Web.Common.Models.Common; /// /// Represents a request to get tag information. /// -public class TagDto +[DebuggerDisplay("{Name}")] +public class TagModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Configuration/ServerConfigurationModel.cs b/src/Lumina.Presentation.Web/Common/Models/Configuration/ServerConfigurationModel.cs index 96e938b5..1602a3ef 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Configuration/ServerConfigurationModel.cs +++ b/src/Lumina.Presentation.Web/Common/Models/Configuration/ServerConfigurationModel.cs @@ -1,8 +1,13 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + namespace Lumina.Presentation.Web.Common.Models.Configuration; /// /// Model for deserializing server configuration settings. /// +[DebuggerDisplay("{SectionName}")] public class ServerConfigurationModel { #region ================================================================== FIELD MEMBERS ================================================================================ @@ -10,6 +15,11 @@ public class ServerConfigurationModel #endregion #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the remote API server path. + /// + public required char ApiVersion { get; init; } + /// /// Gets or sets the remote API server path. /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorDto.cs b/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorDto.cs deleted file mode 100644 index 4fb49846..00000000 --- a/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorDto.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Lumina.Presentation.Web.Common.Models.Contributors; - -/// -/// Represents a media contributor. -/// -public class MediaContributorDto -{ - #region ==================================================================== PROPERTIES ================================================================================= - /// - /// Gets the name of the contributor. - /// - public MediaContributorNameDto? Name { get; set; } - - /// - /// Gets the role of the contributor. - /// - public MediaContributorRoleDto? Role { get; set; } - #endregion -} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/BlobDataModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/BlobDataModel.cs new file mode 100644 index 00000000..2117418a --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/BlobDataModel.cs @@ -0,0 +1,24 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.FileManagement; + +/// +/// Represents a model for storing binary data (blob). +/// +[DebuggerDisplay("{ContentType} (Data.Length)")] +public class BlobDataModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the binary data as a byte array. + /// + public byte[] Data { get; set; } = null!; + + /// + /// Gets or sets the content type (MIME type) of the blob data, such as "image/png" for an image or "application/pdf" for a PDF document. + /// + public string ContentType { get; set; } = null!; + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemItemModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemItemModel.cs new file mode 100644 index 00000000..4d201622 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemItemModel.cs @@ -0,0 +1,40 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.FileSystem; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.FileManagement; + +/// +/// Model for files and directories displayed in custom directory/file browser dialogs. +/// +[DebuggerDisplay("{Path}")] +public class FileSystemItemModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the full path to the file system item. + /// + public string? Path { get; set; } + + /// + /// Gets the type of the file system element. + /// + public FileSystemItemType ItemType { get; set; } + + /// + /// Gets or sets the file extension of the item, if applicable (e.g., ".txt", ".jpg"). + /// + public string? Extension { get; set; } + + /// + /// Gets or sets the source path or identifier for the icon representing the file system item. + /// + public string? IconSource { get; set; } + + /// + /// Gets or sets a friendly name for the file system item, which may be a user-friendly display name. + /// + public string? FriendlyName { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTreeNodeModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTreeNodeModel.cs new file mode 100644 index 00000000..5cd0806b --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTreeNodeModel.cs @@ -0,0 +1,46 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.FileSystem; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.FileManagement; + +/// +/// Generic file system node. +/// +[DebuggerDisplay("{Path}")] +public class FileSystemTreeNodeModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the full path of the file or directory. + /// + public string Path { get; set; } = null!; + + /// + /// Gets or sets the name of the file or directory. + /// + public string Name { get; set; } = null!; + + /// + /// Gets or sets the type of the item, indicating whether it is a file, directory, or drive. + /// + public FileSystemItemType ItemType { get; set; } + + /// + /// Gets or sets a value indicating whether the node is expanded. + /// + public bool IsExpanded { get; set; } + + /// + /// Gets or sets a value indicating whether the child nodes have been loaded. + /// + public bool ChildrenLoaded { get; set; } + + /// + /// Gets or sets the list of child nodes. + /// + public List Children { get; set; } = []; + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs new file mode 100644 index 00000000..8fe57906 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/FileSystemTypeModel.cs @@ -0,0 +1,20 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.FileSystem; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.FileManagement; + +/// +/// Model containing the file system platform type. +/// +[DebuggerDisplay("{PlatformType}")] +public class FileSystemTypeModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the file system platform type. + /// + public PlatformType PlatformType { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Books/BookSeriesDto.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathSegmentModel.cs similarity index 51% rename from src/Lumina.Presentation.Web/Common/Models/Books/BookSeriesDto.cs rename to src/Lumina.Presentation.Web/Common/Models/FileManagement/PathSegmentModel.cs index c3b00466..19fb1396 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Books/BookSeriesDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathSegmentModel.cs @@ -1,14 +1,14 @@ -namespace Lumina.Presentation.Web.Common.Models.Books; +namespace Lumina.Presentation.Web.Common.Models.FileManagement; /// -/// Represents a request to get book series information. +/// Represents a response containing a file system path. /// -public class BookSeriesDto +public class PathSegmentModel { #region ==================================================================== PROPERTIES ================================================================================= /// - /// Gets the title of the book series. + /// Gets or sets the returned path. /// - public string? Title { get; set; } + public string Path { get; set; } = null!; #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathSeparatorModel.cs b/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathSeparatorModel.cs new file mode 100644 index 00000000..d3f4d071 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/FileManagement/PathSeparatorModel.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.FileManagement; + +/// +/// A model representing a file system path separator. +/// +/// The system's path separator. +[DebuggerDisplay("{Separator}")] +public record PathSeparatorModel( + string Separator +); \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Libraries/LibraryModel.cs b/src/Lumina.Presentation.Web/Common/Models/Libraries/LibraryModel.cs new file mode 100644 index 00000000..fc7f81ba --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/Libraries/LibraryModel.cs @@ -0,0 +1,37 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.Library; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.Libraries; + +/// +/// Represents a library element. +/// +[DebuggerDisplay("{Title}")] +public class LibraryModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the unique identifier of the library. + /// + public Guid? Id { get; set; } + + /// + /// Gets or sets the title of the library. + /// + public string? Title { get; set; } + + /// + /// Gets or sets the type of the library. + /// + public LibraryType? LibraryType { get; set; } + + /// + /// Gets or sets the collection of directories that contain the library files. + /// + public List Paths { get; set; } = []; + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorModel.cs b/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorModel.cs new file mode 100644 index 00000000..0201f404 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorModel.cs @@ -0,0 +1,25 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; + +#endregion + +namespace Lumina.Presentation.Web.Common.Models.MediaContributors; + +/// +/// Represents a media contributor. +/// +[DebuggerDisplay("{Name}")] +public class MediaContributorModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the name of the contributor. + /// + public MediaContributorNameModel? Name { get; set; } + + /// + /// Gets the role of the contributor. + /// + public MediaContributorRoleModel? Role { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorNameDto.cs b/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorNameModel.cs similarity index 60% rename from src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorNameDto.cs rename to src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorNameModel.cs index f54968ae..80952f3a 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorNameDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorNameModel.cs @@ -1,9 +1,14 @@ -namespace Lumina.Presentation.Web.Common.Models.Contributors; +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.MediaContributors; /// /// Represents a media contributor name. /// -public class MediaContributorNameDto +[DebuggerDisplay("{DisplayName}")] +public class MediaContributorNameModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorRoleDto.cs b/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorRoleModel.cs similarity index 59% rename from src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorRoleDto.cs rename to src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorRoleModel.cs index 9a46ceff..728887f3 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Contributors/MediaContributorRoleDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/MediaContributors/MediaContributorRoleModel.cs @@ -1,9 +1,14 @@ -namespace Lumina.Presentation.Web.Common.Models.Contributors; +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.MediaContributors; /// /// Represents a media contributor role. /// -public class MediaContributorRoleDto +[DebuggerDisplay("{Name}")] +public class MediaContributorRoleModel { #region ==================================================================== PROPERTIES ================================================================================= /// diff --git a/src/Lumina.Presentation.Web/Common/Models/UI/ComboboxItem.cs b/src/Lumina.Presentation.Web/Common/Models/UI/ComboboxItem.cs index 7243f4cd..0d8bc5b9 100644 --- a/src/Lumina.Presentation.Web/Common/Models/UI/ComboboxItem.cs +++ b/src/Lumina.Presentation.Web/Common/Models/UI/ComboboxItem.cs @@ -1,9 +1,14 @@ -namespace Lumina.Presentation.Web.Common.Models.UI; +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.UI; /// /// Represents an item in a combobox. /// /// The type used for the property of the item. +[DebuggerDisplay("{Text}")] public class ComboboxItem { #region ==================================================================== PROPERTIES ================================================================================= @@ -16,5 +21,10 @@ public class ComboboxItem /// Gets or sets the value of the item, that is used by the application. /// public TValue? Value { get; set; } + + /// + /// Gets or sets the property indicating whether this element can be selected or not. + /// + public bool IsEnabled { get; set; } = true; #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookModel.cs b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookModel.cs new file mode 100644 index 00000000..03450de9 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookModel.cs @@ -0,0 +1,208 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Models.Common; +using System; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a book. +/// +[DebuggerDisplay("{Title}")] +public class BookModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the Id of the media item. + /// + public Guid Id { get; init; } + + /// + /// Gets the title of the media item. + /// + public string Title { get; init; } = null!; + + /// + /// Gets the original title of the media item. + /// + public string? OriginalTitle { get; init; } + + /// + /// Gets the optional description of the media item. + /// + public string? Description { get; init; } + + /// + /// Gets the optional original release date of the media item. + /// + public DateOnly? OriginalReleaseDate { get; init; } + + /// + /// Gets the optional original release year of the media item. + /// This is useful when only the year of original release is known. + /// + public int? OriginalReleaseYear { get; init; } + + /// + /// Gets the optional re-release or reissue date of the media item. + /// + public DateOnly? ReReleaseDate { get; init; } + + /// + /// Gets the optional re-release or reissue year of the media item. + /// + public int? ReReleaseYear { get; init; } + + /// + /// Gets the optional country or region of release. + /// + public string? ReleaseCountry { get; init; } + + /// + /// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0") + /// + public string? ReleaseVersion { get; init; } + + /// + /// Gets the ISO 639-1 two-letter language code. + /// + public string? LanguageCode { get; init; } + + /// + /// Gets the full name of the language in English. + /// + public string? LanguageName { get; init; } + + /// + /// Gets an optional native name of the language. + /// + public string? LanguageNativeName { get; init; } + + /// + /// Gets the optional ISO 639-1 two-letter original language code. + /// + public string? OriginalLanguageCode { get; init; } + + /// + /// Gets the optional full name of the original language in English. + /// + public string? OriginalLanguageName { get; init; } + + /// + /// Gets an optional native name of the original language. + /// + public string? OriginalLanguageNativeName { get; init; } + + /// + /// Gets the list of tags associated with the media item. + /// + public HashSet Tags { get; set; } = []; + + /// + /// Gets the list of genres associated with the media item. + /// + public HashSet Genres { get; set; } = []; + + /// + /// Gets the publisher of the written content. + /// + public string? Publisher { get; init; } + + /// + /// Gets the number of pages in the written content. + /// + public int? PageCount { get; init; } + + /// + /// Gets the format of the book (e.g., Hardcover, Paperback), if applicable. + /// + public string Format { get; init; } = null!; + + /// + /// Gets the edition of the book, if applicable. + /// + public string? Edition { get; init; } + + /// + /// Gets the volume or book number in the series, if applicable. + /// + public int? VolumeNumber { get; init; } + + /// + /// Gets the series id, if the book is part of a series. + /// + //public Guid? BookSeriesId { get; init; } = null; + + /// + /// Gets the ASIN (Amazon Standard Identification Number) of the book. + /// + public string? ASIN { get; init; } = null!; + + /// + /// Gets the Goodreads ID of the book. + /// + public string? GoodreadsId { get; init; } = null!; + + /// + /// Gets the Library of Congress Control Number (LCCN) of the book. + /// + public string? LCCN { get; init; } = null!; + + /// + /// Gets the OCLC Number (WorldCat identifier) of the book. + /// + public string? OCLCNumber { get; init; } = null!; + + /// + /// Gets the Open Library ID of the book. + /// + public string? OpenLibraryId { get; init; } = null!; + + /// + /// Gets the LibraryThing ID of the book. + /// + public string? LibraryThingId { get; init; } = null!; + + /// + /// Gets the Google Books ID of the book. + /// + public string? GoogleBooksId { get; init; } = null!; + + /// + /// Gets the Barnes & Noble ID of the book. + /// + public string? BarnesAndNobleId { get; init; } = null!; + + /// + /// Gets the Apple Books ID of the book. + /// + public string? AppleBooksId { get; init; } = null!; + + /// + /// Gets the list of ISBN (International Standard Book Number) of the book. + /// + public List ISBNs { get; set; } = []; + + /// + /// Gets the list of media contributors (actors, directors, etc) starring in this book. + /// + //public List ContributorIds { get; init; } = []; + + /// + /// Gets the list of ratings for this book. + /// + public List Ratings { get; init; } = []; + + /// + /// Gets the time and date when the entity was added. + /// + public DateTime Created { get; set; } + + /// + /// Gets the optional time and date when the entity was updated. + /// + public DateTime? Updated { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Books/BookRatingDto.cs b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookRatingModel.cs similarity index 62% rename from src/Lumina.Presentation.Web/Common/Models/Books/BookRatingDto.cs rename to src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookRatingModel.cs index 2f5a3e44..f6ce8cd0 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Books/BookRatingDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookRatingModel.cs @@ -1,18 +1,20 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.BookLibrary; using Lumina.Presentation.Web.Common.Models.Common; -using Lumina.Presentation.Web.Common.Enums; +using System.Diagnostics; #endregion -namespace Lumina.Presentation.Web.Common.Models.Books; +namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary; /// /// Represents a book rating. /// -public class BookRatingDto : RatingDto +[DebuggerDisplay("{Value}/{MaxValue}")] +public class BookRatingModel : RatingModel { #region ==================================================================== PROPERTIES ================================================================================= /// - /// Gets the optional source of the rating (e.g., "Goodreads", "Amazon"). + /// Gets or sets the source of the book rating (e.g., a specific website or platform). /// public BookRatingSource? Source { get; set; } #endregion diff --git a/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookSeriesModel.cs b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookSeriesModel.cs new file mode 100644 index 00000000..81150b32 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/BookSeriesModel.cs @@ -0,0 +1,19 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a request to get book series information. +/// +[DebuggerDisplay("{Title}")] +public class BookSeriesModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the title of the book series. + /// + public string? Title { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Models/Books/IsbnDto.cs b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/IsbnModel.cs similarity index 64% rename from src/Lumina.Presentation.Web/Common/Models/Books/IsbnDto.cs rename to src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/IsbnModel.cs index 2b895ffe..344bc48d 100644 --- a/src/Lumina.Presentation.Web/Common/Models/Books/IsbnDto.cs +++ b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/BookLibrary/IsbnModel.cs @@ -1,22 +1,24 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Presentation.Web.Common.Enums; +using Lumina.Presentation.Web.Common.Enums.BookLibrary; +using System.Diagnostics; #endregion -namespace Lumina.Presentation.Web.Common.Models.Books; +namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary; /// /// Represents a request to get ISBN information. /// -public class IsbnDto +[DebuggerDisplay("{Value} ({Format})")] +public class IsbnModel { #region ==================================================================== PROPERTIES ================================================================================= /// - /// Gets the value of the ISBN. + /// Gets or sets the ISBN value. /// public string? Value { get; set; } /// - /// Gets the format of the ISBN. + /// Gets or sets the format of the ISBN (e.g., ISBN-10 or ISBN-13). /// public IsbnFormat? Format { get; set; } #endregion diff --git a/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/WrittenContentMetadataModel.cs b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/WrittenContentMetadataModel.cs new file mode 100644 index 00000000..a54939c2 --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Models/WrittenContentLibrary/WrittenContentMetadataModel.cs @@ -0,0 +1,66 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Models.Common; +using System.Collections.Generic; +using System.Diagnostics; +#endregion + +namespace Lumina.Presentation.Web.Common.Models.WrittenContentLibrary; + +/// +/// Represents written content metadata. +/// +[DebuggerDisplay("{Title}")] +public class WrittenContentMetadataModel +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the title of the written content. + /// + public string? Title { get; set; } + + /// + /// Gets or sets the original title of the written content, if different from the current title. + /// + public string? OriginalTitle { get; set; } + + /// + /// Gets or sets a brief description or summary of the written content. + /// + public string? Description { get; set; } + + /// + /// Gets or sets the release information, including release date and other relevant details. + /// + public ReleaseInfoModel? ReleaseInfo { get; set; } + + /// + /// Gets or sets the list of genres associated with the written content. + /// + public List? Genres { get; set; } + + /// + /// Gets or sets the list of tags that further describe or categorize the written content. + /// + public List? Tags { get; set; } + + /// + /// Gets or sets the language in which the written content is written. + /// + public LanguageInfoModel? Language { get; set; } + + /// + /// Gets or sets the original language of the written content, if it has been translated. + /// + public LanguageInfoModel? OriginalLanguage { get; set; } + + /// + /// Gets or sets the name of the publisher of the written content. + /// + public string? Publisher { get; set; } + + /// + /// Gets or sets the number of pages in the written content. + /// + public int? PageCount { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Requests/WrittenContentLibrary/BookLibrary/AddBookRequest.cs b/src/Lumina.Presentation.Web/Common/Requests/WrittenContentLibrary/BookLibrary/AddBookRequest.cs new file mode 100644 index 00000000..068f283e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Requests/WrittenContentLibrary/BookLibrary/AddBookRequest.cs @@ -0,0 +1,102 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.Enums.BookLibrary; +using Lumina.Presentation.Web.Common.Models.MediaContributors; +using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary; +using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary; +using System.Collections.Generic; +#endregion + +namespace Lumina.Presentation.Web.Common.Requests.WrittenContentLibrary.BookLibrary; + +/// +/// Represents a request to add a book. +/// +public class AddBookRequest +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets or sets the written content metadata of the book. + /// + public WrittenContentMetadataModel? Metadata { get; set; } + + /// + /// Gets or sets the format of the book (e.g., Hardcover, Paperback), if applicable. + /// + public BookFormat? Format { get; set; } + + /// + /// Gets or sets the edition of the book, if applicable. + /// + public string? Edition { get; set; } + + /// + /// Gets or sets the volume or book number in the series, if applicable. + /// + public int? VolumeNumber { get; set; } + + /// + /// Gets or sets the series name, if the book is part of a series. + /// + public BookSeriesModel? Series { get; set; } + + /// + /// Gets or sets the ASIN (Amazon Standard Identification Number) of the book, if applicable. + /// + public string? ASIN { get; set; } + + /// + /// Gets or sets the Goodreads ID of the book, if applicable. + /// + public string? GoodreadsId { get; set; } + + /// + /// Gets or sets the Library of Congress Control Number (LCCN) of the book, if applicable. + /// + public string? LCCN { get; set; } + + /// + /// Gets or sets the OCLC Number (WorldCat identifier) of the book, if applicable. + /// + public string? OCLCNumber { get; set; } + + /// + /// Gets or sets the Open Library ID of the book, if applicable. + /// + public string? OpenLibraryId { get; set; } + + /// + /// Gets or sets the LibraryThing ID of the book, if applicable. + /// + public string? LibraryThingId { get; set; } + + /// + /// Gets or sets the Google Books ID of the book, if applicable. + /// + public string? GoogleBooksId { get; set; } + + /// + /// Gets or sets the Barnes & Noble ID of the book, if applicable. + /// + public string? BarnesAndNobleId { get; set; } + + /// + /// Gets or sets the Apple Books ID of the book, if applicable. + /// + public string? AppleBooksId { get; set; } + + /// + /// Gets or sets the list of ISBN (International Standard Book Number) of the book. + /// + public List? ISBNs { get; set; } + + /// + /// Gets or sets the list of media contributors (actors, directors, etc) starring in this book. + /// + public List? Contributors { get; set; } + + /// + /// Gets or sets the list of ratings for this book. + /// + public List? Ratings { get; set; } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Utilities/OptionsBuilderFluentValidationUtilities.cs b/src/Lumina.Presentation.Web/Common/Utilities/OptionsBuilderFluentValidationUtilities.cs index 8178a69d..fd983114 100644 --- a/src/Lumina.Presentation.Web/Common/Utilities/OptionsBuilderFluentValidationUtilities.cs +++ b/src/Lumina.Presentation.Web/Common/Utilities/OptionsBuilderFluentValidationUtilities.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using FluentValidation; using Lumina.Presentation.Web.Common.Validation; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; #endregion diff --git a/src/Lumina.Presentation.Web/Common/Utilities/StringUtilities.cs b/src/Lumina.Presentation.Web/Common/Utilities/StringUtilities.cs new file mode 100644 index 00000000..1451907e --- /dev/null +++ b/src/Lumina.Presentation.Web/Common/Utilities/StringUtilities.cs @@ -0,0 +1,23 @@ +#region ========================================================================= USING ===================================================================================== +using System.Text.RegularExpressions; +#endregion + +namespace Lumina.Presentation.Web.Common.Utilities; + +/// +/// Extension methods for strings. +/// +public static class StringUtilities +{ + #region ================================================================== METHODS =================================================================================== + /// + /// Splits a camel case string into separate words. + /// + /// The string to be split. + /// The split string. + public static string SplitCamelCase(this string input) + { + return Regex.Replace(input, "([A-Z])", " $1", RegexOptions.Compiled).Trim(); + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Common/Validation/FluentValidationOptions.cs b/src/Lumina.Presentation.Web/Common/Validation/FluentValidationOptions.cs index 5aa1abb2..f1b93c54 100644 --- a/src/Lumina.Presentation.Web/Common/Validation/FluentValidationOptions.cs +++ b/src/Lumina.Presentation.Web/Common/Validation/FluentValidationOptions.cs @@ -1,6 +1,8 @@ #region ========================================================================= USING ===================================================================================== using FluentValidation; using Microsoft.Extensions.Options; +using System; +using System.Linq; #endregion namespace Lumina.Presentation.Web.Common.Validation; @@ -8,7 +10,7 @@ namespace Lumina.Presentation.Web.Common.Validation; /// /// Provides options for fluent validation of a specific options type. /// -/// The type of options being validated +/// The type of options being validated. public class FluentValidationOptions : IValidateOptions where TOptions : class { #region ================================================================== FIELD MEMBERS ================================================================================ diff --git a/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs b/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs index ef462354..3e00cc8f 100644 --- a/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs +++ b/src/Lumina.Presentation.Web/Common/Validators/ServerConfigurationModelValidator.cs @@ -18,6 +18,7 @@ public class ServerConfigurationModelValidator : AbstractValidator x.BaseAddress).NotEmpty().WithMessage("Base address cannot be empty!"); RuleFor(x => x.Port).InclusiveBetween((ushort)0, (ushort)65535).WithMessage("Port number must be between 0 and 65535!"); + RuleFor(x => x.ApiVersion).InclusiveBetween((char)0, (char)255).WithMessage("API version must be between 0 and 255!"); } #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor new file mode 100644 index 00000000..542c4efa --- /dev/null +++ b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor @@ -0,0 +1,62 @@ +@using Lumina.Presentation.Web.Common.Models.UI + +
+
+
+
+
+
+
+ Back + Forward + Up one level +
+
+ +
+ Favorite directory + New Directory +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+ + +
+
+ Cancel + Open +
+
+
+ + + @*
+ + + Cancel + Confirm *@ +
+ +@code { + private ComboboxItem? selectedValue; + private string savedPath = string.Empty; + + private void HandleNodeSelected(string path) + { + Console.WriteLine($"Selected node: {path}"); + } +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css new file mode 100644 index 00000000..ef1747fc --- /dev/null +++ b/src/Lumina.Presentation.Web/Components/DirectoryBrowserComponent.razor.css @@ -0,0 +1,318 @@ +#directory-browser-dialog { + position: absolute; + top: 12.5%; + bottom: 12.5%; + left: 10%; + right: 10%; + padding: 10px; + border: 1px solid var(--border-color-dialog); +} + +#directory-browser-content { + margin: 0px; + height: 100%; + display: flex; + flex-direction: column; + flex-wrap: nowrap; + align-items: center; + align-content: center; + gap: 0px; + flex: 1; + min-height: 0; +} + +#directory-browser-header { + border-radius: 5px 5px 0 0; + border: 1px solid; + background: linear-gradient(to bottom, #505050 0%, #464646 35%, #404040 55%, #363636 100%); + border-color: var(--border-color-light) var(--border-color-dark) var(--border-color-dark) var(--border-color-light); + height: 40px; + display: flex; + flex-direction: column; + flex-wrap: nowrap; + align-items: stretch; + justify-content: flex-start; + position: relative; + width: 100%; +} + +#directory-browser-header-navigation-container { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-items: center; + align-content: center; + gap: 5px; + flex-grow: 1; + margin: 5px; +} + +#directory-browser-header-address-bar-container { + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-items: center; + align-content: center; + gap: 5px; + flex-grow: 1; +} + +.directory-browser-header-address-bar-url { + flex-grow: 1; + flex-shrink: 1; + min-width: 0; +} + +::deep .directory-browser-content-new-directory { + min-width: 120px; + flex-basis: 120px; + flex-shrink: 0; +} + +.navigation-icon { + width: 20px; + cursor: pointer; + transition: background-color 0.3s; +} + + .navigation-icon.disabled { + opacity: 0.7; + cursor: not-allowed; + } + +.directory-browser-header-navigation { + display: flex; + gap: 5px; +} + +.directory-browser-header-address-bar-actions { + display: flex; + align-items: center; + gap: 5px; +} + +.favorite-unselected { + filter: grayscale(100%) opacity(50%); +} + +.favorite-unselected, .favorite-selected { + width: 20px; + height: 20px; + transition: filter 0.3s ease; +} + +#directory-browser-file-system-container { + width: 100%; + flex-grow: 1; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-items: stretch; + overflow: hidden; + gap: 0px; + flex: 1; + min-height: 0; +} + +#directory-browser-file-system-treeview-container { + background-color: #131313; + border-top: 1px solid var(--border-color-light); + border-left: 1px solid var(--border-color-light); + border-right: 1px solid var(--border-color-dark); + min-width: 170px; + max-width: 400px; + width: 400px; + height: 100%; + max-height: 100%; + flex-grow: 0; + display: flex; + flex-direction: column; + flex-wrap: nowrap; + align-items: center; + gap: 0px; + padding: 10px; + overflow: hidden; + min-height: 0; +} + +#directory-browser-file-system-treeview { + background-color: #131313; + border: 1px solid var(--border-color-light); + border-top: 1px solid var(--border-color-dark); + border-left: 1px solid var(--border-color-dark); + margin-bottom: 10px; + flex-grow: 1; + width: 100%; + box-shadow: inset 2px 2px 5px var(--shadow-color); + overflow: auto; + max-height: 100%; + min-height: 0; +} + +::deep .directory-browser-file-system-sources { + flex-grow: 0; +} + +#directory-browser-file-system-directories-container { + background-color: #131313; + border-top: 1px solid var(--border-color-light); + border-left: 1px solid var(--border-color-light-medium); + flex-grow: 1; + min-width: 135px; + padding: 10px; + height: 100%; +} + +#directory-browser-file-system-directories { + background-color: #262626; + border: 1px solid var(--border-color-light); + border-top: 1px solid var(--border-color-dark); + border-left: 1px solid var(--border-color-dark); + width: 100%; + height: 100%; + box-shadow: inset 2px 2px 5px var(--shadow-color); +} + +#directory-browser-actions-container { + flex-grow: 0; + display: flex; + flex-direction: column; + flex-wrap: nowrap; + align-items: flex-start; + align-content: center; + gap: 5px; + width: 100%; +} + +#directory-browser-actions { + flex-grow: 0; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: flex-end; + gap: 5px; + width: 100%; +} + +#directory-browser-actions-path-container { + margin-top: 5px; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + align-items: center; + gap: 5px; + width: 100%; +} + +#directory-browser-shine-effect { + background: linear-gradient(to right, transparent, #fff, transparent); + width: 100%; + height: 1px; + flex-shrink: 0; + pointer-events: none; /* ensure it doesn't interfere with interactions */ +} + +#directory-browser-shine-spark { + position: absolute; + top: -2px; + left: -20px; /* start off-screen */ + width: 20px; + height: 5px; + background: radial-gradient(ellipse at center, rgba(255,255,255,1) 0%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0) 100%); + border-radius: 50%; + filter: blur(1px); + opacity: 0; + animation: spark-animation 30s cubic-bezier(0.25, 0.9, 0.9, 0.1) infinite; +} + + #directory-browser-shine-spark::before { + content: ''; + position: absolute; + top: 50%; + left: 50%; + width: 10px; + height: 10px; + background: white; + clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); + transform: translate(-50%, -50%); + filter: blur(0.5px); + animation: star-rotation 5s linear infinite; + } + + #directory-browser-shine-spark::after { + content: ''; + position: absolute; + top: 50%; + left: 50%; + width: 6px; + height: 6px; + background: #FFFFFF; + border-radius: 50%; + transform: translate(-50%, -50%); + } + +@keyframes spark-animation { + 40% { + left: -20px; + opacity: 0; + } + + 50% { + opacity: 1; + } + + 60% { + left: 100%; + opacity: 0; + } +} + +@keyframes star-rotation { + from { + transform: translate(-50%, -50%) rotate(0deg); + } + + to { + transform: translate(-50%, -50%) rotate(360deg); + } +} + +@media screen and (max-width: 600px) { + #directory-browser-header { + height: auto; + } + + #directory-browser-header-navigation-container { + flex-direction: column; + align-items: flex-start; + } + + #directory-browser-header-address-bar-container { + flex-direction: column; + align-items: stretch; + width: 100%; + } + + .directory-browser-header-address-bar-url { + width: 100%; + margin-bottom: 5px; + } + + .directory-browser-header-navigation { + display: flex; + gap: 5px; + margin-bottom: 5px; + } + + .directory-browser-header-address-bar-actions { + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; + } + + ::deep .directory-browser-content-new-directory { + min-width: 0; + flex-basis: auto; + } +} diff --git a/src/Lumina.Presentation.Web/Components/EnlightenmentButton.razor b/src/Lumina.Presentation.Web/Components/EnlightenmentButton.razor index 706b03d8..cb40b148 100644 --- a/src/Lumina.Presentation.Web/Components/EnlightenmentButton.razor +++ b/src/Lumina.Presentation.Web/Components/EnlightenmentButton.razor @@ -1,9 +1,18 @@ - + @code { [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public EventCallback OnClick { get; set; } [Parameter] public bool IsDisabled { get; set; } [Parameter] public bool IsConfirmButton { get; set; } = true; + [Parameter] public bool UsesPercentForHeight { get; set; } + [Parameter] public bool UsesPercentForWidth { get; set; } + [Parameter] public int Width { get; set; } = 100; + [Parameter] public int Height { get; set; } = 22; [Parameter] public string? CssClass { get; set; } } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/EnlightenmentCheckbox.razor b/src/Lumina.Presentation.Web/Components/EnlightenmentCheckbox.razor index 3549117a..b1bfa83b 100644 --- a/src/Lumina.Presentation.Web/Components/EnlightenmentCheckbox.razor +++ b/src/Lumina.Presentation.Web/Components/EnlightenmentCheckbox.razor @@ -22,6 +22,6 @@ private async Task OnChangeHandler(ChangeEventArgs e) { Checked = e?.Value != null ? (bool)e.Value : false; - await CheckedChanged.InvokeAsync(Checked); + await CheckedChanged.InvokeAsync(Checked).ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/EnlightenmentCombobox.razor b/src/Lumina.Presentation.Web/Components/EnlightenmentCombobox.razor index 415c3db8..4db138d5 100644 --- a/src/Lumina.Presentation.Web/Components/EnlightenmentCombobox.razor +++ b/src/Lumina.Presentation.Web/Components/EnlightenmentCombobox.razor @@ -6,21 +6,22 @@ @implements IDisposable @inject ComboboxService _comboboxService +@inject IJSRuntime JSRuntime -
+
- -
+ +@code { + [Parameter] public string? InitialPath { get; set; } + [Parameter] public List RootNodes { get; set; } = new List(); + [Parameter] public EventCallback OnNodeSelected { get; set; } + + private string? SelectedNodePath { get; set; } + private string PathSeparator { get; set; } = "/"; + private FileSystemTypeModel fileSystemType = null!; + + /// + /// Initializes the component. + /// + protected override async Task OnInitializedAsync() + { + fileSystemType = await _apiHttpClient.GetAsync("file-system/get-type").ConfigureAwait(false); + // ask the API server for the system path separator + PathSeparatorModel pathSeparator = await _apiHttpClient.GetAsync("path/get-path-separator").ConfigureAwait(false); + PathSeparator = pathSeparator.Separator; // TODO: handle error + // on Windows, ask the list of drives + if (fileSystemType.PlatformType == PlatformType.Windows) + { + List drives = await _apiHttpClient.GetAsync>("drives/get-drives").ConfigureAwait(false); + RootNodes.AddRange(drives); + } + else + { + // on UNIX, just add the root "/" + RootNodes.Add(new FileSystemTreeNodeModel() + { + Path = pathSeparator.Separator, + IsExpanded = true, + ItemType = FileSystemItemType.Root, + Name = pathSeparator.Separator + }); + } + // if there was an initial path saved from a previous session, load the full tree up to that initial path + if (InitialPath is not null) + { + // ask the whole tree for the saved path + List initialTree = await _apiHttpClient.GetAsync>($"directories/get-directory-tree?path={Uri.EscapeDataString(InitialPath)}").ConfigureAwait(false); + if (initialTree is not null && initialTree.Count > 0) + { + // take the root of the retrieved tree, and try to match it against a drive in the retrieved list of drives, on Windows; on Unix, add it as the unique root path + PathSegmentModel pathRoot = await _apiHttpClient.GetAsync($"path/get-path-root?path={Uri.EscapeDataString(InitialPath)}").ConfigureAwait(false); + if (fileSystemType.PlatformType == PlatformType.Windows) + { + FileSystemTreeNodeModel? driveNode = RootNodes.FirstOrDefault(drive => drive.Path.Equals(pathRoot.Path, StringComparison.OrdinalIgnoreCase)); + // if a drive was matched, make the retrieved tree a child of it + if (driveNode is not null) + { + int index = RootNodes.IndexOf(driveNode); + RootNodes[index] = initialTree[0]; + } + } + else + RootNodes[0] = initialTree[0]; + } + } + } + + /// + /// Expands or collapses a node in the tree view. + /// + /// The node to expand or collapse. + private async Task ExpandNode(FileSystemTreeNodeModel node) + { + if (!node.IsExpanded && !node.ChildrenLoaded) + { + node.Children = new List(); + node.IsExpanded = true; + StateHasChanged(); + try + { + await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"directories/get-directories?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false)) + { + if (childNode is not null) + { + node.Children.Add(childNode); + StateHasChanged(); + } + } + await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"files/get-files?path={Uri.EscapeDataString(node.Path)}").ConfigureAwait(false)) + { + if (childNode is not null) + { + node.Children.Add(childNode); + StateHasChanged(); + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error expanding node: {ex.Message}"); // TODO: display to the user when notification system is implemented + } + finally + { + node.ChildrenLoaded = true; + } + } + else + node.IsExpanded = !node.IsExpanded; + StateHasChanged(); + } + + /// + /// Retrieves the child nodes for a given path. + /// + /// The path to get child nodes for. + /// A list of representing the child nodes. + private async Task> GetChildNodes(string path) + { + List directories = await _apiHttpClient.GetAsync>($"directories/get-directories?path={Uri.EscapeDataString(path)}").ConfigureAwait(false); + List files = await _apiHttpClient.GetAsync>($"files/get-files?path={Uri.EscapeDataString(path)}").ConfigureAwait(false); + directories.AddRange(files); + return directories; + } + + /// + /// Handles the selection of a node in the tree view. + /// + /// The path of the selected node. + private async Task HandleNodeSelected(string path) + { + SelectedNodePath = path; + await OnNodeSelected.InvokeAsync(path).ConfigureAwait(false); + } +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/FileSystemTreeViewNode.razor b/src/Lumina.Presentation.Web/Components/FileSystemTreeViewNode.razor new file mode 100644 index 00000000..6ddfa062 --- /dev/null +++ b/src/Lumina.Presentation.Web/Components/FileSystemTreeViewNode.razor @@ -0,0 +1,66 @@ +@using Lumina.Presentation.Web.Common.Enums.FileSystem +@using Lumina.Presentation.Web.Common.Models.FileManagement + +
+ + @if (Node.ItemType == FileSystemItemType.Directory || Node.ItemType == FileSystemItemType.Root) + { + + } + else + { + + } + @GetNodeIcon() + @Node.Name + + @if (Node.IsExpanded && Node.Children is not null) + { +
+ @foreach (var childNode in Node.Children) + { + + } +
+ } +
+ +@code { + [Parameter] public FileSystemTreeNodeModel Node { get; set; } = null!; + [Parameter] public EventCallback OnExpand { get; set; } + [Parameter] public EventCallback OnNodeSelected { get; set; } + [Parameter] public string? SelectedNodePath { get; set; } + + private bool IsSelected => Node.Path == SelectedNodePath; + + /// + /// Toggles the expanded state of the node. + /// + private async Task ToggleExpand() + { + await OnExpand.InvokeAsync(Node).ConfigureAwait(false); + } + + /// + /// Handles the click event on the node. + /// + private async Task HandleNodeClick() + { + await OnNodeSelected.InvokeAsync(Node.Path).ConfigureAwait(false); + } + + /// + /// Gets the icon of the node, based on it type. + /// + /// The icon on the node + private string GetNodeIcon() + { + return Node.ItemType switch + { + FileSystemItemType.Root => "💿", + FileSystemItemType.Directory => Node.IsExpanded ? "📂" : "📁", + FileSystemItemType.File => "📄", + _ => "❓" + }; + } +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Components/FileSystemTreeViewNode.razor.css b/src/Lumina.Presentation.Web/Components/FileSystemTreeViewNode.razor.css new file mode 100644 index 00000000..2022d883 --- /dev/null +++ b/src/Lumina.Presentation.Web/Components/FileSystemTreeViewNode.razor.css @@ -0,0 +1,89 @@ +.treeview { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + font-size: 14px; + color: #333; + padding: 10px; + background-color: #f0f0f0; + border: 1px solid #ddd; + height: 100%; + overflow-y: auto; +} + +.tree-node { + padding: 2px 0; +} + +.node-content { + display: flex; + align-items: flex-start; + cursor: pointer; + padding: 0px; + border-radius: 2px; + border: 1px solid transparent; + flex-wrap: wrap; + min-width: 100%; + display: inline-block; + white-space: nowrap; +} + + .node-content:hover { + background-color: #131313; + border-top: 1px solid var(--border-color-light); + border-left: 1px solid var(--border-color-light); + border-right: 1px solid var(--border-color-dark); + background-color: var(--container-background); + } + + .node-content.selected { + background-color: #131313; + border-bottom: 1px solid var(--border-color-light); + border-right: 1px solid var(--border-color-light); + border-left: 1px solid var(--border-color-dark); + background-color: var(--container-background); + } + +.node-icon { + margin-right: 5px; + width: 16px; + text-align: center; + flex-shrink: 0; +} + +.node-icon, .expand-button { + flex-shrink: 0; + align-self: center; +} + +.child-nodes { + padding-left: 20px; + border-left: 1px dotted #ccc; + margin-left: 7px; +} + +.expand-button { + display: inline-flex; + width: 10px; + height: 10px; + margin-right: 5px; + background-image: url("data:image/svg+xml;utf8,"); + background-size: contain; + transition: transform 0.2s ease; +} + + .expand-button.expanded { + background-image: url("data:image/svg+xml;utf8,"); + transform: rotate(90deg); + } + +.spacer { + display: inline-block; + width: 15px; +} + +.node-name { + margin-left: 3px; + overflow-wrap: break-word; + word-break: break-all; + flex: 1; + align-self: end; +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Core/Services/UI/ComboboxService.cs b/src/Lumina.Presentation.Web/Core/Services/UI/ComboboxService.cs index 4ed84e1e..afa9440f 100644 --- a/src/Lumina.Presentation.Web/Core/Services/UI/ComboboxService.cs +++ b/src/Lumina.Presentation.Web/Core/Services/UI/ComboboxService.cs @@ -1,4 +1,8 @@ -namespace Lumina.Presentation.Web.Core.Services.UI; +#region ========================================================================= USING ===================================================================================== +using System; +#endregion + +namespace Lumina.Presentation.Web.Core.Services.UI; /// /// Service for managing comboboxes. diff --git a/src/Lumina.Presentation.Web/Layout/NavMenu.razor b/src/Lumina.Presentation.Web/Layout/NavMenu.razor index dee0074c..9b374227 100644 --- a/src/Lumina.Presentation.Web/Layout/NavMenu.razor +++ b/src/Lumina.Presentation.Web/Layout/NavMenu.razor @@ -24,8 +24,8 @@ Library
Written Content @@ -81,8 +81,8 @@
    -
  • Manage libraries
  • -
  • Add new library
  • +
  • Manage libraries
  • +
  • Add new library
    • diff --git a/src/Lumina.Presentation.Web/Layout/NavMenu.razor.css b/src/Lumina.Presentation.Web/Layout/NavMenu.razor.css index ae49e093..6650a760 100644 --- a/src/Lumina.Presentation.Web/Layout/NavMenu.razor.css +++ b/src/Lumina.Presentation.Web/Layout/NavMenu.razor.css @@ -181,6 +181,11 @@ .menubar { background: linear-gradient( to bottom, #505050 0%, #464646 35%, #404040 55%, #363636 100% ); padding: 0; + position: fixed; + top: 0px; + left: 0px; + width: 100%; + z-index: 900; } .menubar ul { diff --git a/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj b/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj index e52cf5b4..f94765f7 100644 --- a/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj +++ b/src/Lumina.Presentation.Web/Lumina.Presentation.Web.csproj @@ -3,11 +3,11 @@ net8.0 enable - enable - ..\..\bin\ + disable + $(SolutionDir)..\bin\client\ false - + diff --git a/src/Lumina.Presentation.Web/Pages/Home.razor b/src/Lumina.Presentation.Web/Pages/Home.razor index e0f5dd29..9a039b41 100644 --- a/src/Lumina.Presentation.Web/Pages/Home.razor +++ b/src/Lumina.Presentation.Web/Pages/Home.razor @@ -1,3 +1,7 @@ @page "/" -Home \ No newline at end of file +@using Lumina.Presentation.Web.Components + +Lumina - Home + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Pages/Library/Management/Index.razor b/src/Lumina.Presentation.Web/Pages/Library/Management/Index.razor new file mode 100644 index 00000000..5bde51cf --- /dev/null +++ b/src/Lumina.Presentation.Web/Pages/Library/Management/Index.razor @@ -0,0 +1,90 @@ +@page "/library/manage" + +

      Manage Libraries

      + +
      +
      +
      +
      ×
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      +

      LocalFileSystem

      +
      + + + + DescriptionTitle +
      + + + DescriptionURL +
      + + + DescriptionPort +
      + + + DescriptionUsername +
      + + + DescriptionPassword +
      + +
      +
      + + +
      +
      +
      Unix
      +
      Windows
      +
      +
      + DescriptionPlatform +
      + +
      + +
      +
      + +@code { + +} diff --git a/src/Lumina.Presentation.Web/Pages/Library/Management/Item.razor b/src/Lumina.Presentation.Web/Pages/Library/Management/Item.razor new file mode 100644 index 00000000..c5c1eee8 --- /dev/null +++ b/src/Lumina.Presentation.Web/Pages/Library/Management/Item.razor @@ -0,0 +1,190 @@ +@page "/library/manage/item" +@page "/library/manage/item/{id:guid}" + +@using Lumina.Presentation.Web.Common.Enums.AudioLibrary +@using Lumina.Presentation.Web.Common.Enums.BookLibrary +@using Lumina.Presentation.Web.Common.Enums.Library +@using Lumina.Presentation.Web.Common.Enums.PhotoLibrary +@using Lumina.Presentation.Web.Common.Enums.VideoLibrary +@using Lumina.Presentation.Web.Common.Models.Libraries +@using Lumina.Presentation.Web.Common.Models.UI +@using Lumina.Presentation.Web.Common.Utilities +@using Lumina.Presentation.Web.Components + +

      @(Id is null ? "Add New Library" : "Edit Library")

      + +
      +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      + + + DescriptionTitle +
      + + + DescriptionLibraryType +
      + + + + + + + + + + + @foreach (var item in tableData) + { + + + + + + } + +
      Column 1Column 2Directories
      @item.Column1@item.Column2 + +
      + DescriptionURL +
      + + + DescriptionPort +
      + + + DescriptionUsername +
      + + + DescriptionPassword +
      + + + DescriptionPlatform +
      + Cancel + Save +
      + +
      +
      + +@code { + [Parameter] + public Guid? Id { get; set; } + + private LibraryModel dataSource = new(); + + private List> items = new() + { + new ComboboxItem{ Text = nameof(LibraryType.WrittenContent).SplitCamelCase(), IsEnabled = false }, + new ComboboxItem{ Text = nameof(WrittenContentType.Book).SplitCamelCase(), Value = nameof(WrittenContentType.Book) }, + new ComboboxItem{ Text = nameof(WrittenContentType.EBook).SplitCamelCase(), Value = nameof(WrittenContentType.EBook) }, + new ComboboxItem{ Text = nameof(WrittenContentType.BookSeries).SplitCamelCase(), Value = nameof(WrittenContentType.BookSeries) }, + new ComboboxItem{ Text = nameof(WrittenContentType.ComicBook).SplitCamelCase(), Value = nameof(WrittenContentType.ComicBook) }, + new ComboboxItem{ Text = nameof(WrittenContentType.ComicSeries).SplitCamelCase(), Value = nameof(WrittenContentType.ComicSeries) }, + new ComboboxItem{ Text = nameof(WrittenContentType.Magazine).SplitCamelCase(), Value = nameof(WrittenContentType.Magazine) }, + new ComboboxItem{ Text = nameof(WrittenContentType.Manga).SplitCamelCase(), Value = nameof(WrittenContentType.Manga) }, + new ComboboxItem{ Text = nameof(WrittenContentType.GraphicNovel).SplitCamelCase(), Value = nameof(WrittenContentType.GraphicNovel) }, + new ComboboxItem{ Text = nameof(WrittenContentType.AcademicPaper).SplitCamelCase(), Value = nameof(WrittenContentType.AcademicPaper) }, + new ComboboxItem{ Text = nameof(WrittenContentType.SheetMusic).SplitCamelCase(), Value = nameof(WrittenContentType.SheetMusic) }, + new ComboboxItem{ Text = nameof(WrittenContentType.Screenplay).SplitCamelCase(), Value = nameof(WrittenContentType.Screenplay) }, + new ComboboxItem{ Text = nameof(LibraryType.VideoContent).SplitCamelCase(), IsEnabled = false }, + new ComboboxItem{ Text = nameof(VideoContentType.TvShow).SplitCamelCase(), Value = nameof(VideoContentType.TvShow) }, + new ComboboxItem{ Text = nameof(VideoContentType.Movie).SplitCamelCase(), Value = nameof(VideoContentType.Movie) }, + new ComboboxItem{ Text = nameof(VideoContentType.FilmSeries).SplitCamelCase(), Value = nameof(VideoContentType.FilmSeries) }, + new ComboboxItem{ Text = nameof(VideoContentType.FilmFranchise).SplitCamelCase(), Value = nameof(VideoContentType.FilmFranchise) }, + new ComboboxItem{ Text = nameof(VideoContentType.Concert).SplitCamelCase(), Value = nameof(VideoContentType.Concert) }, + new ComboboxItem{ Text = nameof(VideoContentType.Documentary).SplitCamelCase(), Value = nameof(VideoContentType.Documentary) }, + new ComboboxItem{ Text = nameof(VideoContentType.Tutorial).SplitCamelCase(), Value = nameof(VideoContentType.Tutorial) }, + new ComboboxItem{ Text = nameof(VideoContentType.Personal).SplitCamelCase(), Value = nameof(VideoContentType.Personal) }, + new ComboboxItem{ Text = nameof(VideoContentType.Anime).SplitCamelCase(), Value = nameof(VideoContentType.Anime) }, + new ComboboxItem{ Text = nameof(VideoContentType.Youtube).SplitCamelCase(), Value = nameof(VideoContentType.Youtube) }, + new ComboboxItem{ Text = nameof(VideoContentType.Videoclip).SplitCamelCase(), Value = nameof(VideoContentType.Videoclip) }, + new ComboboxItem{ Text = nameof(LibraryType.AudioContent).SplitCamelCase(), IsEnabled = false }, + new ComboboxItem{ Text = nameof(AudioContentType.Music).SplitCamelCase(), Value = nameof(AudioContentType.Music) }, + new ComboboxItem{ Text = nameof(AudioContentType.AudioBook).SplitCamelCase(), Value = nameof(AudioContentType.AudioBook) }, + new ComboboxItem{ Text = nameof(AudioContentType.LivePerformance).SplitCamelCase(), Value = nameof(AudioContentType.LivePerformance) }, + new ComboboxItem{ Text = nameof(AudioContentType.Interview).SplitCamelCase(), Value = nameof(AudioContentType.Interview) }, + new ComboboxItem{ Text = nameof(AudioContentType.Cover).SplitCamelCase(), Value = nameof(AudioContentType.Cover) }, + new ComboboxItem{ Text = nameof(AudioContentType.Remix).SplitCamelCase(), Value = nameof(AudioContentType.Remix) }, + new ComboboxItem{ Text = nameof(AudioContentType.Soundeffect).SplitCamelCase(), Value = nameof(AudioContentType.Soundeffect) }, + new ComboboxItem{ Text = nameof(AudioContentType.Podcast).SplitCamelCase(), Value = nameof(AudioContentType.Podcast) }, + new ComboboxItem{ Text = nameof(AudioContentType.RadioShow).SplitCamelCase(), Value = nameof(AudioContentType.RadioShow) }, + new ComboboxItem{ Text = nameof(LibraryType.VisualContent).SplitCamelCase(), IsEnabled = false }, + new ComboboxItem{ Text = nameof(VisualContentType.PhotoAlbum).SplitCamelCase(), Value = nameof(VisualContentType.PhotoAlbum) }, + new ComboboxItem{ Text = nameof(LibraryType.MiscellaneousContent).SplitCamelCase(), IsEnabled = false }, + new ComboboxItem{ Text = nameof(MiscellaneousContentType.Other).SplitCamelCase(), Value = nameof(MiscellaneousContentType.Other) }, + }; + + private ComboboxItem? selectedValue; + private ComboboxItem? selectedValue2; + + private bool isSaving = false; + private bool isCancelling = false; + + private async Task SaveData() + { + isSaving = true; + // Perform save operation + isSaving = false; + Console.WriteLine("saved"); + } + + private async Task CancelOperation() + { + isCancelling = true; + // Perform cancel operation + isCancelling = false; + Console.WriteLine("cancelled"); + } + + private List tableData = new List + { + new TableItem { Column1 = "Value 1", Column2 = "Value 2", Directories = new List() }, + new TableItem { Column1 = "Value 3", Column2 = "Value 4", Directories = new List() } + }; + + public class TableItem + { + public string Column1 { get; set; } + public string Column2 { get; set; } + public List Directories { get; set; } + } +} diff --git a/src/Lumina.Presentation.Web/Pages/Library/WrittenContentLibrary/BookLibrary/Books/Index.razor b/src/Lumina.Presentation.Web/Pages/Library/WrittenContentLibrary/BookLibrary/Books/Index.razor new file mode 100644 index 00000000..15ac1bde --- /dev/null +++ b/src/Lumina.Presentation.Web/Pages/Library/WrittenContentLibrary/BookLibrary/Books/Index.razor @@ -0,0 +1,7 @@ +@page "/library/written-content/books-library/books" + +

      Books

      + +@code { + +} diff --git a/src/Lumina.Presentation.Web/Pages/Library/WrittenContentLibrary/BookLibrary/Books/Item.razor b/src/Lumina.Presentation.Web/Pages/Library/WrittenContentLibrary/BookLibrary/Books/Item.razor new file mode 100644 index 00000000..29bab801 --- /dev/null +++ b/src/Lumina.Presentation.Web/Pages/Library/WrittenContentLibrary/BookLibrary/Books/Item.razor @@ -0,0 +1,146 @@ +@page "/library/written-content-library/books-library/books/item/{id:guid}" + +@using Lumina.Presentation.Web.Common.Enums.BookLibrary +@using Lumina.Presentation.Web.Common.Models.Common +@using Lumina.Presentation.Web.Common.Models.MediaContributors +@using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary +@using Lumina.Presentation.Web.Common.Models.WrittenContentLibrary.BookLibrary +@using Lumina.Presentation.Web.Common.Requests.WrittenContentLibrary.BookLibrary + +@inject HttpClient _httpClient + +

      @(Id.HasValue ? "Edit" : "Add") Book

      + + + + + +
      + + +
      + +
      + + +
      + +
      + + +
      + +

      Release Information

      +
      + + +
      + +
      + + +
      + +

      Genres

      + @foreach (var genre in bookRequest.Metadata.Genres) + { +
      + +
      + } + + +

      Language

      +
      + + +
      + +
      + + +
      + +

      Book Details

      +
      + + + @foreach (var format in Enum.GetValues(typeof(BookFormat))) + { + + } + +
      + +
      + + +
      + +

      Identifiers

      +
      + + + + @foreach (var format in Enum.GetValues(typeof(IsbnFormat))) + { + + } + +
      + +

      Contributors

      + @foreach (var contributor in bookRequest.Contributors) + { +
      + @* *@ + +
      + } + + + +
      + +@code { + private AddBookRequest bookRequest = new AddBookRequest + { + Metadata = new WrittenContentMetadataModel + { + ReleaseInfo = new ReleaseInfoModel(), + Genres = new List(), + Language = new LanguageInfoModel() + }, + ISBNs = new List { new IsbnModel() }, + Contributors = new List() + }; + + private void AddGenre() + { + bookRequest.Metadata.Genres.Add(new GenreModel()); + } + + private void AddContributor() + { + bookRequest.Contributors.Add(new MediaContributorModel { Role = new MediaContributorRoleModel() }); + } + + private async Task HandleValidSubmit() + { + // Send the bookRequest to your API + var response = await _httpClient.PostAsJsonAsync("api/books", bookRequest).ConfigureAwait(false); + if (response.IsSuccessStatusCode) + { + // Handle successful submission + } + else + { + // Handle error + } + } +} + +@code { + [Parameter] + public Guid? Id { get; set; } +} \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/Program.cs b/src/Lumina.Presentation.Web/Program.cs index 869dd6dc..93a09f80 100644 --- a/src/Lumina.Presentation.Web/Program.cs +++ b/src/Lumina.Presentation.Web/Program.cs @@ -1,9 +1,8 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Presentation.Web.Common.DependencyInjection; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Lumina.Presentation.Web.Common.DependencyInjection; -using Lumina.Presentation.Web.Common.Api; -using Lumina.Application.Common.Models.FileSystem; +using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Web; @@ -32,7 +31,7 @@ public class Program var webAssemblyHost = builder.Build(); - await webAssemblyHost.RunAsync(); + await webAssemblyHost.RunAsync().ConfigureAwait(false); } #endregion } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/appsettings.json b/src/Lumina.Presentation.Web/wwwroot/appsettings.json index fee5dc4f..5e125dc7 100644 --- a/src/Lumina.Presentation.Web/wwwroot/appsettings.json +++ b/src/Lumina.Presentation.Web/wwwroot/appsettings.json @@ -1,6 +1,7 @@ { "ServerConfiguration": { - "BaseAddress": "https://localhost", - "Port": 7057 + "ApiVersion": 1, + "BaseAddress": "http://localhost", + "Port": 5214 } } \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/css/site.css b/src/Lumina.Presentation.Web/wwwroot/css/site.css index 73aeade8..ce0c1791 100644 --- a/src/Lumina.Presentation.Web/wwwroot/css/site.css +++ b/src/Lumina.Presentation.Web/wwwroot/css/site.css @@ -1,7 +1,13 @@ :root { --background-color: #222; - --border-color-light: #777777; + --container-background: #232323; + --border-color-light: #363636; + --border-color-light-medium: #555555; + --border-color-light-high: #777777; --border-color-dark: #000000; + --border-color-dialog: #1E90FF; + --shadow-color: #000000; + --text-foreground: #6DCBFE; } html, @@ -35,7 +41,7 @@ body { #page { border-style: solid; border-width: 1px; - border-color: var(--border-color-light) var(--border-color-dark) var(--border-color-dark) var(--border-color-light); + border-color: var(--border-color-light-high) var(--border-color-dark) var(--border-color-dark) var(--border-color-light-high); background-color: #222; min-width: 100%; min-height: 100%; @@ -45,6 +51,21 @@ main { padding-top: 20px; } +#modal-background { + z-index: 998; + position: absolute; + top: 0px; + left: 0px; + min-width: 100%; + min-height: 100%; + background-color: #000000; + opacity: 0.6; +} + +.above-modal { + z-index: 999; +} + .shine-effect { position: relative; top: -11px; @@ -61,7 +82,7 @@ main { .enlightenment-panel { border-radius: 5px; - background: linear-gradient(135deg, #404040, #232323); + background: linear-gradient(135deg, #404040, var(--container-background)); border-top: 1px solid #505050; border-left: 1px solid #505050; border-right: 1px solid #000; @@ -69,8 +90,8 @@ main { padding: 10px; } -.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { - box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; +.container-background { + background-color: var(--container-background); } .panel { @@ -1146,6 +1167,14 @@ main { font-size: 24px !important; } +.bold { + font-weight: bold; +} + +.italic { + font-style: italic; +} + .hidden { display: none !important; } diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/back.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/back.svg new file mode 100644 index 00000000..8510fcae --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/back.svg @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/favorite-star.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/favorite-star.svg new file mode 100644 index 00000000..c2e80cb3 --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/favorite-star.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/forward.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/forward.svg new file mode 100644 index 00000000..066f051d --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/forward.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/images/ui/up.svg b/src/Lumina.Presentation.Web/wwwroot/images/ui/up.svg new file mode 100644 index 00000000..2ad5e585 --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/images/ui/up.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Lumina.Presentation.Web/wwwroot/index.html b/src/Lumina.Presentation.Web/wwwroot/index.html index be6127dc..233b4e88 100644 --- a/src/Lumina.Presentation.Web/wwwroot/index.html +++ b/src/Lumina.Presentation.Web/wwwroot/index.html @@ -4,7 +4,7 @@ - Lumina.Presentation.Web + Lumina @@ -20,13 +20,15 @@
- + +
An unhandled error has occurred. Reload 🗙
+ diff --git a/src/Lumina.Presentation.Web/wwwroot/js/site.js b/src/Lumina.Presentation.Web/wwwroot/js/site.js new file mode 100644 index 00000000..eb1fe9af --- /dev/null +++ b/src/Lumina.Presentation.Web/wwwroot/js/site.js @@ -0,0 +1,25 @@ +/** + * Adjusts the height of a dropdown identified by `comboboxId` to fit in the available space. + * @param {string} comboboxId The ID of the combobox whose dropdown should be adjusted. + */ +function adjustDropdownHeight(comboboxId) { + const combobox = document.getElementById(comboboxId); + const dropdown = combobox.querySelector('.enlightenment-dropdown'); + // get the bounds of the combobox and the height of the viewport + const comboboxRect = combobox.getBoundingClientRect(); + const viewportHeight = window.innerHeight; + // calculate the space available between the combobox and the bottom of the viewport, with a 10px margin + const dropdownTopPosition = comboboxRect.top + comboboxRect.height; + const availableSpace = viewportHeight - dropdownTopPosition - 10; // 10px margin + dropdown.style.maxHeight = `${availableSpace}px`; +} + +window.showDirectoryPicker = async () => { + try { + const dirHandle = await window.showDirectoryPicker().ConfigureAwait(false); + return dirHandle.name; + } catch (err) { + console.error(err); + return null; + } +}; \ No newline at end of file diff --git a/src/Lumina.sln b/src/Lumina.sln index 6077e9cf..3b7a5f2d 100644 --- a/src/Lumina.sln +++ b/src/Lumina.sln @@ -71,6 +71,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Presentation.Api.Int EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{D4C61542-FC91-47FA-B1D2-11CC99617454}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Contracts", "Lumina.Contracts\Lumina.Contracts.csproj", "{6BD85BA8-B3C4-4D79-8858-F6D7676FF2CC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -133,6 +135,10 @@ Global {D4C61542-FC91-47FA-B1D2-11CC99617454}.Debug|Any CPU.Build.0 = Debug|Any CPU {D4C61542-FC91-47FA-B1D2-11CC99617454}.Release|Any CPU.ActiveCfg = Release|Any CPU {D4C61542-FC91-47FA-B1D2-11CC99617454}.Release|Any CPU.Build.0 = Release|Any CPU + {6BD85BA8-B3C4-4D79-8858-F6D7676FF2CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BD85BA8-B3C4-4D79-8858-F6D7676FF2CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BD85BA8-B3C4-4D79-8858-F6D7676FF2CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BD85BA8-B3C4-4D79-8858-F6D7676FF2CC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -158,6 +164,7 @@ Global {3F057926-562F-4EF4-BFC0-EE62372D4551} = {16E590D3-DD9F-4B45-BF19-C6E317A57D11} {6B3FC07B-6208-4544-ACFB-79243A59EA1A} = {3F057926-562F-4EF4-BFC0-EE62372D4551} {3680DAFB-10BA-4A0F-AE40-620D06DAF617} = {3F057926-562F-4EF4-BFC0-EE62372D4551} + {6BD85BA8-B3C4-4D79-8858-F6D7676FF2CC} = {3C316ABB-08D5-4450-9A4E-91059DB54254} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4A55A28E-C657-4A0B-95EA-2931AE66004E} diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index d7774a07..e8be593c 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -1,5 +1,5 @@ services: - lumina.presentation.api: + lumina-server: container_name: lumina-server build: context: . diff --git a/src/docker-compose.vs.debug.yml b/src/docker-compose.vs.debug.yml index 684e66fa..341df4e3 100644 --- a/src/docker-compose.vs.debug.yml +++ b/src/docker-compose.vs.debug.yml @@ -1,7 +1,7 @@ # this file is required because the default base output path for the projects has been changed, and we need to tell docker compose where to take the files from, in debug mode # this file is the last in the chain of files when docker-compose commands are called, so it always takes precedence services: - lumina.presentation.api: + lumina-server: labels: com.microsoft.visualstudio.debuggee.program: "/app/Lumina.Presentation.Api.dll" com.microsoft.visualstudio.debuggee.workingdirectory: "/app" diff --git a/src/docker-compose.yml b/src/docker-compose.yml index d84ac5ae..12f8eaab 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -1,5 +1,5 @@ services: - lumina.presentation.api: + lumina-server: container_name: lumina-server image: ${DOCKER_REGISTRY-}lumina-server build: diff --git a/src/launchSettings.json b/src/launchSettings.json index fe4f1df9..9de105e4 100644 --- a/src/launchSettings.json +++ b/src/launchSettings.json @@ -4,7 +4,7 @@ "commandName": "DockerCompose", "commandVersion": "1.0", "serviceActions": { - "lumina.presentation.api": "StartDebugging" + "lumina-server": "StartDebugging" } } } diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Lumina.DataAccess.IntegrationTests.csproj b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Lumina.DataAccess.IntegrationTests.csproj index e134d618..92668374 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Lumina.DataAccess.IntegrationTests.csproj +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Lumina.DataAccess.IntegrationTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs index 9a292414..c29d140d 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Converters/BookJsonConverter.cs @@ -1,11 +1,14 @@ #region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.BookLibrary; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Common.ValueObjects.Metadata; using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; +using System; +using System.Collections.Generic; +using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; #endregion diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/BogusExtensions.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/BogusExtensions.cs index 7a4f2a51..ee94dc64 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/BogusExtensions.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/BogusExtensions.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Bogus; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/DateOnlySpecimenBuilder.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/DateOnlySpecimenBuilder.cs index 6be85768..6d6714c7 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/DateOnlySpecimenBuilder.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/DateOnlySpecimenBuilder.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture.Kernel; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs index a6275315..0f6adb68 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/LuminaApiFactory.cs @@ -5,7 +5,9 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using System; using System.Diagnostics.CodeAnalysis; +using System.Linq; #endregion namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup; diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs index d9fd8674..769a2653 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture.Kernel; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/BooksControllerTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/BooksControllerTests.cs index 7aab9f22..08618814 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/BooksControllerTests.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/BooksControllerTests.cs @@ -1,18 +1,23 @@ #region ========================================================================= USING ===================================================================================== +using Bogus; using FluentAssertions; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; +using Lumina.Domain.Common.Errors; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate; -using Lumina.Presentation.Api.Common.Contracts.Books; using Lumina.Presentation.Api.IntegrationTests.Common.Converters; using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Core.Controllers.Books.Fixtures; using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Net; +using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; -using Lumina.Domain.Common.Errors; -using Bogus; -using Lumina.Domain.Common.Enums; +using System.Threading.Tasks; #endregion namespace Lumina.Presentation.Api.IntegrationTests.Core.Controllers.Books; diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/AddBookRequestFixture.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/AddBookRequestFixture.cs index 89bbfb40..1d2dd62b 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/AddBookRequestFixture.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/AddBookRequestFixture.cs @@ -1,13 +1,17 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture; using Bogus; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; -using Lumina.Application.Common.Models.Contributors; -using Lumina.Domain.Common.Enums; -using Lumina.Presentation.Api.Common.Contracts.Books; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.MediaContributors; +using Lumina.Contracts.Models.WrittenContentLibrary; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; +using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary; using Lumina.Presentation.Api.IntegrationTests.Common.Setup; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; #endregion namespace Lumina.Presentation.Api.IntegrationTests.Core.Controllers.Books.Fixtures; @@ -47,8 +51,8 @@ public class AddBookRequestFixture var releaseYear = _random.Next(2000, 2010); var reReleaseYear = _random.Next(2010, 2020); - var releaseInfo = new Faker() - .CustomInstantiator(f => new ReleaseInfoDto( + var releaseInfo = new Faker() + .CustomInstantiator(f => new ReleaseInfoModel( default, default, default, @@ -64,44 +68,44 @@ public class AddBookRequestFixture .RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50))) .Generate(); - var genre = new Faker() - .CustomInstantiator(f => new GenreDto( + var genre = new Faker() + .CustomInstantiator(f => new GenreModel( default! )) .RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50))); - var tag = new Faker() - .CustomInstantiator(f => new TagDto( + var tag = new Faker() + .CustomInstantiator(f => new TagModel( default! )) .RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50))); - var mediaContributorRole = new Faker() - .CustomInstantiator(f => new MediaContributorRoleDto( + var mediaContributorRole = new Faker() + .CustomInstantiator(f => new MediaContributorRoleModel( default!, default! )) .RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50))); - var mediaContributorName = new Faker() - .CustomInstantiator(f => new MediaContributorNameDto( + var mediaContributorName = new Faker() + .CustomInstantiator(f => new MediaContributorNameModel( default!, default! )) .RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50))); - var mediaContributor = new Faker() - .CustomInstantiator(f => new MediaContributorDto( + var mediaContributor = new Faker() + .CustomInstantiator(f => new MediaContributorModel( default!, default! )) .RuleFor(e => e.Name, mediaContributorName) .RuleFor(e => e.Role, mediaContributorRole); - var rating = new Faker() - .CustomInstantiator(f => new BookRatingDto( + var rating = new Faker() + .CustomInstantiator(f => new BookRatingModel( default, default, default, @@ -112,8 +116,8 @@ public class AddBookRequestFixture .RuleFor(e => e.Source, _fixture.Create()) .RuleFor(e => e.VoteCount, _random.Next(1, 1000)); - var language = new Faker() - .CustomInstantiator(f => new LanguageInfoDto( + var language = new Faker() + .CustomInstantiator(f => new LanguageInfoModel( default!, default!, default @@ -122,8 +126,8 @@ public class AddBookRequestFixture .RuleFor(e => e.LanguageCode, f => f.Random.String2(2)) .RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50))); - var originalLanguage = new Faker() - .CustomInstantiator(f => new LanguageInfoDto( + var originalLanguage = new Faker() + .CustomInstantiator(f => new LanguageInfoModel( default!, default!, default @@ -132,8 +136,8 @@ public class AddBookRequestFixture .RuleFor(e => e.LanguageCode, f => f.Random.String2(2)) .RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50))); - var metadata = new Faker() - .CustomInstantiator(f => new WrittenContentMetadataDto( + var metadata = new Faker() + .CustomInstantiator(f => new WrittenContentMetadataModel( default!, default, default, @@ -156,8 +160,8 @@ public class AddBookRequestFixture .RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100))) .RuleFor(x => x.PageCount, _random.Next(100, 300)); - var isbn = new Faker() - .CustomInstantiator(f => new IsbnDto( + var isbn = new Faker() + .CustomInstantiator(f => new IsbnModel( default!, default )) @@ -279,7 +283,7 @@ public class AddBookRequestFixture var releaseYear = _random.Next(2000, 2010); var reReleaseYear = _random.Next(2010, 2020); - _fixture.Register(() => new ReleaseInfoDto( + _fixture.Register(() => new ReleaseInfoModel( _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)), releaseYear, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)), @@ -287,53 +291,53 @@ public class AddBookRequestFixture _fixture.Create()[2..], _fixture.Create())); - _fixture.Register(() => new GenreDto( + _fixture.Register(() => new GenreModel( _fixture.Create() )); - _fixture.Register(() => new TagDto( + _fixture.Register(() => new TagModel( _fixture.Create() )); - _fixture.Register(() => new LanguageInfoDto( + _fixture.Register(() => new LanguageInfoModel( _fixture.Create(), _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new IsbnDto( + _fixture.Register(() => new IsbnModel( _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new BookRatingDto( + _fixture.Register(() => new BookRatingModel( _fixture.Create(), _fixture.Create(), _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new WrittenContentMetadataDto( + _fixture.Register(() => new WrittenContentMetadataModel( _fixture.Create()[255..], LimitStringLength(_fixture.Create(), 255), LimitStringLength(_fixture.Create(), 2000), - _fixture.Create(), - _fixture.Create>(), - _fixture.Create>(), - _fixture.Create(), - _fixture.Create(), + _fixture.Create(), + _fixture.Create>(), + _fixture.Create>(), + _fixture.Create(), + _fixture.Create(), _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new BookSeriesDto( + _fixture.Register(() => new BookSeriesModel( _fixture.Create() )); - _fixture.Register(() => new MediaContributorRoleDto( + _fixture.Register(() => new MediaContributorRoleModel( _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new MediaContributorNameDto( + _fixture.Register(() => new MediaContributorNameModel( _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new MediaContributorDto( - _fixture.Create(), - _fixture.Create() + _fixture.Register(() => new MediaContributorModel( + _fixture.Create(), + _fixture.Create() )); } diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/DomainBookFixture.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/DomainBookFixture.cs index 4df98f94..cd263b6c 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/DomainBookFixture.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Controllers/Books/Fixtures/DomainBookFixture.cs @@ -1,6 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.BookLibrary; using Lumina.Domain.Common.Primitives; using Lumina.Domain.Common.ValueObjects.Metadata; using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects; @@ -8,6 +8,8 @@ using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects; using Lumina.Presentation.Api.IntegrationTests.Common.Setup; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Lumina.Presentation.Api.IntegrationTests.csproj b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Lumina.Presentation.Api.IntegrationTests.csproj index f0bbb9de..91980a4b 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Lumina.Presentation.Api.IntegrationTests.csproj +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Lumina.Presentation.Api.IntegrationTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/BogusExtensions.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/BogusExtensions.cs index b3eb377e..32c37e40 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/BogusExtensions.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/BogusExtensions.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Bogus; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs index 8de9a4e3..e24b46fe 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture.Kernel; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs index 84706e0f..e9bc0c3d 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture.Kernel; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandlerTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandlerTests.cs index 8e552271..9817ed38 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandlerTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandHandlerTests.cs @@ -5,17 +5,20 @@ using ErrorOr; using FluentAssertions; using Lumina.Application.Common.DataAccess.Repositories.Books; using Lumina.Application.Common.DataAccess.UoW; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.UnitTests.Common.Setup; using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; using Lumina.Domain.Common.Errors; using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate; using MapsterMapper; using NSubstitute; +using System; using System.Diagnostics.CodeAnalysis; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; @@ -62,10 +65,10 @@ public class AddBookCommandHandlerTests { // Arrange var bookCommand = _commandBookFixture.CreateCommandBook(); - var bookDto = _fixture.Create(); + var bookModel = _fixture.Create(); - _mockMapper.Map(Arg.Any()).Returns(bookDto); - _mockBookRepository.InsertAsync(Arg.Any(), Arg.Any()) + _mockMapper.Map(Arg.Any()).Returns(bookModel); + _mockBookRepository.InsertAsync(Arg.Any(), Arg.Any()) .Returns(Result.Created); // Act @@ -74,7 +77,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeFalse(); result.Value.Should().BeOfType(); - await _mockBookRepository.Received(1).InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.Received(1).InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any()); } @@ -91,7 +94,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.TitleCannotBeEmpty.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -100,10 +103,10 @@ public class AddBookCommandHandlerTests { // Arrange var bookCommand = _commandBookFixture.CreateCommandBook(); - var bookDto = _fixture.Create(); + var bookModel = _fixture.Create(); - _mockMapper.Map(Arg.Any()).Returns(bookDto); - _mockBookRepository.InsertAsync(Arg.Any(), Arg.Any()) + _mockMapper.Map(Arg.Any()).Returns(bookModel); + _mockBookRepository.InsertAsync(Arg.Any(), Arg.Any()) .Returns(Errors.WrittenContent.BookAlreadyExists); // Act @@ -112,7 +115,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(Errors.WrittenContent.BookAlreadyExists); - await _mockBookRepository.Received(1).InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.Received(1).InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -121,7 +124,7 @@ public class AddBookCommandHandlerTests { // Arrange var bookCommand = _commandBookFixture.CreateCommandBook(); - bookCommand = bookCommand with { ISBNs = [new IsbnDto("invalid", IsbnFormat.Isbn13)] }; + bookCommand = bookCommand with { ISBNs = [new IsbnModel("invalid", IsbnFormat.Isbn13)] }; // Act var result = await _sut.Handle(bookCommand, CancellationToken.None); @@ -129,7 +132,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.WrittenContent.InvalidIsbn13Format.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -138,7 +141,7 @@ public class AddBookCommandHandlerTests { // Arrange var bookCommand = _commandBookFixture.CreateCommandBook(); - bookCommand = bookCommand with { Ratings = [new BookRatingDto(-1, 5, null, null)] }; + bookCommand = bookCommand with { Ratings = [new BookRatingModel(-1, 5, null, null)] }; // Act var result = await _sut.Handle(bookCommand, CancellationToken.None); @@ -146,7 +149,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.RatingValueMustBePositive.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -159,7 +162,7 @@ public class AddBookCommandHandlerTests { Metadata = bookCommand.Metadata with { - Genres = [new GenreDto("")] + Genres = [new GenreModel("")] } }; @@ -169,7 +172,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.GenreNameCannotBeEmpty.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -182,7 +185,7 @@ public class AddBookCommandHandlerTests { Metadata = bookCommand.Metadata with { - Tags = [new TagDto("")] + Tags = [new TagModel("")] } }; @@ -192,7 +195,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.TagNameCannotBeEmpty.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -205,7 +208,7 @@ public class AddBookCommandHandlerTests { Metadata = bookCommand.Metadata with { - ReleaseInfo = new ReleaseInfoDto( + ReleaseInfo = new ReleaseInfoModel( OriginalReleaseDate: new DateOnly(2025, 1, 1), ReReleaseDate: new DateOnly(2024, 1, 1), OriginalReleaseYear: null, @@ -222,7 +225,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -235,7 +238,7 @@ public class AddBookCommandHandlerTests { Metadata = bookCommand.Metadata with { - Language = new LanguageInfoDto("", "English", null) + Language = new LanguageInfoModel("", "English", null) } }; @@ -245,7 +248,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.LanguageCodeCannotBeEmpty.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } @@ -258,7 +261,7 @@ public class AddBookCommandHandlerTests { Metadata = bookCommand.Metadata with { - OriginalLanguage = new LanguageInfoDto("", "English", null) + OriginalLanguage = new LanguageInfoModel("", "English", null) } }; @@ -268,7 +271,7 @@ public class AddBookCommandHandlerTests // Assert result.IsError.Should().BeTrue(); result.Errors.Should().Contain(e => e.Code == Errors.Metadata.LanguageCodeCannotBeEmpty.Code); - await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); + await _mockBookRepository.DidNotReceive().InsertAsync(Arg.Any(), Arg.Any()); await _mockUnitOfWork.DidNotReceive().SaveChangesAsync(Arg.Any()); } #endregion diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidatorTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidatorTests.cs index 84d02fcf..f601cf62 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidatorTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/AddBookCommandValidatorTests.cs @@ -1,13 +1,13 @@ #region ========================================================================= USING ===================================================================================== +using Bogus; using FluentValidation.TestHelper; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures; -using System.Diagnostics.CodeAnalysis; +using Lumina.Contracts.Enums.BookLibrary; using Lumina.Domain.Common.Errors; -using Bogus; -using Lumina.Domain.Common.Enums; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; #endregion namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/Fixtures/AddBookCommandFixture.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/Fixtures/AddBookCommandFixture.cs index be870200..d3120647 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/Fixtures/AddBookCommandFixture.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/WrittenContentLibrary/BooksLibrary/Books/Commands/Fixtures/AddBookCommandFixture.cs @@ -1,13 +1,17 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture; using Bogus; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; -using Lumina.Application.Common.Models.Contributors; using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands; using Lumina.Application.UnitTests.Common.Setup; -using Lumina.Domain.Common.Enums; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.MediaContributors; +using Lumina.Contracts.Models.WrittenContentLibrary; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; #endregion namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.Fixtures; @@ -47,8 +51,8 @@ public class AddBookCommandFixture var releaseYear = _random.Next(2000, 2010); var reReleaseYear = _random.Next(2010, 2020); - var releaseInfo = new Faker() - .CustomInstantiator(f => new ReleaseInfoDto( + var releaseInfo = new Faker() + .CustomInstantiator(f => new ReleaseInfoModel( default, default, default, @@ -64,42 +68,42 @@ public class AddBookCommandFixture .RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50))) .Generate(); - var genre = new Faker() - .CustomInstantiator(f => new GenreDto( + var genre = new Faker() + .CustomInstantiator(f => new GenreModel( default! )) .RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50))); - var tag = new Faker() - .CustomInstantiator(f => new TagDto( + var tag = new Faker() + .CustomInstantiator(f => new TagModel( default! )) .RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50))); - var mediaContributorRole = new Faker() - .CustomInstantiator(f => new MediaContributorRoleDto( + var mediaContributorRole = new Faker() + .CustomInstantiator(f => new MediaContributorRoleModel( default!, default! )) .RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50))); - var mediaContributorName = new Faker() - .CustomInstantiator(f => new MediaContributorNameDto( + var mediaContributorName = new Faker() + .CustomInstantiator(f => new MediaContributorNameModel( default!, default! )) .RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50))); - var mediaContributor = new Faker() - .CustomInstantiator(f => new MediaContributorDto( + var mediaContributor = new Faker() + .CustomInstantiator(f => new MediaContributorModel( default!, default! )) .RuleFor(e => e.Name, mediaContributorName) .RuleFor(e => e.Role, mediaContributorRole); - var rating = new Faker() - .CustomInstantiator(f => new BookRatingDto( + var rating = new Faker() + .CustomInstantiator(f => new BookRatingModel( default, default, default, @@ -110,8 +114,8 @@ public class AddBookCommandFixture .RuleFor(e => e.Source, _fixture.Create()) .RuleFor(e => e.VoteCount, _random.Next(1, 1000)); - var language = new Faker() - .CustomInstantiator(f => new LanguageInfoDto( + var language = new Faker() + .CustomInstantiator(f => new LanguageInfoModel( default!, default!, default @@ -120,8 +124,8 @@ public class AddBookCommandFixture .RuleFor(e => e.LanguageCode, f => f.Random.String2(2)) .RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50))); - var originalLanguage = new Faker() - .CustomInstantiator(f => new LanguageInfoDto( + var originalLanguage = new Faker() + .CustomInstantiator(f => new LanguageInfoModel( default!, default!, default @@ -130,8 +134,8 @@ public class AddBookCommandFixture .RuleFor(e => e.LanguageCode, f => f.Random.String2(2)) .RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50))); - var metadata = new Faker() - .CustomInstantiator(f => new WrittenContentMetadataDto( + var metadata = new Faker() + .CustomInstantiator(f => new WrittenContentMetadataModel( default!, default, default, @@ -154,8 +158,8 @@ public class AddBookCommandFixture .RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100))) .RuleFor(x => x.PageCount, _random.Next(100, 300)); - var isbn = new Faker() - .CustomInstantiator(f => new IsbnDto( + var isbn = new Faker() + .CustomInstantiator(f => new IsbnModel( default!, default )) @@ -277,7 +281,7 @@ public class AddBookCommandFixture var releaseYear = _random.Next(2000, 2010); var reReleaseYear = _random.Next(2010, 2020); - _fixture.Register(() => new ReleaseInfoDto( + _fixture.Register(() => new ReleaseInfoModel( _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)), releaseYear, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)), @@ -285,53 +289,53 @@ public class AddBookCommandFixture _fixture.Create()[2..], _fixture.Create())); - _fixture.Register(() => new GenreDto( + _fixture.Register(() => new GenreModel( _fixture.Create() )); - _fixture.Register(() => new TagDto( + _fixture.Register(() => new TagModel( _fixture.Create() )); - _fixture.Register(() => new LanguageInfoDto( + _fixture.Register(() => new LanguageInfoModel( _fixture.Create(), _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new IsbnDto( + _fixture.Register(() => new IsbnModel( _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new BookRatingDto( + _fixture.Register(() => new BookRatingModel( _fixture.Create(), _fixture.Create(), _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new WrittenContentMetadataDto( + _fixture.Register(() => new WrittenContentMetadataModel( _fixture.Create()[255..], LimitStringLength(_fixture.Create(), 255), LimitStringLength(_fixture.Create(), 2000), - _fixture.Create(), - _fixture.Create>(), - _fixture.Create>(), - _fixture.Create(), - _fixture.Create(), + _fixture.Create(), + _fixture.Create>(), + _fixture.Create>(), + _fixture.Create(), + _fixture.Create(), _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new BookSeriesDto( + _fixture.Register(() => new BookSeriesModel( _fixture.Create() )); - _fixture.Register(() => new MediaContributorRoleDto( + _fixture.Register(() => new MediaContributorRoleModel( _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new MediaContributorNameDto( + _fixture.Register(() => new MediaContributorNameModel( _fixture.Create(), _fixture.Create() )); - _fixture.Register(() => new MediaContributorDto( - _fixture.Create(), - _fixture.Create() + _fixture.Register(() => new MediaContributorModel( + _fixture.Create(), + _fixture.Create() )); } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Lumina.Application.UnitTests.csproj b/tests/UnitTests/Lumina.Application.UnitTests/Lumina.Application.UnitTests.csproj index 0388cb46..3e5c41c3 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Lumina.Application.UnitTests.csproj +++ b/tests/UnitTests/Lumina.Application.UnitTests/Lumina.Application.UnitTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/DependencyInjection/DataAccessLayerServicesTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/DependencyInjection/DataAccessLayerServicesTests.cs index 6199a03f..344e740b 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/DependencyInjection/DataAccessLayerServicesTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/DependencyInjection/DataAccessLayerServicesTests.cs @@ -11,6 +11,8 @@ using Lumina.DataAccess.Core.UoW; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; #endregion namespace Lumina.DataAccess.UnitTests.Common.DependencyInjection; @@ -41,7 +43,7 @@ public class DataAccessLayerServicesTests { // Arrange var services = new ServiceCollection(); - var basePath = Path.GetTempPath(); // Use a real existing path + var basePath = Path.GetTempPath(); // use a real existing path // Act DataAccessLayerServices.AddDataAccessLayerServices(services); diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/BogusExtensions.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/BogusExtensions.cs index 38417286..6dd188cb 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/BogusExtensions.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/BogusExtensions.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Bogus; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs index 53bfe9c7..249e821c 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/DateOnlySpecimenBuilder.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture.Kernel; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs index 7a7dd522..447f4768 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Common/Setup/NullableDateOnlySpecimenBuilder.cs @@ -1,5 +1,6 @@ #region ========================================================================= USING ===================================================================================== using AutoFixture.Kernel; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/BookRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/BookRepositoryTests.cs index a0dad0bb..ae3bff8b 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/BookRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/BookRepositoryTests.cs @@ -2,15 +2,19 @@ using EntityFrameworkCore.Testing.NSubstitute; using ErrorOr; using FluentAssertions; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; using Lumina.DataAccess.Core.Repositories.Books; using Lumina.DataAccess.Core.UoW; using Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures; -using Lumina.Domain.Common.Enums; using Lumina.Domain.Common.Errors; using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books; @@ -24,7 +28,7 @@ public class BookRepositoryTests #region ================================================================== FIELD MEMBERS ================================================================================ private readonly LuminaDbContext _mockContext; private readonly BookRepository _sut; - private readonly BookDtoFixture _bookDtoFixture; + private readonly BookModelFixture _bookModelFixture; #endregion #region ====================================================================== CTOR ===================================================================================== @@ -35,7 +39,7 @@ public class BookRepositoryTests { _mockContext = Create.MockedDbContextFor(); _sut = new BookRepository(_mockContext); - _bookDtoFixture = new BookDtoFixture(); + _bookModelFixture = new BookModelFixture(); } #endregion @@ -44,18 +48,18 @@ public class BookRepositoryTests public async Task InsertAsync_WhenBookDoesNotExist_ShouldAddBookToContextAndReturnCreated() { // Arrange - var bookDto = _bookDtoFixture.CreateBookDto(); + var bookModel = _bookModelFixture.CreateBookModel(); // Act - var result = await _sut.InsertAsync(bookDto, CancellationToken.None); + var result = await _sut.InsertAsync(bookModel, CancellationToken.None); // Assert result.IsError.Should().BeFalse(); result.Value.Should().Be(Result.Created); // Check if the book was added to the context's ChangeTracker - var addedBook = _mockContext.ChangeTracker.Entries() - .FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookDto.Id); + var addedBook = _mockContext.ChangeTracker.Entries() + .FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id); addedBook.Should().NotBeNull(); } @@ -63,40 +67,40 @@ public class BookRepositoryTests public async Task InsertAsync_WhenBookAlreadyExists_ShouldReturnError() { // Arrange - var bookDto = _bookDtoFixture.CreateBookDto(); + var bookModel = _bookModelFixture.CreateBookModel(); - _mockContext.Books.Add(bookDto); + _mockContext.Books.Add(bookModel); await _mockContext.SaveChangesAsync(); // Act - var result = await _sut.InsertAsync(bookDto, CancellationToken.None); + var result = await _sut.InsertAsync(bookModel, CancellationToken.None); // Assert result.IsError.Should().BeTrue(); result.FirstError.Should().Be(Errors.WrittenContent.BookAlreadyExists); - _mockContext.ChangeTracker.Entries().Should().HaveCount(1); // Only the existing book should be in the context} + _mockContext.ChangeTracker.Entries().Should().HaveCount(1); // Only the existing book should be in the context} } [Fact] public async Task InsertAsync_WhenExistingTagsFound_ShouldReplaceTagsWithExistingOnes() { // Arrange - var existingTag = new TagDto("Existing"); - _mockContext.Set().Add(existingTag); + var existingTag = new TagModel("Existing"); + _mockContext.Set().Add(existingTag); await _mockContext.SaveChangesAsync(); - var bookDto = _bookDtoFixture.CreateBookDto(); - bookDto.Tags = [new("Existing"), new("New")]; + var bookModel = _bookModelFixture.CreateBookModel(); + bookModel.Tags = [new("Existing"), new("New")]; // Act - var result = await _sut.InsertAsync(bookDto, CancellationToken.None); + var result = await _sut.InsertAsync(bookModel, CancellationToken.None); // Assert result.IsError.Should().BeFalse(); result.Value.Should().Be(Result.Created); - var addedBook = _mockContext.ChangeTracker.Entries() - .FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookDto.Id); + var addedBook = _mockContext.ChangeTracker.Entries() + .FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id); addedBook.Should().NotBeNull(); var addedBookEntity = addedBook!.Entity; addedBookEntity.Tags.Should().HaveCount(2); @@ -108,22 +112,22 @@ public class BookRepositoryTests public async Task InsertAsync_WhenExistingGenresFound_ShouldReplaceGenresWithExistingOnes() { // Arrange - var existingGenre = new GenreDto("Existing"); - _mockContext.Set().Add(existingGenre); + var existingGenre = new GenreModel("Existing"); + _mockContext.Set().Add(existingGenre); await _mockContext.SaveChangesAsync(); - var bookDto = _bookDtoFixture.CreateBookDto(); - bookDto.Genres = [new("Existing"), new("New")]; + var bookModel = _bookModelFixture.CreateBookModel(); + bookModel.Genres = [new("Existing"), new("New")]; // Act - var result = await _sut.InsertAsync(bookDto, CancellationToken.None); + var result = await _sut.InsertAsync(bookModel, CancellationToken.None); // Assert result.IsError.Should().BeFalse(); result.Value.Should().Be(Result.Created); - var addedBook = _mockContext.ChangeTracker.Entries() - .FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookDto.Id); + var addedBook = _mockContext.ChangeTracker.Entries() + .FirstOrDefault(e => e.State == EntityState.Added && e.Entity.Id == bookModel.Id); addedBook.Should().NotBeNull(); var addedBookEntity = addedBook!.Entity; addedBookEntity.Genres.Should().HaveCount(2); @@ -135,11 +139,11 @@ public class BookRepositoryTests public async Task GetAllAsync_WhenCalled_ShouldReturnAllBooks() { // Arrange - var books = new List + var books = new List { - _bookDtoFixture.CreateBookDto(), - _bookDtoFixture.CreateBookDto(), - _bookDtoFixture.CreateBookDto() + _bookModelFixture.CreateBookModel(), + _bookModelFixture.CreateBookModel(), + _bookModelFixture.CreateBookModel() }; _mockContext.Books.AddRange(books); await _mockContext.SaveChangesAsync(); @@ -170,10 +174,10 @@ public class BookRepositoryTests public async Task GetAllAsync_WhenCalled_ShouldIncludeRelatedEntities() { // Arrange - var book = _bookDtoFixture.CreateBookDto(); - book.Tags = [new TagDto("Tag1"), new TagDto("Tag2")]; - book.Genres = [new GenreDto("Genre1"), new GenreDto("Genre2")]; - book.ISBNs = [new IsbnDto("1234567890", IsbnFormat.Isbn10), new IsbnDto("1234567890123", IsbnFormat.Isbn13)]; + var book = _bookModelFixture.CreateBookModel(); + book.Tags = [new TagModel("Tag1"), new TagModel("Tag2")]; + book.Genres = [new GenreModel("Genre1"), new GenreModel("Genre2")]; + book.ISBNs = [new IsbnModel("1234567890", IsbnFormat.Isbn10), new IsbnModel("1234567890123", IsbnFormat.Isbn13)]; _mockContext.Books.Add(book); await _mockContext.SaveChangesAsync(); diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/Fixtures/BookDtoFixture.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/Fixtures/BookModelFixture.cs similarity index 80% rename from tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/Fixtures/BookDtoFixture.cs rename to tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/Fixtures/BookModelFixture.cs index 70401e64..b8081405 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/Fixtures/BookDtoFixture.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Books/Fixtures/BookModelFixture.cs @@ -1,23 +1,23 @@ -using AutoFixture; +#region ========================================================================= USING ===================================================================================== +using AutoFixture; using Bogus; -using Lumina.Application.Common.Models.Books; -using Lumina.Application.Common.Models.Common; +using Lumina.Contracts.Enums.BookLibrary; +using Lumina.Contracts.Models.Common; +using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary; using Lumina.DataAccess.UnitTests.Common.Setup; -using Lumina.Domain.Common.Enums; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Text; -using System.Threading.Tasks; +#endregion namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures; /// -/// Fixture class for the class. +/// Fixture class for the class. /// [ExcludeFromCodeCoverage] -public class BookDtoFixture +public class BookModelFixture { #region ================================================================== FIELD MEMBERS ================================================================================ private readonly Fixture _fixture; @@ -27,9 +27,9 @@ public class BookDtoFixture #region ====================================================================== CTOR ===================================================================================== /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public BookDtoFixture() + public BookModelFixture() { _fixture = new Fixture(); _fixture.Customizations.Add(new DateOnlySpecimenBuilder()); @@ -41,15 +41,15 @@ public class BookDtoFixture #region ===================================================================== METHODS =================================================================================== /// - /// Creates a random valid BookDto. + /// Creates a random valid BookModel. /// - /// The created BookDto. - public BookDto CreateBookDto() + /// The created BookModel. + public BookModel CreateBookModel() { var releaseYear = _random.Next(2000, 2010); var reReleaseYear = _random.Next(2010, 2020); - return new Faker() + return new Faker() .RuleFor(x => x.Id, f => f.Random.Guid()) .RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255))) .RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255))) @@ -66,8 +66,8 @@ public class BookDtoFixture .RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2)) .RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50))) .RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50))) - .RuleFor(x => x.Tags, f => new HashSet(CreateTags(f.Random.Number(1, 5)))) - .RuleFor(x => x.Genres, f => new HashSet(CreateGenres(f.Random.Number(1, 5)))) + .RuleFor(x => x.Tags, f => new HashSet(CreateTags(f.Random.Number(1, 5)))) + .RuleFor(x => x.Genres, f => new HashSet(CreateGenres(f.Random.Number(1, 5)))) .RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100))) .RuleFor(x => x.PageCount, _random.Next(100, 300)) .RuleFor(x => x.Format, f => f.PickRandom().ToString()) @@ -89,17 +89,17 @@ public class BookDtoFixture .Generate(); } - private List CreateTags(int count) + private List CreateTags(int count) { - return new Faker() - .CustomInstantiator(f => new TagDto(f.Random.String2(f.Random.Number(1, 50)))) + return new Faker() + .CustomInstantiator(f => new TagModel(f.Random.String2(f.Random.Number(1, 50)))) .Generate(count); } - private List CreateGenres(int count) + private List CreateGenres(int count) { - return new Faker() - .CustomInstantiator(f => new GenreDto(f.Random.String2(f.Random.Number(1, 50)))) + return new Faker() + .CustomInstantiator(f => new GenreModel(f.Random.String2(f.Random.Number(1, 50)))) .Generate(count); } @@ -143,10 +143,10 @@ public class BookDtoFixture .ToArray()); } - private List CreateIsbns(int count) + private List CreateIsbns(int count) { - return new Faker() - .CustomInstantiator(f => new IsbnDto(CreateIsbn(f), f.PickRandom())) + return new Faker() + .CustomInstantiator(f => new IsbnModel(CreateIsbn(f), f.PickRandom())) .Generate(count); } @@ -180,10 +180,10 @@ public class BookDtoFixture } } - private List CreateBookRatings(int count) + private List CreateBookRatings(int count) { - return new Faker() - .CustomInstantiator(f => new BookRatingDto( + return new Faker() + .CustomInstantiator(f => new BookRatingModel( f.Random.Decimal(1, 5), 5, f.PickRandom(), @@ -194,10 +194,10 @@ public class BookDtoFixture private void ConfigureCustomTypes() { - _fixture.Register(() => new TagDto(_fixture.Create())); - _fixture.Register(() => new GenreDto(_fixture.Create())); - _fixture.Register(() => new IsbnDto(_fixture.Create(), _fixture.Create())); - _fixture.Register(() => new BookRatingDto( + _fixture.Register(() => new TagModel(_fixture.Create())); + _fixture.Register(() => new GenreModel(_fixture.Create())); + _fixture.Register(() => new IsbnModel(_fixture.Create(), _fixture.Create())); + _fixture.Register(() => new BookRatingModel( _fixture.Create(), _fixture.Create(), _fixture.Create(), @@ -205,4 +205,4 @@ public class BookDtoFixture )); } #endregion -} +} \ No newline at end of file diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryDictionaryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryDictionaryTests.cs index 4b258c5b..5f01ad4a 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryDictionaryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryDictionaryTests.cs @@ -5,6 +5,7 @@ using FluentAssertions; using Lumina.Application.Common.DataAccess.Repositories.Books; using Lumina.DataAccess.Core.Repositories.Books; using Lumina.DataAccess.Core.Repositories.Common.Factory; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryFactoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryFactoryTests.cs index ae0cf886..531480d1 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryFactoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/Common/Factory/RepositoryFactoryTests.cs @@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Books; using Lumina.DataAccess.Common.DependencyInjection; using Lumina.DataAccess.Core.Repositories.Common.Factory; using Microsoft.Extensions.DependencyInjection; +using System; using System.Diagnostics.CodeAnalysis; #endregion diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/UoW/UnitOfWorkTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/UoW/UnitOfWorkTests.cs index d0f7b9a9..4a7e3565 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/UoW/UnitOfWorkTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/UoW/UnitOfWorkTests.cs @@ -10,7 +10,10 @@ using Lumina.DataAccess.Core.UoW; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using NSubstitute; +using System; using System.Diagnostics.CodeAnalysis; +using System.Threading; +using System.Threading.Tasks; #endregion namespace Lumina.DataAccess.UnitTests.Core.UoW; diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Lumina.DataAccess.UnitTests.csproj b/tests/UnitTests/Lumina.DataAccess.UnitTests/Lumina.DataAccess.UnitTests.csproj index f187793e..71edc424 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Lumina.DataAccess.UnitTests.csproj +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Lumina.DataAccess.UnitTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false diff --git a/tests/UnitTests/Lumina.Domain.UnitTests/Lumina.Domain.UnitTests.csproj b/tests/UnitTests/Lumina.Domain.UnitTests/Lumina.Domain.UnitTests.csproj index cf923aca..be4836a0 100644 --- a/tests/UnitTests/Lumina.Domain.UnitTests/Lumina.Domain.UnitTests.csproj +++ b/tests/UnitTests/Lumina.Domain.UnitTests/Lumina.Domain.UnitTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false diff --git a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Utilities/OptionsBuilderFluentValidationUtilitiesTests.cs b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Utilities/OptionsBuilderFluentValidationUtilitiesTests.cs index 49d6d2f0..d2c17ba4 100644 --- a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Utilities/OptionsBuilderFluentValidationUtilitiesTests.cs +++ b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Utilities/OptionsBuilderFluentValidationUtilitiesTests.cs @@ -1,5 +1,4 @@ #region ========================================================================= USING ===================================================================================== -using System.Diagnostics.CodeAnalysis; using AutoFixture; using AutoFixture.AutoNSubstitute; using FluentAssertions; @@ -10,6 +9,9 @@ using Lumina.Infrastructure.UnitTests.Common.Utilities.Fixtures; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using NSubstitute; +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; #endregion namespace Lumina.Infrastructure.UnitTests.Common.Utilities; diff --git a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Validation/FluentValidationOptionsTests.cs b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Validation/FluentValidationOptionsTests.cs index 78a0e143..78773ef1 100644 --- a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Validation/FluentValidationOptionsTests.cs +++ b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Common/Validation/FluentValidationOptionsTests.cs @@ -4,11 +4,13 @@ using AutoFixture.AutoNSubstitute; using FluentAssertions; using FluentValidation; using FluentValidation.Results; +using Lumina.Infrastructure.Common.Validation; +using Lumina.Infrastructure.UnitTests.Common.Validation.Fixtures; using Microsoft.Extensions.Options; using NSubstitute; -using Lumina.Infrastructure.Common.Validation; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using Lumina.Infrastructure.UnitTests.Common.Validation.Fixtures; #endregion namespace Lumina.Infrastructure.UnitTests.Common.Validation; diff --git a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Lumina.Infrastructure.UnitTests.csproj b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Lumina.Infrastructure.UnitTests.csproj index f482e7cc..cebfc1ff 100644 --- a/tests/UnitTests/Lumina.Infrastructure.UnitTests/Lumina.Infrastructure.UnitTests.csproj +++ b/tests/UnitTests/Lumina.Infrastructure.UnitTests/Lumina.Infrastructure.UnitTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false diff --git a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Lumina.Presentation.Api.UnitTests.csproj b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Lumina.Presentation.Api.UnitTests.csproj index 2e19ff5d..2bbe3be7 100644 --- a/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Lumina.Presentation.Api.UnitTests.csproj +++ b/tests/UnitTests/Lumina.Presentation.Api.UnitTests/Lumina.Presentation.Api.UnitTests.csproj @@ -2,7 +2,7 @@ net8.0 - enable + disable enable false