Replaces MVC with FastEndpoints in Lumina.Presentation.Api

This commit is contained in:
BinaryAlley committed 2024-10-23 21:34:10 +03:00
1 parent b1a20716df
commit c7b8bc2f1c
519 files changed
+15329 -8539

No files matched your search

@@ -3,7 +3,6 @@ using ErrorOr;
using FluentValidation;
using Mediator;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -51,4 +50,4 @@ public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TReques
// this is acceptable because we DO know that we will always have a list of errors of type ErrorOr (check the generic constraint at the top of the class!)
return (dynamic)errors;
}
}
}
@@ -1,44 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
#endregion
namespace Lumina.Application.Common.Converters;
/// <summary>
/// Converts an <see cref="Optional{TValue}"/> to and from JSON.
/// </summary>
/// <typeparam name="TValue">The type of the value represented by the <see cref="Optional{TValue}"/> structure.</typeparam>
public class OptionalJsonConverter<TValue> : JsonConverter<Optional<TValue>>
{
/// <summary>
/// Reads and converts the JSON to an instance of <see cref="Optional{TValue}"/>.
/// </summary>
/// <param name="reader">The <see cref="Utf8JsonReader"/> to read from.</param>
/// <param name="typeToConvert">The type to convert.</param>
/// <param name="options">An object that specifies serialization options to use.</param>
/// <returns>The converted <see cref="Optional{TValue}"/> value.</returns>
public override Optional<TValue> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
return Optional<TValue>.None();
TValue? value = JsonSerializer.Deserialize<TValue>(ref reader, options);
return Optional<TValue>.Some(value!);
}
/// <summary>
/// Writes an <see cref="Optional{TValue}"/> value as JSON.
/// </summary>
/// <param name="writer">The <see cref="Utf8JsonWriter"/> to write to.</param>
/// <param name="value">The value to convert to JSON.</param>
/// <param name="options">An object that specifies serialization options to use.</param>
public override void Write(Utf8JsonWriter writer, Optional<TValue> value, JsonSerializerOptions options)
{
if (value.HasValue)
JsonSerializer.Serialize(writer, value.Value, options);
else
writer.WriteNullValue();
}
}
@@ -1,38 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
#endregion
namespace Lumina.Application.Common.Converters;
/// <summary>
/// A factory for creating <see cref="OptionalJsonConverter{T}"/> instances.
/// </summary>
public class OptionalJsonConverterFactory : JsonConverterFactory
{
/// <summary>
/// Determines whether the converter can convert the specified type.
/// </summary>
/// <param name="typeToConvert">The type to check for convertibility.</param>
/// <returns><see langword="true"/> if the type is <see cref="Optional{TValue}"/>, <see langword="false"/> otherwise.</returns>
public override bool CanConvert(Type typeToConvert)
{
return typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(Optional<>);
}
/// <summary>
/// Creates a converter for the specified type.
/// </summary>
/// <param name="typeToConvert">The type for which to create a converter.</param>
/// <param name="options">The serializer options to use.</param>
/// <returns>A converter for <see cref="Optional{TValue}"/>.</returns>
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
Type valueType = typeToConvert.GetGenericArguments()[0];
JsonConverter converter = (JsonConverter)Activator.CreateInstance(
typeof(OptionalJsonConverter<>).MakeGenericType(valueType))!;
return converter;
}
}
@@ -1,7 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Contracts.Models.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
@@ -9,8 +10,8 @@ namespace Lumina.Application.Common.DataAccess.Repositories.Books;
/// <summary>
/// Interface for the repository for books.
/// </summary>
public interface IBookRepository : IRepository<BookModel>,
IInsertRepositoryAction<BookModel>,
IGetAllRepositoryAction<BookModel>
public interface IBookRepository : IRepository<BookEntity>,
IInsertRepositoryAction<BookEntity>,
IGetAllRepositoryAction<BookEntity>
{
}
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.Common;
using Lumina.Contracts.Entities.Common;
#endregion
@@ -1,8 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Application.Common.Behaviors;
using Mapster;
using MapsterMapper;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
#endregion
@@ -33,12 +31,6 @@ public static class ApplicationLayerServices
// register fluent validators
services.AddValidatorsFromAssembly(typeof(ApplicationLayerServices).Assembly);
// register mapster configs in this assembly
TypeAdapterConfig mapsterConfig = TypeAdapterConfig.GlobalSettings;
mapsterConfig.Scan(typeof(ApplicationLayerServices).Assembly);
services.AddSingleton(mapsterConfig);
services.AddScoped<IMapper, ServiceMapper>();
return services;
}
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.Common.Metadata;
/// <summary>
/// Extension methods for converting <see cref="Genre"/>.
/// </summary>
public static class GenreMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="GenreEntity"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static GenreEntity ToRepositoryEntity(this Genre domainModel)
{
return new GenreEntity(
domainModel.Name
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="GenreEntity"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<GenreEntity> ToRepositoryEntities(this IEnumerable<Genre> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToRepositoryEntity());
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.Common.Metadata;
/// <summary>
/// Extension methods for converting <see cref="GenreEntity"/>.
/// </summary>
public static class GenreModelMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="GenreEntity"/>.
/// </summary>
/// <param name="repositoryEntity">The repository model to be converted.</param>
/// <returns>The converted domain model.</returns>
public static ErrorOr<Genre> ToDomainModel(this GenreEntity repositoryEntity)
{
return Genre.Create(
repositoryEntity.Name
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Genre"/>.
/// </summary>
/// <param name="repositoryEntities">The repository models to be converted.</param>
/// <returns>The converted domain models.</returns>
public static IEnumerable<ErrorOr<Genre>> ToDomainModels(this IEnumerable<GenreEntity> repositoryEntities)
{
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainModel());
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.Common.Metadata;
/// <summary>
/// Extension methods for converting <see cref="Tag"/>.
/// </summary>
public static class TagMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="TagEntity"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static TagEntity ToRepositoryEntity(this Tag domainModel)
{
return new TagEntity(
domainModel.Name
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="TagEntity"/>.
/// </summary>
/// <param name="domainModels">The domain model to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<TagEntity> ToRepositoryEntities(this IEnumerable<Tag> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToRepositoryEntity());
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.Common.Metadata;
/// <summary>
/// Extension methods for converting <see cref="TagEntity"/>.
/// </summary>
public static class TagModelMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Tag"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted domain model.</returns>
public static ErrorOr<Tag> ToDomainModel(this TagEntity repositoryEntity)
{
return Tag.Create(
repositoryEntity.Name
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Tag"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted domain models.</returns>
public static IEnumerable<ErrorOr<Tag>> ToDomainModels(this IEnumerable<TagEntity> repositoryEntities)
{
return repositoryEntities.Select(domainModel => domainModel.ToDomainModel());
}
}
@@ -1,50 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.FileManagement;
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Mapster;
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system directories between the domain object and the presentation object.
/// </summary>
public class DirectoryMappingConfig : IRegister
{
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Directory, FileSystemTreeNodeResponse>()
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.ItemType, src => src.Type)
.Map(dest => dest.IsExpanded, () => false)
.Map(dest => dest.ChildrenLoaded, () => false)
.Map(dest => dest.Children, src => src.Items.Adapt<List<FileSystemTreeNodeResponse>>())
.MapToConstructor(true);
config.NewConfig<Directory, DirectoryResponse>()
.MapWith(src => new DirectoryResponse(
src.Id.Path,
src.Name,
src.DateCreated.Value,
src.DateModified.Value,
src.Items.Adapt<List<FileSystemItemModel>>()
));
config.NewConfig<FileSystemItem, FileSystemItemModel>()
.MapWith(src => new FileSystemItemModel(
src.Id.Path,
src.Name,
DateTime.Now,
DateTime.Now
));
}
}
@@ -1,37 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
using Mapster;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system files between the domain object and the presentation object.
/// </summary>
public class FileMappingConfig : IRegister
{
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<File, FileSystemTreeNodeResponse>()
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.ItemType, src => src.Type)
.Map(dest => dest.IsExpanded, () => false)
.Map(dest => dest.ChildrenLoaded, () => false)
.MapToConstructor(true);
config.NewConfig<File, FileResponse>()
.MapWith(src => new FileResponse(
src.Id.Path,
src.Name,
src.DateCreated.HasValue ? src.DateCreated.Value : default,
src.DateModified.HasValue ? src.DateModified.Value : default,
src.Size
));
}
}
@@ -1,65 +0,0 @@
#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;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system trees between the domain object and the presentation object.
/// </summary>
public class FileSystemTreeMappingConfig : IRegister
{
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<WindowsRootItem, FileSystemTreeNodeResponse>()
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.ItemType, src => FileSystemItemType.Root)
.Map(dest => dest.IsExpanded, () => false);
config.NewConfig<FileSystemTreeNodeResponse, WindowsRootItem>()
.MapWith(src => WindowsRootItem.Create(
src.Path,
src.Name,
FileSystemItemStatus.Accessible)
.Value);
config.NewConfig<UnixRootItem, FileSystemTreeNodeResponse>()
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.ItemType, src => FileSystemItemType.Root)
.Map(dest => dest.IsExpanded, () => false)
.Map(dest => dest.ChildrenLoaded, () => false)
.Map(dest => dest.Children, src => src.Items.Select(item => item.Adapt<FileSystemTreeNodeResponse>(config)).ToList());
config.NewConfig<FileSystemTreeNodeResponse, UnixRootItem>()
.MapWith(src => UnixRootItem.Create(
FileSystemItemStatus.Accessible)
.Value);
config.NewConfig<FileSystemItem, FileSystemTreeNodeResponse>()
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Path, src => src.Id.Path)
.Map(dest => dest.ItemType, src => src.Type)
.Map(dest => dest.IsExpanded, _ => false)
.Map(dest => dest.ChildrenLoaded, _ => false)
.Map(dest => dest.ChildrenLoaded, _ => false)
.AfterMapping((src, dest) =>
{
if (src is Directory dir)
dest.Children = dir.Items.Select(item => item.Adapt<FileSystemTreeNodeResponse>(config)).ToList();
else
dest.Children = [];
});
}
}
@@ -1,24 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using Mapster;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system paths between the domain object and the presentation object.
/// </summary>
public class PathSegmentMappingConfig : IRegister
{
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<PathSegment, PathSegmentResponse>()
.Map(dest => dest.Path, src => src.Name)
.MapToConstructor(true);
}
}
@@ -1,25 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileManagement;
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
using Mapster;
#endregion
namespace Lumina.Application.Common.Mapping.FileManagement;
/// <summary>
/// Mapping configuration for file system thumbnails between the domain object and the presentation object.
/// </summary>
public class ThumbnailMappingConfig : IRegister
{
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Thumbnail, ThumbnailResponse>()
.Map(dest => dest.Type, src => src.Type)
.Map(dest => dest.Bytes, src => src.Bytes)
.MapToConstructor(true);
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Common;
/// <summary>
/// Extension methods for converting <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
public static class FileSystemTreeNodeResponseMapping
{
/// <summary>
/// Converts <paramref name="response"/> to <see cref="WindowsRootItem"/>.
/// </summary>
/// <param name="response">The response to be converted.</param>
/// <returns>The converted domain model.</returns>
public static ErrorOr<WindowsRootItem> ToWindowsRootItem(this FileSystemTreeNodeResponse response)
{
return WindowsRootItem.Create(
response.Path,
response.Name,
FileSystemItemStatus.Accessible
);
}
/// <summary>
/// Converts <paramref name="_"/> to <see cref="UnixRootItem"/>.
/// </summary>
/// <param name="_">The response to be converted.</param>
/// <returns>The converted domain model.</returns>
public static ErrorOr<UnixRootItem> ToUnixRootItem(this FileSystemTreeNodeResponse _)
{
return UnixRootItem.Create(
FileSystemItemStatus.Accessible
);
}
}
@@ -0,0 +1,72 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
/// <summary>
/// Extension methods for converting <see cref="Directory"/>.
/// </summary>
public static class DirectoryMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToFileSystemTreeNodeResponse(this Directory domainModel)
{
return new FileSystemTreeNodeResponse()
{
Name = domainModel.Name,
Path = domainModel.Id.Path,
ItemType = domainModel.Type,
IsExpanded = false,
ChildrenLoaded = false,
Children = domainModel.Items.Select(item => item.ToTreeNodeResponse())
.ToList()
};
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<FileSystemTreeNodeResponse> ToFileSystemTreeNodeResponses(this IEnumerable<Directory> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToTreeNodeResponse());
}
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static DirectoryResponse ToResponse(this Directory domainModel)
{
return new DirectoryResponse(
domainModel.Id.Path,
domainModel.Name,
domainModel.DateCreated.Value,
domainModel.DateModified.Value,
domainModel.Items.Select(fileSystemItem => fileSystemItem.ToFileSystemItemModel())
.ToList()
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<DirectoryResponse> ToResponses(this IEnumerable<Directory> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToResponse());
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
/// <summary>
/// Extension methods for converting <see cref="GetDirectoriesRequest"/>.
/// </summary>
public static class GetDirectoriesRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetDirectoriesQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetDirectoriesQuery ToQuery(this GetDirectoriesRequest request)
{
return new GetDirectoriesQuery(request.Path, request.IncludeHiddenElements);
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
/// <summary>
/// Extension methods for converting <see cref="GetDirectoryTreeRequest"/>.
/// </summary>
public static class GetDirectoryTreeRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetDirectoryTreeQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetDirectoryTreeQuery ToQuery(this GetDirectoryTreeRequest request)
{
return new GetDirectoryTreeQuery(request.Path, request.IncludeFiles, request.IncludeHiddenElements);
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
/// <summary>
/// Extension methods for converting <see cref="GetTreeDirectoriesRequest"/>.
/// </summary>
public static class GetTreeDirectoriesRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetTreeDirectoriesQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetTreeDirectoriesQuery ToQuery(this GetTreeDirectoriesRequest request)
{
return new GetTreeDirectoriesQuery(request.Path, request.IncludeHiddenElements);
}
}
@@ -0,0 +1,64 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
using Lumina.Contracts.Entities.FileSystemManagement;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
/// <summary>
/// Extension methods for converting <see cref="FileSystemItem"/>.
/// </summary>
public static class FileSystemItemMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileSystemItemEntity"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted model.</returns>
public static FileSystemItemEntity ToFileSystemItemModel(this FileSystemItem domainModel)
{
return new FileSystemItemEntity(
domainModel.Id.Path,
domainModel.Name,
DateTime.Now,
DateTime.Now
);
}
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted model.</returns>
/// <exception cref="ArgumentException">Thrown when the provided parameter is not an expected descendant of <see cref="FileSystemItem"/>.</exception>
public static FileSystemTreeNodeResponse ToTreeNodeResponse(this FileSystemItem domainModel)
{
if (domainModel is Directory directory)
return directory.ToFileSystemTreeNodeResponse();
else if (domainModel is File file)
return file.ToFileSystemTreeNodeResponse();
else if (domainModel is WindowsRootItem windowsRootItem)
return windowsRootItem.ToTreeNodeResponse();
else if (domainModel is UnixRootItem unixRootItem)
return unixRootItem.ToTreeNodeResponse();
else
throw new ArgumentException("Invalid FileSystemItem");
}
/// <summary>
/// Converts <paramref name="domainModels"/> to <see cref="IEnumerable<FileSystemTreeNodeResponse>"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted models.</returns>
public static IEnumerable<FileSystemTreeNodeResponse> ToTreeNodeResponses(this IEnumerable<FileSystemItem> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToTreeNodeResponse());
}
}
@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
/// <summary>
/// Extension methods for converting <see cref="UnixRootItem"/>.
/// </summary>
public static class UnixRootItemMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToTreeNodeResponse(this UnixRootItem domainModel)
{
return new FileSystemTreeNodeResponse()
{
Path = domainModel.Id.Path,
Name = domainModel.Name,
ItemType = FileSystemItemType.Root,
IsExpanded = false,
ChildrenLoaded = false,
Children = domainModel.Items.Select(item => item.ToTreeNodeResponse())
.ToList()
};
}
}
@@ -0,0 +1,32 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.FileSystemManagement.Common;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
/// <summary>
/// Extension methods for converting <see cref="WindowsRootItem"/>.
/// </summary>
public static class WindowsRootItemMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToTreeNodeResponse(this WindowsRootItem domainModel)
{
return new FileSystemTreeNodeResponse()
{
Path = domainModel.Id.Path,
Name = domainModel.Name,
ItemType = FileSystemItemType.Root,
IsExpanded = false
};
}
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Files;
/// <summary>
/// Extension methods for converting <see cref="File"/>.
/// </summary>
public static class FileMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToFileSystemTreeNodeResponse(this File domainModel)
{
return new FileSystemTreeNodeResponse()
{
Name = domainModel.Name,
Path = domainModel.Id.Path,
ItemType = domainModel.Type,
IsExpanded = false,
ChildrenLoaded = false
};
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<FileSystemTreeNodeResponse> ToFileSystemTreeNodeResponses(this IEnumerable<File> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToFileSystemTreeNodeResponse());
}
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="FileResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static FileResponse ToResponse(this File domainModel)
{
return new FileResponse(
domainModel.Id.Path,
domainModel.Name,
domainModel.DateCreated.HasValue ? domainModel.DateCreated.Value : default,
domainModel.DateModified.HasValue ? domainModel.DateModified.Value : default,
domainModel.Size
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="FileResponse"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<FileResponse> ToResponses(this IEnumerable<File> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToResponse());
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Files;
/// <summary>
/// Extension methods for converting <see cref="GetFilesRequest"/>.
/// </summary>
public static class GetFilesRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetFilesQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetFilesQuery ToQuery(this GetFilesRequest request)
{
return new GetFilesQuery(request.Path, request.IncludeHiddenElements);
}
}
@@ -0,0 +1,23 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Files;
/// <summary>
/// Extension methods for converting <see cref="GetTreeFilesRequest"/>.
/// </summary>
public static class GetTreeFilesRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetTreeDirectoriesQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetTreeFilesQuery ToQuery(this GetTreeFilesRequest request)
{
return new GetTreeFilesQuery(request.Path, request.IncludeHiddenElements);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="CheckPathExistsRequest"/>.
/// </summary>
public static class CheckPathExistsQueryMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="CheckPathExistsQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static CheckPathExistsQuery ToQuery(this CheckPathExistsRequest request)
{
return new CheckPathExistsQuery(
request.Path,
request.IncludeHiddenElements
);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="CombinePathRequest"/>.
/// </summary>
public static class CombinePathRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="CombinePathCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static CombinePathCommand ToCommand(this CombinePathRequest request)
{
return new CombinePathCommand(
request.OriginalPath,
request.NewPath
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="GetPathParentRequest"/>.
/// </summary>
public static class GetPathParentRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetPathParentQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetPathParentQuery ToQuery(this GetPathParentRequest request)
{
return new GetPathParentQuery(
request.Path
);
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="GetPathRootRequest"/>.
/// </summary>
public static class GetPathRootRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetPathRootQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetPathRootQuery ToQuery(this GetPathRootRequest request)
{
return new GetPathRootQuery(request.Path);
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="PathSegment"/>.
/// </summary>
public static class PathSegmentMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="PathSegmentResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static PathSegmentResponse ToResponse(this PathSegment domainModel)
{
return new PathSegmentResponse(
domainModel.Name
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="PathSegmentResponse"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<PathSegmentResponse> ToResponses(this IEnumerable<PathSegment> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToResponse());
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="SplitPathRequest"/>.
/// </summary>
public static class SplitPathRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="SplitPathCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static SplitPathCommand ToCommand(this SplitPathRequest request)
{
return new SplitPathCommand(
request.Path
);
}
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Extension methods for converting <see cref="ValidatePathRequest"/>.
/// </summary>
public static class ValidatePathRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="ValidatePathQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static ValidatePathQuery ToQuery(this ValidatePathRequest request)
{
return new ValidatePathQuery(
request.Path
);
}
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
/// <summary>
/// Extension methods for converting <see cref="GetThumbnailRequest"/>.
/// </summary>
public static class GetThumbnailRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetThumbnailQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetThumbnailQuery ToQuery(this GetThumbnailRequest request)
{
return new GetThumbnailQuery(request.Path, request.Quality);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
#endregion
namespace Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
/// <summary>
/// Extension methods for converting <see cref="Thumbnail"/>.
/// </summary>
public static class ThumbnailMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="ThumbnailResponse"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted response.</returns>
public static ThumbnailResponse ToResponse(this Thumbnail domainModel)
{
return new ThumbnailResponse(
domainModel.Type,
domainModel.Bytes
);
}
}
@@ -1,132 +0,0 @@
#region ========================================================================= USING =====================================================================================
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;
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;
/// <summary>
/// Mapping configuration for books between the domain object and the persistence object.
/// </summary>
public class BookMappingConfig : IRegister
{
/// <summary>
/// Registers the mapping configuration.
/// </summary>
/// <param name="config">The type adapter configuration.</param>
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Book, BookModel>()
.Map(dest => dest.Id, src => src.Id.Value)
.Map(dest => dest.Title, src => src.Metadata.Title)
.Map(dest => dest.OriginalTitle, src => src.Metadata.OriginalTitle.HasValue ? src.Metadata.OriginalTitle.Value : default)
.Map(dest => dest.Description, src => src.Metadata.Description.HasValue ? src.Metadata.Description.Value : default)
.Map(dest => dest.OriginalReleaseDate, src => src.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? src.Metadata.ReleaseInfo.OriginalReleaseDate.Value : default)
.Map(dest => dest.OriginalReleaseYear, src => src.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? src.Metadata.ReleaseInfo.OriginalReleaseYear.Value : default)
.Map(dest => dest.ReReleaseDate, src => src.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? src.Metadata.ReleaseInfo.ReReleaseDate.Value : default)
.Map(dest => dest.ReReleaseYear, src => src.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? src.Metadata.ReleaseInfo.ReReleaseYear.Value : default)
.Map(dest => dest.ReleaseCountry, src => src.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? src.Metadata.ReleaseInfo.ReleaseCountry.Value : default)
.Map(dest => dest.ReleaseVersion, src => src.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? src.Metadata.ReleaseInfo.ReleaseVersion.Value : default)
.Map(dest => dest.LanguageCode, src => src.Metadata.Language.HasValue ? src.Metadata.Language.Value.LanguageCode : default)
.Map(dest => dest.LanguageName, src => src.Metadata.Language.HasValue ? src.Metadata.Language.Value.LanguageName : default)
.Map(dest => dest.LanguageNativeName, src => src.Metadata.Language.HasValue ? src.Metadata.Language.Value.NativeName : default)
.Map(dest => dest.OriginalLanguageCode, src => src.Metadata.OriginalLanguage.HasValue ? src.Metadata.OriginalLanguage.Value.LanguageCode : default)
.Map(dest => dest.OriginalLanguageName, src => src.Metadata.OriginalLanguage.HasValue ? src.Metadata.OriginalLanguage.Value.LanguageName : default)
.Map(dest => dest.OriginalLanguageNativeName, src => src.Metadata.OriginalLanguage.HasValue ? src.Metadata.OriginalLanguage.Value.NativeName : default)
.Map(dest => dest.Tags, src => src.Metadata.Tags)
.Map(dest => dest.Genres, src => src.Metadata.Genres)
.Map(dest => dest.Publisher, src => src.Metadata.Publisher.HasValue ? src.Metadata.Publisher.Value : default)
.Map(dest => dest.PageCount, src => src.Metadata.PageCount.HasValue ? src.Metadata.PageCount.Value : default)
.Map(dest => dest.Format, src => src.Format.ToString())
.Map(dest => dest.Edition, src => src.Edition.HasValue ? src.Edition.Value : default)
.Map(dest => dest.VolumeNumber, src => src.VolumeNumber.HasValue ? src.VolumeNumber.Value : default)
.Map(dest => dest.ASIN, src => src.ASIN.HasValue ? src.ASIN.Value : default)
.Map(dest => dest.GoodreadsId, src => src.GoodreadsId.HasValue ? src.GoodreadsId.Value : default)
.Map(dest => dest.LCCN, src => src.LCCN.HasValue ? src.LCCN.Value : default)
.Map(dest => dest.OCLCNumber, src => src.OCLCNumber.HasValue ? src.OCLCNumber.Value : default)
.Map(dest => dest.OpenLibraryId, src => src.OpenLibraryId.HasValue ? src.OpenLibraryId.Value : default)
.Map(dest => dest.LibraryThingId, src => src.LibraryThingId.HasValue ? src.LibraryThingId.Value : default)
.Map(dest => dest.GoogleBooksId, src => src.GoogleBooksId.HasValue ? src.GoogleBooksId.Value : default)
.Map(dest => dest.BarnesAndNobleId, src => src.BarnesAndNobleId.HasValue ? src.BarnesAndNobleId.Value : default)
.Map(dest => dest.AppleBooksId, src => src.AppleBooksId.HasValue ? src.AppleBooksId.Value : default)
.Map(dest => dest.ISBNs, src => src.ISBNs)
.Map(dest => dest.Ratings, src => src.Ratings)
.Map(dest => dest.Created, src => src.Created)
.Map(dest => dest.Updated, src => src.Updated.HasValue ? src.Updated : null);
config.NewConfig<BookRating, BookRatingModel>()
.Map(dest => dest.Value, src => src.Value)
.Map(dest => dest.MaxValue, src => src.MaxValue)
.Map(dest => dest.VoteCount, src => src.VoteCount.HasValue ? src.VoteCount.Value : default)
.Map(dest => dest.Source, src => src.Source.HasValue ? src.Source.Value : default);
config.NewConfig<Optional<BookRatingSource>, BookRatingSource?>()
.MapWith(src => src.HasValue ? src.Value : default);
// from BookModel to Book
config.NewConfig<BookModel, Book>()
.MapWith(src => Book.Create(
BookId.Create(src.Id),
WrittenContentMetadata.Create(
src.Title,
Optional<string>.FromNullable(src.OriginalTitle),
Optional<string>.FromNullable(src.Description),
ReleaseInfo.Create(
Optional<DateOnly>.FromNullable(src.OriginalReleaseDate),
Optional<int>.FromNullable(src.OriginalReleaseYear),
Optional<DateOnly>.FromNullable(src.ReReleaseDate),
Optional<int>.FromNullable(src.ReReleaseYear),
Optional<string>.FromNullable(src.ReleaseCountry),
Optional<string>.FromNullable(src.ReleaseVersion)
).Value,
src.Genres.Select(g => Genre.Create(g.Name!).Value).ToList(),
src.Tags.Select(t => Tag.Create(t.Name!).Value).ToList(),
src.LanguageCode != null ? LanguageInfo.Create(
src.LanguageCode,
src.LanguageName!,
Optional<string>.FromNullable(src.LanguageNativeName)
).Value : Optional<LanguageInfo>.None(),
src.OriginalLanguageCode != null ? LanguageInfo.Create(
src.OriginalLanguageCode,
src.OriginalLanguageName!,
Optional<string>.FromNullable(src.OriginalLanguageNativeName)
).Value : Optional<LanguageInfo>.None(),
Optional<string>.FromNullable(src.Publisher),
Optional<int>.FromNullable(src.PageCount)
).Value,
Optional<BookFormat>.FromNullable(!string.IsNullOrWhiteSpace(src.Format) ? Enum.Parse<BookFormat>(src.Format) : default),
Optional<string>.FromNullable(src.Edition),
Optional<int>.FromNullable(src.VolumeNumber),
Optional<BookSeries>.None(),
Optional<string>.FromNullable(src.ASIN),
Optional<string>.FromNullable(src.GoodreadsId),
Optional<string>.FromNullable(src.LCCN),
Optional<string>.FromNullable(src.OCLCNumber),
Optional<string>.FromNullable(src.OpenLibraryId),
Optional<string>.FromNullable(src.LibraryThingId),
Optional<string>.FromNullable(src.GoogleBooksId),
Optional<string>.FromNullable(src.BarnesAndNobleId),
Optional<string>.FromNullable(src.AppleBooksId),
src.Created,
Optional<DateTime>.FromNullable(src.Updated),
src.ISBNs.Select(i => Isbn.Create(i.Value!, i.Format ?? default).Value).ToList(),
new List<MediaContributorId>(),
src.Ratings.Select(r => BookRating.Create(
r.Value ?? default,
r.MaxValue ?? default,
Optional<BookRatingSource>.FromNullable(r.Source),
Optional<int>.FromNullable(r.VoteCount)
).Value).ToList()
).Value);
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary.Books;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Extension methods for converting <see cref="AddBookRequest"/>.
/// </summary>
public static class AddBookRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="AddBookCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static AddBookCommand ToCommand(this AddBookRequest request)
{
return new AddBookCommand(
request.Metadata,
request.Format,
request.Edition,
request.VolumeNumber,
request.Series,
request.ASIN,
request.GoodreadsId,
request.LCCN,
request.OCLCNumber,
request.OpenLibraryId,
request.LibraryThingId,
request.GoogleBooksId,
request.BarnesAndNobleId,
request.AppleBooksId,
request.ISBNs,
request.Contributors,
request.Ratings
);
}
}
@@ -0,0 +1,64 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Extension methods for converting <see cref="Book"/>.
/// </summary>
public static class BookMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="BookEntity"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static BookEntity ToRepositoryEntity(this Book domainModel)
{
return new BookEntity
{
Id = domainModel.Id.Value,
Title = domainModel.Metadata.Title,
OriginalTitle = domainModel.Metadata.OriginalTitle.HasValue ? domainModel.Metadata.OriginalTitle.Value : null,
Description = domainModel.Metadata.Description.HasValue ? domainModel.Metadata.Description.Value : null,
OriginalReleaseDate = domainModel.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? domainModel.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null,
OriginalReleaseYear = domainModel.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? domainModel.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null,
ReReleaseDate = domainModel.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? domainModel.Metadata.ReleaseInfo.ReReleaseDate.Value : null,
ReReleaseYear = domainModel.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? domainModel.Metadata.ReleaseInfo.ReReleaseYear.Value : null,
ReleaseCountry = domainModel.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? domainModel.Metadata.ReleaseInfo.ReleaseCountry.Value : null,
ReleaseVersion = domainModel.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? domainModel.Metadata.ReleaseInfo.ReleaseVersion.Value : null,
LanguageCode = domainModel.Metadata.Language.HasValue ? domainModel.Metadata.Language.Value.LanguageCode : null,
LanguageName = domainModel.Metadata.Language.HasValue ? domainModel.Metadata.Language.Value.LanguageName : null,
LanguageNativeName = domainModel.Metadata.Language.HasValue ? domainModel.Metadata.Language.Value.NativeName.Value : null,
OriginalLanguageCode = domainModel.Metadata.OriginalLanguage.HasValue ? domainModel.Metadata.OriginalLanguage.Value.LanguageCode : null,
OriginalLanguageName = domainModel.Metadata.OriginalLanguage.HasValue ? domainModel.Metadata.OriginalLanguage.Value.LanguageName : null,
OriginalLanguageNativeName = domainModel.Metadata.OriginalLanguage.HasValue ? domainModel.Metadata.OriginalLanguage.Value.NativeName.Value : null,
Tags = domainModel.Metadata.Tags.ToRepositoryEntities().ToHashSet(),
Genres = domainModel.Metadata.Genres.ToRepositoryEntities().ToHashSet(),
Publisher = domainModel.Metadata.Publisher.HasValue ? domainModel.Metadata.Publisher.Value : null,
PageCount = domainModel.Metadata.PageCount.HasValue ? domainModel.Metadata.PageCount.Value : null,
Format = domainModel.Format.ToString(),
Edition = domainModel.Edition.HasValue ? domainModel.Edition.Value : null,
VolumeNumber = domainModel.VolumeNumber.HasValue ? domainModel.VolumeNumber.Value : null,
ASIN = domainModel.ASIN.HasValue ? domainModel.ASIN.Value : null,
GoodreadsId = domainModel.GoodreadsId.HasValue ? domainModel.GoodreadsId.Value : null,
LCCN = domainModel.LCCN.HasValue ? domainModel.LCCN.Value : null,
OCLCNumber = domainModel.OCLCNumber.HasValue ? domainModel.OCLCNumber.Value : null,
OpenLibraryId = domainModel.OpenLibraryId.HasValue ? domainModel.OpenLibraryId.Value : null,
LibraryThingId = domainModel.LibraryThingId.HasValue ? domainModel.LibraryThingId.Value : null,
GoogleBooksId = domainModel.GoogleBooksId.HasValue ? domainModel.GoogleBooksId.Value : null,
BarnesAndNobleId = domainModel.BarnesAndNobleId.HasValue ? domainModel.BarnesAndNobleId.Value : null,
AppleBooksId = domainModel.AppleBooksId.HasValue ? domainModel.AppleBooksId.Value : null,
ISBNs = domainModel.ISBNs.ToRepositoryEntities().ToList(),
Ratings = domainModel.Ratings.ToRepositoryEntities().ToList(),
Created = domainModel.Created,
Updated = domainModel.Updated.HasValue ? domainModel.Updated : null
};
}
}
@@ -0,0 +1,223 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Contracts.Entities.Common;
using Lumina.Contracts.Entities.WrittenContentLibrary;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
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;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Extension methods for converting <see cref="BookEntity"/>.
/// </summary>
public static class BookModelMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Book"/>.
/// </summary>
/// <param name="repositoryEntity">The repository model to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Book"/>, or an error message.
/// </returns>
public static ErrorOr<Book> ToDomainModel(this BookEntity repositoryEntity)
{
IEnumerable<ErrorOr<Tag>> tagsResult = repositoryEntity.Tags.ToDomainModels();
foreach (ErrorOr<Tag> tagResult in tagsResult)
if (tagResult.IsError)
return tagResult.Errors;
IEnumerable<ErrorOr<Genre>> genresResult = repositoryEntity.Genres.ToDomainModels();
foreach (ErrorOr<Genre> genreResult in genresResult)
if (genreResult.IsError)
return genreResult.Errors;
IEnumerable<ErrorOr<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainModels();
foreach (ErrorOr<Isbn> isbnResult in isbnsResult)
if (isbnResult.IsError)
return isbnResult.Errors;
IEnumerable<ErrorOr<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainModels();
foreach (ErrorOr<BookRating> bookRatingResult in bookRatingsResult)
if (bookRatingResult.IsError)
return bookRatingResult.Errors;
ErrorOr<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
Optional<DateOnly>.FromNullable(repositoryEntity.OriginalReleaseDate),
Optional<int>.FromNullable(repositoryEntity.OriginalReleaseYear),
Optional<DateOnly>.FromNullable(repositoryEntity.ReReleaseDate),
Optional<int>.FromNullable(repositoryEntity.ReReleaseYear),
Optional<string>.FromNullable(repositoryEntity.ReleaseCountry),
Optional<string>.FromNullable(repositoryEntity.ReleaseVersion)
);
if (releaseInfoResult.IsError)
return releaseInfoResult.Errors;
Optional<LanguageInfo> languageInfo = Optional<LanguageInfo>.None();
if (repositoryEntity.LanguageCode is not null)
{
ErrorOr<LanguageInfo> languageInfoResult = LanguageInfo.Create(
repositoryEntity.LanguageCode,
repositoryEntity.LanguageName,
Optional<string>.FromNullable(repositoryEntity.LanguageNativeName)
);
if (languageInfoResult.IsError)
return languageInfoResult.Errors;
languageInfo = languageInfoResult.Value;
}
Optional<LanguageInfo> originalLanguageCode = Optional<LanguageInfo>.None();
if (repositoryEntity.OriginalLanguageCode is not null)
{
ErrorOr<LanguageInfo> originalLanguageInfoResult = LanguageInfo.Create(
repositoryEntity.OriginalLanguageCode,
repositoryEntity.OriginalLanguageName!,
Optional<string>.FromNullable(repositoryEntity.OriginalLanguageNativeName)
);
if (originalLanguageInfoResult.IsError)
return originalLanguageInfoResult.Errors;
originalLanguageCode = originalLanguageInfoResult.Value;
}
ErrorOr<WrittenContentMetadata> writtenContentMetadataResult = WrittenContentMetadata.Create(
repositoryEntity.Title,
Optional<string>.FromNullable(repositoryEntity.OriginalTitle),
Optional<string>.FromNullable(repositoryEntity.Description),
releaseInfoResult.Value,
genresResult.Select(genre => genre.Value).ToList(),
tagsResult.Select(tag => tag.Value).ToList(),
languageInfo,
originalLanguageCode,
Optional<string>.FromNullable(repositoryEntity.Publisher),
Optional<int>.FromNullable(repositoryEntity.PageCount)
);
if (writtenContentMetadataResult.IsError)
return writtenContentMetadataResult.Errors;
Optional<BookFormat> bookFormat = Optional<BookFormat>.FromNullable(!string.IsNullOrWhiteSpace(repositoryEntity.Format) ? Enum.Parse<BookFormat>(repositoryEntity.Format) : (BookFormat?)null);
return Book.Create(
BookId.Create(repositoryEntity.Id),
writtenContentMetadataResult.Value,
bookFormat,
Optional<string>.FromNullable(repositoryEntity.Edition),
Optional<int>.FromNullable(repositoryEntity.VolumeNumber),
Optional<BookSeries>.None(),
Optional<string>.FromNullable(repositoryEntity.ASIN),
Optional<string>.FromNullable(repositoryEntity.GoodreadsId),
Optional<string>.FromNullable(repositoryEntity.LCCN),
Optional<string>.FromNullable(repositoryEntity.OCLCNumber),
Optional<string>.FromNullable(repositoryEntity.OpenLibraryId),
Optional<string>.FromNullable(repositoryEntity.LibraryThingId),
Optional<string>.FromNullable(repositoryEntity.GoogleBooksId),
Optional<string>.FromNullable(repositoryEntity.BarnesAndNobleId),
Optional<string>.FromNullable(repositoryEntity.AppleBooksId),
repositoryEntity.Created,
Optional<DateTime>.FromNullable(repositoryEntity.Updated),
isbnsResult.Select(isbn => isbn.Value).ToList(),
[],
bookRatingsResult.Select(bookRating => bookRating.Value).ToList());
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Book"/>.
/// </summary>
/// <param name="repositoryEntities">The repository models to be converted.</param>
/// <returns>The converted domain models.</returns>
/// <returns>
/// An colection of <see cref="ErrorOr{TValue}"/> containing either successfully converted <see cref="Book"/>, or error messages.
/// </returns>
public static IEnumerable<ErrorOr<Book>> ToDomainModels(this IEnumerable<BookEntity> repositoryEntities)
{
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainModel());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The repository model to be converted.</param>
/// <returns>The converted response model.</returns>
public static BookResponse ToResponse(this BookEntity repositoryEntity)
{
ReleaseInfoEntity releaseInfoModel = new(
repositoryEntity.OriginalReleaseDate,
repositoryEntity.OriginalReleaseYear,
repositoryEntity.ReReleaseDate,
repositoryEntity.ReReleaseYear,
repositoryEntity.ReleaseCountry,
repositoryEntity.ReleaseVersion
);
// language and original language make sense only if their subproperties have values
LanguageInfoEntity? languageInfoModel = (!string.IsNullOrWhiteSpace(repositoryEntity.LanguageCode) ||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageName) ||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageNativeName))
? new LanguageInfoEntity(
repositoryEntity.LanguageCode,
repositoryEntity.LanguageName,
repositoryEntity.LanguageNativeName
) : null;
LanguageInfoEntity? originalLanguageInfoModel = (!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageCode) ||
!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageName) ||
!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageNativeName))
? new LanguageInfoEntity(
repositoryEntity.OriginalLanguageCode,
repositoryEntity.OriginalLanguageName,
repositoryEntity.OriginalLanguageNativeName
) : null;
WrittenContentMetadataEntity metadata = new(
repositoryEntity.Title,
repositoryEntity.OriginalTitle,
repositoryEntity.Description,
releaseInfoModel,
[.. repositoryEntity.Genres],
[.. repositoryEntity.Tags],
languageInfoModel,
originalLanguageInfoModel,
repositoryEntity.Publisher,
repositoryEntity.PageCount
);
return new BookResponse(
repositoryEntity.Id,
metadata,
!string.IsNullOrWhiteSpace(repositoryEntity.Format) ? Enum.Parse<BookFormat>(repositoryEntity.Format) : null,
repositoryEntity.Edition,
repositoryEntity.VolumeNumber,
null,
repositoryEntity.ASIN,
repositoryEntity.GoodreadsId,
repositoryEntity.LCCN,
repositoryEntity.OCLCNumber,
repositoryEntity.OpenLibraryId,
repositoryEntity.LibraryThingId,
repositoryEntity.GoogleBooksId,
repositoryEntity.BarnesAndNobleId,
repositoryEntity.AppleBooksId,
repositoryEntity.ISBNs,
null,
repositoryEntity.Ratings,
repositoryEntity.Created,
repositoryEntity.Updated
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Book"/>.
/// </summary>
/// <param name="repositoryEntities">The repository models to be converted.</param>
/// <returns>The converted reponses.</returns>
public static IEnumerable<BookResponse> ToResponses(this IEnumerable<BookEntity> repositoryEntities)
{
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToResponse());
}
}
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="BookRating"/>.
/// </summary>
public static class BookRatingMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="BookRatingEntity"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static BookRatingEntity ToRepositoryEntity(this BookRating domainModel)
{
return new BookRatingEntity(
domainModel.Value,
domainModel.MaxValue,
domainModel.Source.HasValue ? domainModel.Source.Value : null,
domainModel.VoteCount.HasValue ? domainModel.VoteCount.Value : null
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="BookRatingEntity"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<BookRatingEntity> ToRepositoryEntities(this IEnumerable<BookRating> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToRepositoryEntity());
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="BookRatingEntity"/>.
/// </summary>
public static class BookRatingModelMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookRating"/>.
/// </summary>
/// <param name="repositoryEntity">The repository model to be converted.</param>
/// <returns>The converted domain model.</returns>
public static ErrorOr<BookRating> ToDomainModel(this BookRatingEntity repositoryEntity)
{
return BookRating.Create(
repositoryEntity.Value ?? default,
repositoryEntity.MaxValue ?? default,
Optional<BookRatingSource>.FromNullable(repositoryEntity.Source),
Optional<int>.FromNullable(repositoryEntity.VoteCount)
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="BookRating"/>.
/// </summary>
/// <param name="repositoryEntities">The repository models to be converted.</param>
/// <returns>The converted domain models.</returns>
public static IEnumerable<ErrorOr<BookRating>> ToDomainModels(this IEnumerable<BookRatingEntity> repositoryEntities)
{
return repositoryEntities.Select(domainModel => domainModel.ToDomainModel());
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="Isbn"/>.
/// </summary>
public static class IsbnMapping
{
/// <summary>
/// Converts <paramref name="domainModel"/> to <see cref="IsbnEntity"/>.
/// </summary>
/// <param name="domainModel">The domain model to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static IsbnEntity ToRepositoryEntity(this Isbn domainModel)
{
return new IsbnEntity(
domainModel.Value,
domainModel.Format
);
}
/// <summary>
/// Converts <paramref name="domainModels"/> to a collection of <see cref="IsbnEntity"/>.
/// </summary>
/// <param name="domainModels">The domain models to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<IsbnEntity> ToRepositoryEntities(this IEnumerable<Isbn> domainModels)
{
return domainModels.Select(domainModel => domainModel.ToRepositoryEntity());
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="IsbnEntity"/>.
/// </summary>
public static class IsbnModelMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Isbn"/>.
/// </summary>
/// <param name="repositoryEntity">The repository model to be converted.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully converted <see cref="Isbn"/>, or an error message.
/// </returns>
public static ErrorOr<Isbn> ToDomainModel(this IsbnEntity repositoryEntity)
{
return Isbn.Create(
repositoryEntity.Value,
repositoryEntity.Format ?? IsbnFormat.Isbn13
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Isbn"/>.
/// </summary>
/// <param name="repositoryEntities">The repository models to be converted.</param>
/// <returns>The converted domain models.</returns>
public static IEnumerable<ErrorOr<Isbn>> ToDomainModels(this IEnumerable<IsbnEntity> repositoryEntities)
{
return repositoryEntities.Select(domainModel => domainModel.ToDomainModel());
}
}