Updates to .NET 9.0

This commit is contained in:
BinaryAlley committed 2024-11-13 20:46:54 +02:00
commit acbdb0a5f8
853 files changed
+34993 -10123

No files matched your search

+6 -2
View File
@@ -4,10 +4,14 @@ on:
pull_request:
branches:
- master
workflow_dispatch: # enable manual triggers
jobs:
test:
runs-on: ubuntu-latest
run-platform-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
- name: Set up .NET
+2 -2
View File
@@ -1,4 +1,4 @@
name: Branch Naming Convention Check
name: Branch Push Naming Convention Check
on:
push:
@@ -6,7 +6,7 @@ on:
- master
jobs:
check-branch-name:
validate-branch-push:
runs-on: ubuntu-latest
steps:
- name: Check branch name
@@ -1,4 +1,4 @@
name: PR Source Branch Check
name: Pull Request Source Branch Validation Check
on:
pull_request:
@@ -6,7 +6,7 @@ on:
- master
jobs:
check-branch-name:
validate-pr-source:
runs-on: ubuntu-latest
steps:
- name: Check source branch name
+2 -1
View File
@@ -31,7 +31,8 @@ bld/
*.sln.iml
# Common
*.Development.json
*.[Dd]evelopment.json
*.[Tt]est.json
# Windows image file caches
Thumbs.db
+2
View File
@@ -38,6 +38,8 @@ Several icons used in this project were adapted from icons sourced from [svgrepo
- [`toggle-thumbnails.svg`](https://www.svgrepo.com/svg/370469/page-image) (Public Domain license)
- [`toggle-hidden.svg`](https://www.svgrepo.com/svg/470389/hidden) (MIT License)
- [`delete.svg`](https://www.svgrepo.com/svg/488148/delete) (MIT License)
- [`add-directory.svg`](https://www.svgrepo.com/svg/488040/add-folder) (MIT License)
## License
+1 -29
View File
@@ -99,39 +99,11 @@ public interface IUserService
### C# Specific
#### Code Conventions:
- Each class, interface and struct should use the following `#region`s to group code sections:
- Group `using`s with the following `#region`:
```csharp
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Current.Namespace;
public class DhlDeliveryServiceProvider : IDeliveryServiceProvider
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly ITaxCalculator _taxCalculator;
#endregion
#region ====================================================================== CTOR =====================================================================================
public GetDirectoryTreeQueryHandler(ITaxCalculator taxCalculator)
{
_taxCalculator = taxCalculator;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
public void Deliver()
{
// code
}
public decimal CalculateCost()
{
// code
}
#endregion
}
```
- Enforce one type per file. For example:
```csharp
+17
View File
@@ -0,0 +1,17 @@
## Reverse Proxy Setup
### Rate Limiting Headers
The application uses IP-based rate limiting on some endpoints. When deploying behind a reverse proxy, you must forward the
original client IP, otherwise the "per IP" rate limiting will become global, per any request aimed at those endpoints, regardless of origin:
```text
# Nginx
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Apache
RemoteIPHeader X-Forwarded-For
# Caddy
reverse_proxy {
header_up X-Forwarded-For {remote_host}
}
```
+76
View File
@@ -0,0 +1,76 @@
<span style="color: #FF0000;">Domain</span>
├── <span style="color: #004BFF;">Audio Library Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #F589DD;">Audio Library Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #BDE180;">Audio Metadata</span>
├── <span style="color: #004BFF;">Video Library Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #F589DD;">Movie Library Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Movie Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Video Metadata</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Movie Library Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">Movie</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #F589DD;">Tv Show Library Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Episode Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Season Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Tv Show Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">Episode</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">Season</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Tv Show Library Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">Tv Show</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #FEB423;">Video Library Service</span>
├── <span style="color: #004BFF;">Photo Library Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #F589DD;">Photo Library Aggregate</span>
├── <span style="color: #004BFF;">Written Content Library Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #F589DD;">Book Library Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Book Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Book Rating</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Book Series Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">ISBN</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Written Content Metadata</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">Book Series</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Book Library Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">Book</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #F589DD;">Magazine Library Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">Magazine</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #FEB423;">Written Content Library Service</span>
├── <span style="color: #004BFF;">Media Contributor Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #F589DD;">Media Contributor Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Contributor Name</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Media Contributor Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Media Contributor Role</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">Media Contributor</span>
├── <span style="color: #004BFF;">Library Management Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #F589DD;">Library Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Library Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">Library</span>
├── <span style="color: #004BFF;">User Management Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #F589DD;">User Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">User Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">User</span>
├── <span style="color: #004BFF;">File System Management Bounded Context</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #F589DD;">File System Management Aggregate</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">File System Path Id</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Path Segment</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Stream Info</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #BDE180;">Thumbnail</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">Directory</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">File</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">UNIX Root Item</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #80B0E0;">Windows Root Item</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Directory Provider Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">File Provider Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Directory Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">File Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Drive Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Path Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">Thumbnail Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">File System Permissions Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├── <span style="color: #FEB423;">File Type Service</span>
│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└── <span style="color: #B46DD4;">File System Item</span>
<span style="color: #004BFF;">&bull; Bounded Context</span>
<span style="color: #F589DD;">&bull; Aggregate</span>
<span style="color: #B46DD4;">&bull; Aggregate Root</span>
<span style="color: #80B0E0;">&bull; Entity</span>
<span style="color: #BDE180;">&bull; Value Object</span>
<span style="color: #E14B5B;">&bull; Event</span>
<span style="color: #FEB423;">&bull; Service</span>
+6 -5
View File
@@ -95,6 +95,7 @@
- ComicSeries
- Magazine
- MagazineIssue
- Newspaper
- Manga
- GraphicNovel
- AcademicPaper
@@ -117,11 +118,11 @@
- 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, EBook, BookSeries, ComicBook, ComicSeries, Magazine, MagazineIssue, Manga, GraphicNovel, AcademicPaper, SheetMusic, Screenplay)
- WrittenContentLibrary (root: WrittenContentLibrary, entities: Book, EBook, BookSeries, ComicBook, ComicSeries, Magazine, MagazineIssue, Newspaper, 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)
- FileManagement (root: File, entities: Stream)
- FileSystemManagement (root: File, entities: Stream)
- WrittenContentLibrary
- BookLibrary (root: BookLibrary)
@@ -133,7 +134,7 @@
- Value Objects: ComicMetadata, SeriesInfo
- PeriodicalLibrary (root: PeriodicalLibrary)
- Entities: Magazine, MagazineIssue
- Entities: Magazine, MagazineIssue, Newspaper
- Value Objects: PeriodicalMetadata, IssueInfo
- AcademicLibrary (root: AcademicLibrary)
@@ -219,7 +220,7 @@
- Aggregates: UserProfile
- Services: RecommendationEngine, ContentCurationService, UserActivityTrackingService
- ContentDelivery
- Aggregates: FileManagement
- Aggregates: FileSystemManagement
- Services: StreamingService, ContentSynchronizationService
- MetadataManagement
- Aggregates: SupplementaryContentLibrary
@@ -235,4 +236,4 @@
- PlaylistRepository
- CollectionRepository
- FileRepository
- StreamRepository
- StreamRepository
@@ -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;
}
}
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.Common;
/// <summary>
/// Represents a genre.
/// </summary>
/// <param name="Name">Gets the name of the genre.</param>
[DebuggerDisplay("Name: {Name}")]
public record GenreEntity(
string? Name
);
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Contracts.Models.Common;
namespace Lumina.Application.Common.DataAccess.Entities.Common;
/// <summary>
/// Interface for storage models, enforces Id.
@@ -15,12 +15,12 @@ public interface IStorageEntity
Guid Id { get; init; }
/// <summary>
/// The time and date when the entity was added.
/// Gets or sets the time and date when the entity was added.
/// </summary>
DateTime Created { get; set; }
/// <summary>
/// The time and date when the entity was updated.
/// Gets or sets the optional time and date when the entity was updated.
/// </summary>
DateTime? Updated { get; set; }
}
}
@@ -2,7 +2,7 @@
using System.Diagnostics;
#endregion
namespace Lumina.Contracts.Models.Common;
namespace Lumina.Application.Common.DataAccess.Entities.Common;
/// <summary>
/// Represents a rating.
@@ -11,8 +11,8 @@ namespace Lumina.Contracts.Models.Common;
/// <param name="MaxValue">Gets the maximum possible rating value.</param>
/// <param name="VoteCount">Gets the number of votes that contributed to the rating.</param>
[DebuggerDisplay("{Value}/{MaxValue}")]
public abstract record RatingModel(
public abstract record RatingEntity(
decimal? Value,
decimal? MaxValue,
int? VoteCount
);
);
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.Common;
/// <summary>
/// Represents a tag.
/// </summary>
/// <param name="Name">Gets the name of the tag.</param>
[DebuggerDisplay("Name: {Name}")]
public record TagEntity(
string? Name
);
@@ -0,0 +1,21 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.FileSystemManagement;
/// <summary>
/// Generic filesystem data transfer object.
/// </summary>
/// <param name="Path">The path of the file system item.</param>
/// <param name="Name">The name of the file system item.</param>
/// <param name="DateCreated">The creation date of the file system item.</param>
/// <param name="DateModified">The modification date of the file system item.</param>
[DebuggerDisplay("Name: {Name}")]
public record FileSystemItemEntity(
string Path,
string Name,
DateTime DateCreated,
DateTime DateModified
);
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
/// <summary>
/// Repository entity for a media contributor.
/// </summary>
/// <param name="Name">The name details of the media contributor, including display and legal names.</param>
/// <param name="Role">The role details of the media contributor, including the role name and category.</param>
[DebuggerDisplay("Name: {Name}, Role: {Role}")]
public record MediaContributorEntity(
MediaContributorNameEntity? Name,
MediaContributorRoleEntity? Role
);
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
/// <summary>
/// Repository entity for a media contributor name.
/// </summary>
/// <param name="DisplayName">The display name of the media contributor.</param>
/// <param name="LegalName">The legal name of the media contributor.</param>
[DebuggerDisplay("DisplayName: {DisplayName}")]
public record MediaContributorNameEntity(
string? DisplayName,
string? LegalName
);
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaContributors;
/// <summary>
/// Repository entity for a media contributor role.
/// </summary>
/// <param name="Name">The name of the role assigned to the media contributor.</param>
/// <param name="Category">The category of the role.</param>
[DebuggerDisplay("Name: {Name}, Category: {Category}")]
public record MediaContributorRoleEntity(
string? Name,
string? Category
);
@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Repository entity for a media library content location.
/// </summary>
[DebuggerDisplay("Path: {Path}")]
public class LibraryContentLocationEntity
{
/// <summary>
/// Gets or sets the path of the media library content location.
/// </summary>
public required string Path { get; set; }
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Domain.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Repository entity for a media library.
/// </summary>
[DebuggerDisplay("Title: {Title}")]
public class LibraryEntity : IStorageEntity
{
/// <summary>
/// Gets the Id of the media library.
/// </summary>
public required Guid Id { get; init; }
/// <summary>
/// Gets the Id of the user that owns the media library.
/// </summary>
public required Guid UserId { get; init; }
/// <summary>
/// Gets or sets the title of the media library.
/// </summary>
public required string Title { get; set; }
/// <summary>
/// Gets or sets the type of the media library.
/// </summary>
public required LibraryType LibraryType { get; set; }
/// <summary>
/// Gets or sets the list of file system paths that make up the media library.
/// </summary>
public required ICollection<LibraryContentLocationEntity> ContentLocations { get; init; } = [];
/// <summary>
/// Gets the user that owns the media library.
/// </summary>
public UserEntity User { get; init; } = null!;
/// <summary>
/// Gets or sets the time and date when the entity was added.
/// </summary>
public required DateTime Created { get; set; }
/// <summary>
/// Gets or sets the optional time and date when the entity was updated.
/// </summary>
public DateTime? Updated { get; set; }
}
@@ -0,0 +1,207 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Repository entity for a book.
/// </summary>
[DebuggerDisplay("Title: {Title}")]
public class BookEntity : IStorageEntity
{
/// <summary>
/// Gets the Id of the media item.
/// </summary>
public required Guid Id { get; init; }
/// <summary>
/// Gets or sets the title of the media item.
/// </summary>
public required string Title { get; set; }
/// <summary>
/// Gets or sets the original title of the media item.
/// </summary>
public string? OriginalTitle { get; set; }
/// <summary>
/// Gets or sets the optional description of the media item.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// Gets or sets the optional original release date of the media item.
/// </summary>
public DateOnly? OriginalReleaseDate { get; set; }
/// <summary>
/// Gets or sets the optional original release year of the media item.
/// This is useful when only the year of original release is known.
/// </summary>
public int? OriginalReleaseYear { get; set; }
/// <summary>
/// Gets or sets the optional re-release or reissue date of the media item.
/// </summary>
public DateOnly? ReReleaseDate { get; set; }
/// <summary>
/// Gets or sets the optional re-release or reissue year of the media item.
/// </summary>
public int? ReReleaseYear { get; set; }
/// <summary>
/// Gets or sets the optional country or region of release.
/// </summary>
public string? ReleaseCountry { get; set; }
/// <summary>
/// Gets or sets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0")
/// </summary>
public string? ReleaseVersion { get; set; }
/// <summary>
/// Gets or sets the ISO 639-1 two-letter language code.
/// </summary>
public string? LanguageCode { get; set; }
/// <summary>
/// Gets or sets the full name of the language in English.
/// </summary>
public string? LanguageName { get; set; }
/// <summary>
/// Gets or sets an optional native name of the language.
/// </summary>
public string? LanguageNativeName { get; set; }
/// <summary>
/// Gets or sets the optional ISO 639-1 two-letter original language code.
/// </summary>
public string? OriginalLanguageCode { get; set; }
/// <summary>
/// Gets or sets the optional full name of the original language in English.
/// </summary>
public string? OriginalLanguageName { get; set; }
/// <summary>
/// Gets or sets an optional native name of the original language.
/// </summary>
public string? OriginalLanguageNativeName { get; set; }
/// <summary>
/// Gets or sets the list of tags associated with the media item.
/// </summary>
public HashSet<TagEntity> Tags { get; set; } = [];
/// <summary>
/// Gets or sets the list of genres associated with the media item.
/// </summary>
public HashSet<GenreEntity> Genres { get; set; } = [];
/// <summary>
/// Gets or sets the publisher of the written content.
/// </summary>
public string? Publisher { get; set; }
/// <summary>
/// Gets or sets the number of pages in the written content.
/// </summary>
public int? PageCount { get; set; }
/// <summary>
/// Gets or sets the format of the book (e.g., Hardcover, Paperback), if applicable.
/// </summary>
public BookFormat? Format { get; set; }
/// <summary>
/// Gets or sets the edition of the book, if applicable.
/// </summary>
public string? Edition { get; set; }
/// <summary>
/// Gets or sets the volume or book number in the series, if applicable.
/// </summary>
public int? VolumeNumber { get; set; }
// TODO: uncomment when series is implemented
/// <summary>
/// Gets or sets the series id, if the book is part of a series.
/// </summary>
//public Guid? BookSeriesId { get; set; }
/// <summary>
/// Gets or sets the ASIN (Amazon Standard Identification Number) of the book.
/// </summary>
public string? ASIN { get; set; }
/// <summary>
/// Gets or sets the Goodreads ID of the book.
/// </summary>
public string? GoodreadsId { get; set; }
/// <summary>
/// Gets or sets the Library of Congress Control Number (LCCN) of the book.
/// </summary>
public string? LCCN { get; set; }
/// <summary>
/// Gets or sets the OCLC Number (WorldCat identifier) of the book.
/// </summary>
public string? OCLCNumber { get; set; }
/// <summary>
/// Gets or sets the Open Library ID of the book.
/// </summary>
public string? OpenLibraryId { get; set; }
/// <summary>
/// Gets or sets the LibraryThing ID of the book.
/// </summary>
public string? LibraryThingId { get; set; }
/// <summary>
/// Gets or sets the Google Books ID of the book.
/// </summary>
public string? GoogleBooksId { get; set; }
/// <summary>
/// Gets or sets the Barnes & Noble ID of the book.
/// </summary>
public string? BarnesAndNobleId { get; set; } = null!;
/// <summary>
/// Gets or sets the Apple Books ID of the book.
/// </summary>
public string? AppleBooksId { get; set; }
/// <summary>
/// Gets or sets the list of ISBN (International Standard Book Number) of the book.
/// </summary>
public List<IsbnEntity> ISBNs { get; set; } = [];
/// <summary>
/// Gets or sets the list of media contributors (actors, directors, etc) starring in this book.
/// </summary>
//public List<ContributorIdModel> ContributorIds { get; set; } = [];
/// <summary>
/// Gets or sets the list of ratings for this book.
/// </summary>
public List<BookRatingEntity> Ratings { get; set; } = [];
/// <summary>
/// Gets or sets the time and date when the entity was added.
/// </summary>
public required DateTime Created { get; set; }
/// <summary>
/// Gets or sets the optional time and date when the entity was updated.
/// </summary>
public DateTime? Updated { get; set; }
}
@@ -0,0 +1,22 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Domain.Common.Enums.BookLibrary;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Repository entity for a book rating.
/// </summary>
/// <param name="Value">The rating value for the book.</param>
/// <param name="MaxValue">The maximum possible rating value for the book.</param>
/// <param name="Source">The source of the book rating (e.g., a specific website or platform).</param>
/// <param name="VoteCount">The number of votes that contributed to the book rating.</param>
[DebuggerDisplay("{Value}/{MaxValue}")]
public record BookRatingEntity(
decimal? Value,
decimal? MaxValue,
BookRatingSource? Source,
int? VoteCount
) : RatingEntity(Value, MaxValue, VoteCount);
@@ -0,0 +1,14 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Repository entity for book series.
/// </summary>
/// <param name="Title">The title of the book series.</param>
[DebuggerDisplay("Title: {Title}")]
public record BookSeriesEntity(
string? Title
);
@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums.BookLibrary;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Repository entity for ISBN information.
/// </summary>
/// <param name="Value">The ISBN value.</param>
/// <param name="Format">The format of the ISBN (e.g., ISBN-10 or ISBN-13).</param>
[DebuggerDisplay("ISBN: {Value} ({Format})")]
public record IsbnEntity(
string? Value,
IsbnFormat? Format
);
@@ -0,0 +1,71 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Common.DataAccess.Entities.UsersManagement;
/// <summary>
/// Repository entity for a user.
/// </summary>
[DebuggerDisplay("Username: {Username}")]
public class UserEntity : IStorageEntity
{
/// <summary>
/// Gets the Id of the user.
/// </summary>
public Guid Id { get; init; }
/// <summary>
/// Gets or sets the username of the user.
/// </summary>
public required string Username { get; set; }
/// <summary>
/// Gets or sets the hashed password of the user.
/// </summary>
public required string Password { get; set; }
/// <summary>
/// Gets or sets the temporary hashed password used in password recovery.
/// </summary>
public string? TempPassword { get; set; }
/// <summary>
/// Gets or sets the optional Time-based One-Time Password (TOTP) secret for two-factor authentication.
/// </summary>
public string? TotpSecret { get; set; }
/// <summary>
/// Gets or sets the optional token used for account verification or password reset.
/// </summary>
public string? VerificationToken { get; set; } // TODO: to be deleted, not used
/// <summary>
/// Gets or sets the optional date and time when the verification token was created.
/// </summary>
public DateTime? VerificationTokenCreated { get; set; } // TODO: to be deleted, not used
/// <summary>
/// Gets or sets the date and time when the temporary password used in password recovery was created.
/// </summary>
public DateTime? TempPasswordCreated { get; set; }
/// <summary>
/// Gets the collection of libraries owned by this user.
/// </summary>
public required ICollection<LibraryEntity> Libraries { get; init; } = [];
/// <summary>
/// Gets the time and date when the entity was added.
/// </summary>
public required DateTime Created { get; set; }
/// <summary>
/// Gets the optional time and date when the entity was updated.
/// </summary>
public DateTime? Updated { get; set; }
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
#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.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
@@ -9,8 +9,8 @@ namespace Lumina.Application.Common.DataAccess.Repositories.Books;
/// <summary>
/// Interface for the repository for books.
/// </summary>
public interface IBookRepository : IRepository<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.Application.Common.DataAccess.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.Application.Common.DataAccess.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.Application.Common.DataAccess.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.Application.Common.DataAccess.Entities.Common;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Models.Common;
using Lumina.Application.Common.DataAccess.Entities.Common;
#endregion
@@ -0,0 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
/// <summary>
/// Interface for the repository for media libraries.
/// </summary>
public interface ILibraryRepository : IRepository<LibraryEntity>,
IInsertRepositoryAction<LibraryEntity>
{
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.Common.DataAccess.Repositories.Users;
/// <summary>
/// Interface for the repository for users.
/// </summary>
public interface IUserRepository : IRepository<UserEntity>,
IGetAllRepositoryAction<UserEntity>,
IInsertRepositoryAction<UserEntity>,
IUpdateRepositoryAction<UserEntity>
{
/// <summary>
/// Gets a username identified by <paramref name="username"/> from the repository, if it exists.
/// </summary>
/// <param name="username">The username of the user to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="UserEntity"/> if found, or an error.</returns>
Task<ErrorOr<UserEntity?>> GetByUsernameAsync(string username, CancellationToken cancellationToken);
}
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using FluentValidation;
using Lumina.Application.Common.Behaviors;
using Mapster;
using MapsterMapper;
using Mediator;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.Common.DependencyInjection;
@@ -12,6 +11,7 @@ namespace Lumina.Application.Common.DependencyInjection;
/// <summary>
/// Contains all services of the Application layer.
/// </summary>
[ExcludeFromCodeCoverage]
public static class ApplicationLayerServices
{
/// <summary>
@@ -33,12 +33,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,33 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
#endregion
namespace Lumina.Application.Common.Errors;
/// <summary>
/// Application authentication related error types.
/// </summary>
public static partial class Errors
{
public static class Authentication
{
public static Error UsernameAlreadyExists => Error.Conflict(description: nameof(UsernameAlreadyExists));
public static Error UsernameDoesNotExist => Error.NotFound(description: nameof(UsernameDoesNotExist));
public static Error UsernameCannotBeEmpty => Error.Validation(description: nameof(UsernameCannotBeEmpty));
public static Error TotpCannotBeEmpty => Error.Validation(description: nameof(TotpCannotBeEmpty));
public static Error PasswordCannotBeEmpty => Error.Validation(description: nameof(PasswordCannotBeEmpty));
public static Error NewPasswordCannotBeEmpty => Error.Validation(description: nameof(NewPasswordCannotBeEmpty));
public static Error CurrentPasswordCannotBeEmpty => Error.Validation(description: nameof(CurrentPasswordCannotBeEmpty));
public static Error PasswordConfirmCannotBeEmpty => Error.Validation(description: nameof(PasswordConfirmCannotBeEmpty));
public static Error NewPasswordConfirmCannotBeEmpty => Error.Validation(description: nameof(NewPasswordConfirmCannotBeEmpty));
public static Error InvalidPassword => Error.Validation(description: nameof(InvalidPassword));
public static Error UsernameMustBeBetween3And255CharactersLong => Error.Validation(description: nameof(UsernameMustBeBetween3And255CharactersLong));
public static Error InvalidUsername => Error.Validation(description: nameof(InvalidUsername));
public static Error PasswordsNotMatch => Error.Validation(description: nameof(PasswordsNotMatch));
public static Error InvalidTotpCode => Error.Validation(description: nameof(InvalidTotpCode));
public static Error InvalidUsernameOrPassword => Error.Failure(description: nameof(InvalidUsernameOrPassword));
public static Error InvalidCurrentPassword => Error.Failure(description: nameof(InvalidCurrentPassword));
public static Error TempPasswordExpired => Error.Failure(description: nameof(TempPasswordExpired));
public static Error PasswordResetAlreadyRequested => Error.Failure(description: nameof(PasswordResetAlreadyRequested));
}
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
#endregion
namespace Lumina.Application.Common.Errors;
/// <summary>
/// Application authorization related error types.
/// </summary>
public static partial class Errors
{
public static class Authorization
{
public static Error AdminAccountAlreadyCreated => Error.Unauthorized(description: nameof(AdminAccountAlreadyCreated));
}
}
@@ -0,0 +1,15 @@
namespace Lumina.Application.Common.Infrastructure.Authentication;
/// <summary>
/// Interface for generating JWT tokens.
/// </summary>
public interface IJwtTokenGenerator
{
/// <summary>
/// Generates a new JWT token.
/// </summary>
/// <param name="id">The id of the user for which to generate the token.</param>
/// <param name="username">The username for which to generate the token.</param>
/// <returns>The generated JWT token.</returns>
string GenerateToken(string id, string username);
}
@@ -0,0 +1,15 @@
namespace Lumina.Application.Common.Infrastructure.Authentication;
/// <summary>
/// Interface for the service for generating QR codes for TOTP.
/// </summary>
public interface IQRCodeGenerator
{
/// <summary>
/// Generates a QR code Data URI for the specified TOTP secret.
/// </summary>
/// <param name="username">User's username or unique identifier.</param>
/// <param name="secret">The TOTP secret for which the QR code should be generated.</param>
/// <returns>Data URI for the QR code.</returns>
string GenerateQrCodeDataUri(string username, byte[] secret);
}
@@ -0,0 +1,13 @@
namespace Lumina.Application.Common.Infrastructure.Authentication;
/// <summary>
/// Interface for the service for generating secure tokens for accounts confirmation or recovery.
/// </summary>
public interface ITokenGenerator
{
/// <summary>
/// Generates a secure token.
/// </summary>
/// <returns>A secure token.</returns>
string GenerateToken();
}
@@ -0,0 +1,21 @@
namespace Lumina.Application.Common.Infrastructure.Authentication;
/// <summary>
/// Interface for the service for generating and validating TOTP tokens.
/// </summary>
public interface ITotpTokenGenerator
{
/// <summary>
/// Generates a new TOTP secret for a user.
/// </summary>
/// <returns>The generated TOTP secret.</returns>
byte[] GenerateSecret();
/// <summary>
/// Validates a TOTP token against the stored secret.
/// </summary>
/// <param name="secret">The user's TOTP secret.</param>
/// <param name="token">The token to validate.</param>
/// <returns><see langword="true"/> if valid, <see langword="false"/> otherwise.</returns>
bool ValidateToken(byte[] secret, string token);
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Application.Common.Infrastructure.Security;
/// <summary>
/// Interface for the service for cryptographic concerns.
/// </summary>
public interface ICryptographyService
{
/// <summary>
/// Encrypts a plaintext string using AES encryption with a randomly generated initialization vector (IV).
/// </summary>
/// <param name="plaintext">The plaintext string to encrypt.</param>
/// <returns>A Base64-encoded string of the combined IV and encrypted ciphertext.</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="plaintext"/> is <see langword="null"/> or empty.</exception>
string Encrypt(string plaintext);
/// <summary>
/// Decrypts a Base64-encoded string that contains both the IV and ciphertext.
/// </summary>
/// <param name="ciphertext">The Base64-encoded string containing both IV and ciphertext.</param>
/// <returns>The decrypted plaintext string.</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="ciphertext"/> is <see langword="null"/>, empty, or invalid.</exception>
string Decrypt(string ciphertext);
}
@@ -0,0 +1,22 @@
namespace Lumina.Application.Common.Infrastructure.Security;
/// <summary>
/// Interface for the service for hashing passwords.
/// </summary>
public interface IHashService
{
/// <summary>
/// Creates a hash from a string.
/// </summary>
/// <param name="password">The string to be hashed.</param>
/// <returns>The hashed string.</returns>
string HashString(string password);
/// <summary>
/// Verifies a password against a hash.
/// </summary>
/// <param name="password">The string to be checked.</param>
/// <param name="hashedPassword">The hashed representation of the string to be checked.</param>
/// <returns><see langword="true"/> if <paramref name="password"/> and the de-hashed versions of <paramref name="hashedPassword"/> are equal, <see langword="false"/> otherwise.</returns>
bool CheckStringAgainstHash(string password, string hashedPassword);
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System;
#endregion
namespace Lumina.Application.Common.Infrastructure.Time;
/// <summary>
/// Interface for time related concerns.
/// </summary>
public interface IDateTimeProvider
{
/// <summary>
/// The current UTC time.
/// </summary>
DateTime UtcNow { get; }
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Contracts.Requests.Authentication;
#endregion
namespace Lumina.Application.Common.Mapping.Authentication;
/// <summary>
/// Extension methods for converting <see cref="ChangePasswordRequest"/>.
/// </summary>
public static class ChangePasswordRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="ChangePasswordCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static ChangePasswordCommand ToCommand(this ChangePasswordRequest request)
{
return new ChangePasswordCommand(
request.Username,
request.CurrentPassword,
request.NewPassword,
request.NewPasswordConfirm
);
}
}
@@ -0,0 +1,26 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Contracts.Requests.Authentication;
#endregion
namespace Lumina.Application.Common.Mapping.Authentication;
/// <summary>
/// Extension methods for converting <see cref="LoginRequest"/>.
/// </summary>
public static class LoginRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="LoginUserQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static LoginUserQuery ToQuery(this LoginRequest request)
{
return new LoginUserQuery(
request.Username,
request.Password,
request.TotpCode
);
}
}
@@ -0,0 +1,25 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Contracts.Requests.Authentication;
#endregion
namespace Lumina.Application.Common.Mapping.Authentication;
/// <summary>
/// Extension methods for converting <see cref="RecoverPasswordRequest"/>.
/// </summary>
public static class RecoverPasswordRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="RecoverPasswordCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static RecoverPasswordCommand ToCommand(this RecoverPasswordRequest request)
{
return new RecoverPasswordCommand(
request.Username,
request.TotpCode
);
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
using Lumina.Contracts.Requests.Authentication;
#endregion
namespace Lumina.Application.Common.Mapping.Authentication;
/// <summary>
/// Extension methods for converting <see cref="RegistrationRequest"/>.
/// </summary>
public static class RegistrationRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="SetupApplicationCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static SetupApplicationCommand ToSetupCommand(this RegistrationRequest request)
{
return new SetupApplicationCommand(
request.Username,
request.Password,
request.PasswordConfirm,
request.Use2fa
);
}
/// <summary>
/// Converts <paramref name="request"/> to <see cref="RegisterUserCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static RegisterUserCommand ToCommand(this RegistrationRequest request)
{
return new RegisterUserCommand(
request.Username,
request.Password,
request.PasswordConfirm,
request.Use2fa
);
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.DTO.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="GenreDto"/>.
/// </summary>
public static class GenreDtoMapping
{
/// <summary>
/// Converts <paramref name="dto"/> to <see cref="GenreDto"/>.
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<Genre> ToDomainEntity(this GenreDto dto)
{
return Genre.Create(
dto.Name
);
}
/// <summary>
/// Converts <paramref name="dtos"/> to a collection of <see cref="Genre"/>.
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<Genre>> ToDomainEntities(this IEnumerable<GenreDto> dtos)
{
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
}
}
@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Contracts.DTO.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 GenreEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="GenreDto"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted DTO.</returns>
public static GenreDto ToResponse(this GenreEntity repositoryEntity)
{
return new GenreDto(
repositoryEntity.Name ?? default
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="GenreDto"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted DTOs.</returns>
public static IEnumerable<GenreDto> ToResponses(this IEnumerable<GenreEntity> repositoryEntities)
{
return repositoryEntities.Select(responseEntity => responseEntity.ToResponse());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Genre"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
{
return Genre.Create(
repositoryEntity.Name ?? default
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Genre"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<Genre>> ToDomainEntities(this IEnumerable<GenreEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.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="domainEntity"/> to <see cref="GenreEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static GenreEntity ToRepositoryEntity(this Genre domainEntity)
{
return new GenreEntity(
domainEntity.Name
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="GenreEntity"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<GenreEntity> ToRepositoryEntities(this IEnumerable<Genre> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity());
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.DTO.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="TagDto"/>.
/// </summary>
public static class TagDtoMapping
{
/// <summary>
/// Converts <paramref name="dto"/> to <see cref="Tag"/>.
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<Tag> ToDomainEntity(this TagDto dto)
{
return Tag.Create(
dto.Name
);
}
/// <summary>
/// Converts <paramref name="dtos"/> to a collection of <see cref="Tag"/>.
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<Tag>> ToDomainEntities(this IEnumerable<TagDto> dtos)
{
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Contracts.DTO.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 TagEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="TagDto"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted DTO.</returns>
public static TagDto ToResponse(this TagEntity repositoryEntity)
{
return new TagDto(
repositoryEntity.Name ?? default
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="TagDto"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted DTOs.</returns>
public static IEnumerable<TagDto> ToResponses(this IEnumerable<TagEntity> repositoryEntities)
{
return repositoryEntities.Select(responseEntity => responseEntity.ToResponse());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Tag"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<Tag> ToDomainEntity(this TagEntity repositoryEntity)
{
return Tag.Create(
repositoryEntity.Name ?? default
);
}
/// <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 entities.</returns>
public static IEnumerable<ErrorOr<Tag>> ToDomainEntities(this IEnumerable<TagEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.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="domainEntity"/> to <see cref="TagEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static TagEntity ToRepositoryEntity(this Tag domainEntity)
{
return new TagEntity(
domainEntity.Name
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="TagEntity"/>.
/// </summary>
/// <param name="domainEntities">The domain entity to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<TagEntity> ToRepositoryEntities(this IEnumerable<Tag> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity());
}
}
@@ -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.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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 entity.</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 entity.</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.BoundedContexts.FileSystemManagementBoundedContext.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="domainEntity"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToFileSystemTreeNodeResponse(this Directory domainEntity)
{
return new FileSystemTreeNodeResponse()
{
Name = domainEntity.Name,
Path = domainEntity.Id.Path,
ItemType = domainEntity.Type,
IsExpanded = false,
ChildrenLoaded = false,
Children = domainEntity.Items.Select(item => item.ToTreeNodeResponse())
.ToList()
};
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<FileSystemTreeNodeResponse> ToFileSystemTreeNodeResponses(this IEnumerable<Directory> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToTreeNodeResponse());
}
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static DirectoryResponse ToResponse(this Directory domainEntity)
{
return new DirectoryResponse(
domainEntity.Id.Path,
domainEntity.Name,
domainEntity.DateCreated.Value,
domainEntity.DateModified.Value,
domainEntity.Items.Select(fileSystemItem => fileSystemItem.ToFileSystemItemDto())
.ToList()
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<DirectoryResponse> ToResponses(this IEnumerable<Directory> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.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.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using Lumina.Contracts.DTO.FileSystemManagement;
#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="domainEntity"/> to <see cref="FileSystemItemDto"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted Dto.</returns>
public static FileSystemItemDto ToFileSystemItemDto(this FileSystemItem domainEntity)
{
return new FileSystemItemDto(
domainEntity.Id.Path,
domainEntity.Name,
DateTime.Now,
DateTime.Now
);
}
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted entity.</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 domainEntity)
{
if (domainEntity is Directory directory)
return directory.ToFileSystemTreeNodeResponse();
else if (domainEntity is File file)
return file.ToFileSystemTreeNodeResponse();
else if (domainEntity is WindowsRootItem windowsRootItem)
return windowsRootItem.ToTreeNodeResponse();
else if (domainEntity is UnixRootItem unixRootItem)
return unixRootItem.ToTreeNodeResponse();
else
throw new ArgumentException("Invalid FileSystemItem");
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to <see cref="IEnumerable<FileSystemTreeNodeResponse>"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted entities.</returns>
public static IEnumerable<FileSystemTreeNodeResponse> ToTreeNodeResponses(this IEnumerable<FileSystemItem> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToTreeNodeResponse());
}
}
@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.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="domainEntity"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToTreeNodeResponse(this UnixRootItem domainEntity)
{
return new FileSystemTreeNodeResponse()
{
Path = domainEntity.Id.Path,
Name = domainEntity.Name,
ItemType = FileSystemItemType.Root,
IsExpanded = false,
ChildrenLoaded = false,
Children = domainEntity.Items.Select(item => item.ToTreeNodeResponse())
.ToList()
};
}
}
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
#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="domainEntity"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToTreeNodeResponse(this WindowsRootItem domainEntity)
{
return new FileSystemTreeNodeResponse()
{
Path = domainEntity.Id.Path,
Name = domainEntity.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.BoundedContexts.FileSystemManagementBoundedContext.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="domainEntity"/> to <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static FileSystemTreeNodeResponse ToFileSystemTreeNodeResponse(this File domainEntity)
{
return new FileSystemTreeNodeResponse()
{
Name = domainEntity.Name,
Path = domainEntity.Id.Path,
ItemType = domainEntity.Type,
IsExpanded = false,
ChildrenLoaded = false
};
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="FileSystemTreeNodeResponse"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<FileSystemTreeNodeResponse> ToFileSystemTreeNodeResponses(this IEnumerable<File> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToFileSystemTreeNodeResponse());
}
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="FileResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static FileResponse ToResponse(this File domainEntity)
{
return new FileResponse(
domainEntity.Id.Path,
domainEntity.Name,
domainEntity.DateCreated.HasValue ? domainEntity.DateCreated.Value : default,
domainEntity.DateModified.HasValue ? domainEntity.DateModified.Value : default,
domainEntity.Size
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="FileResponse"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<FileResponse> ToResponses(this IEnumerable<File> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.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 CheckPathExistsRequestMapping
{
/// <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.BoundedContexts.FileSystemManagementBoundedContext.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="domainEntity"/> to <see cref="PathSegmentResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static PathSegmentResponse ToResponse(this PathSegment domainEntity)
{
return new PathSegmentResponse(
domainEntity.Name
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="PathSegmentResponse"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted responses.</returns>
public static IEnumerable<PathSegmentResponse> ToResponses(this IEnumerable<PathSegment> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.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.BoundedContexts.FileSystemManagementBoundedContext.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="domainEntity"/> to <see cref="ThumbnailResponse"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted response.</returns>
public static ThumbnailResponse ToResponse(this Thumbnail domainEntity)
{
return new ThumbnailResponse(
domainEntity.Type,
domainEntity.Bytes
);
}
}
@@ -0,0 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Contracts.Requests.MediaLibrary.Management;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Extension methods for converting <see cref="AddLibraryRequest"/>.
/// </summary>
public static class AddMediaLibraryRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="AddLibraryCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static AddLibraryCommand ToCommand(this AddLibraryRequest request)
{
return new AddLibraryCommand(
request.UserId,
request.Title,
request.LibraryType,
request.ContentLocations
);
}
}
@@ -0,0 +1,31 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Extension methods for converting <see cref="LibraryEntity"/>.
/// </summary>
public static class LibraryEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="LibraryResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted response entity.</returns>
public static LibraryResponse ToResponse(this LibraryEntity repositoryEntity)
{
return new LibraryResponse(
repositoryEntity.Id,
repositoryEntity.UserId,
repositoryEntity.Title,
repositoryEntity.LibraryType,
repositoryEntity.ContentLocations.Select(location => location.Path).ToList(),
repositoryEntity.Created,
repositoryEntity.Updated
);
}
}
@@ -0,0 +1,32 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Extension methods for converting <see cref="Library"/>.
/// </summary>
public static class LibraryMapping
{
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="LibraryEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static LibraryEntity ToRepositoryEntity(this Library domainEntity)
{
return new LibraryEntity
{
Id = domainEntity.Id.Value,
Title = domainEntity.Title,
LibraryType = domainEntity.LibraryType,
UserId = domainEntity.UserId.Value,
ContentLocations = domainEntity.ContentLocations.Select(path => new LibraryContentLocationEntity() { Path = path.Path }).ToList(),
Created = domainEntity.Created,
Updated = domainEntity.Updated.HasValue ? domainEntity.Updated : null
};
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.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,224 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Extension methods for converting <see cref="BookEntity"/>.
/// </summary>
public static class BookEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Book"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity 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> ToDomainEntity(this BookEntity repositoryEntity)
{
IEnumerable<ErrorOr<Tag>> tagsResult = repositoryEntity.Tags.ToDomainEntities();
foreach (ErrorOr<Tag> tagResult in tagsResult)
if (tagResult.IsError)
return tagResult.Errors;
IEnumerable<ErrorOr<Genre>> genresResult = repositoryEntity.Genres.ToDomainEntities();
foreach (ErrorOr<Genre> genreResult in genresResult)
if (genreResult.IsError)
return genreResult.Errors;
IEnumerable<ErrorOr<Isbn>> isbnsResult = repositoryEntity.ISBNs.ToDomainEntities();
foreach (ErrorOr<Isbn> isbnResult in isbnsResult)
if (isbnResult.IsError)
return isbnResult.Errors;
IEnumerable<ErrorOr<BookRating>> bookRatingsResult = repositoryEntity.Ratings.ToDomainEntities();
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(repositoryEntity.Format);
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 entities to be converted.</param>
/// <returns>The converted domain entities.</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>> ToDomainEntities(this IEnumerable<BookEntity> repositoryEntities)
{
return repositoryEntities.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted response entity.</returns>
public static BookResponse ToResponse(this BookEntity repositoryEntity)
{
ReleaseInfoDto releaseInfoEntity = 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
LanguageInfoDto? languageInfoEntity = !string.IsNullOrWhiteSpace(repositoryEntity.LanguageCode) ||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageName) ||
!string.IsNullOrWhiteSpace(repositoryEntity.LanguageNativeName)
? new LanguageInfoDto(
repositoryEntity.LanguageCode,
repositoryEntity.LanguageName,
repositoryEntity.LanguageNativeName
) : null;
LanguageInfoDto? originalLanguageInfoEntity = !string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageCode) ||
!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageName) ||
!string.IsNullOrWhiteSpace(repositoryEntity.OriginalLanguageNativeName)
? new LanguageInfoDto(
repositoryEntity.OriginalLanguageCode,
repositoryEntity.OriginalLanguageName,
repositoryEntity.OriginalLanguageNativeName
) : null;
WrittenContentMetadataDto metadata = new(
repositoryEntity.Title,
repositoryEntity.OriginalTitle,
repositoryEntity.Description,
releaseInfoEntity,
[.. repositoryEntity.Genres.ToResponses()],
[.. repositoryEntity.Tags.ToResponses()],
languageInfoEntity,
originalLanguageInfoEntity,
repositoryEntity.Publisher,
repositoryEntity.PageCount
);
return new BookResponse(
repositoryEntity.Id,
metadata,
repositoryEntity.Format,
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.ToResponses()],
null,
[.. repositoryEntity.Ratings.ToResponses()],
repositoryEntity.Created,
repositoryEntity.Updated
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Book"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities 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,63 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Extension methods for converting <see cref="Book"/>.
/// </summary>
public static class BookMapping
{
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="BookEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static BookEntity ToRepositoryEntity(this Book domainEntity)
{
return new BookEntity
{
Id = domainEntity.Id.Value,
Title = domainEntity.Metadata.Title,
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
OriginalReleaseDate = domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null,
OriginalReleaseYear = domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null,
ReReleaseDate = domainEntity.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseDate.Value : null,
ReReleaseYear = domainEntity.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? domainEntity.Metadata.ReleaseInfo.ReReleaseYear.Value : null,
ReleaseCountry = domainEntity.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? domainEntity.Metadata.ReleaseInfo.ReleaseCountry.Value : null,
ReleaseVersion = domainEntity.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? domainEntity.Metadata.ReleaseInfo.ReleaseVersion.Value : null,
LanguageCode = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.LanguageCode : null,
LanguageName = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.LanguageName : null,
LanguageNativeName = domainEntity.Metadata.Language.HasValue ? domainEntity.Metadata.Language.Value.NativeName.Value : null,
OriginalLanguageCode = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageCode : null,
OriginalLanguageName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.LanguageName : null,
OriginalLanguageNativeName = domainEntity.Metadata.OriginalLanguage.HasValue ? domainEntity.Metadata.OriginalLanguage.Value.NativeName.Value : null,
Tags = domainEntity.Metadata.Tags.ToRepositoryEntities().ToHashSet(),
Genres = domainEntity.Metadata.Genres.ToRepositoryEntities().ToHashSet(),
Publisher = domainEntity.Metadata.Publisher.HasValue ? domainEntity.Metadata.Publisher.Value : null,
PageCount = domainEntity.Metadata.PageCount.HasValue ? domainEntity.Metadata.PageCount.Value : null,
Format = domainEntity.Format.HasValue ? domainEntity.Format.Value : null,
Edition = domainEntity.Edition.HasValue ? domainEntity.Edition.Value : null,
VolumeNumber = domainEntity.VolumeNumber.HasValue ? domainEntity.VolumeNumber.Value : null,
ASIN = domainEntity.ASIN.HasValue ? domainEntity.ASIN.Value : null,
GoodreadsId = domainEntity.GoodreadsId.HasValue ? domainEntity.GoodreadsId.Value : null,
LCCN = domainEntity.LCCN.HasValue ? domainEntity.LCCN.Value : null,
OCLCNumber = domainEntity.OCLCNumber.HasValue ? domainEntity.OCLCNumber.Value : null,
OpenLibraryId = domainEntity.OpenLibraryId.HasValue ? domainEntity.OpenLibraryId.Value : null,
LibraryThingId = domainEntity.LibraryThingId.HasValue ? domainEntity.LibraryThingId.Value : null,
GoogleBooksId = domainEntity.GoogleBooksId.HasValue ? domainEntity.GoogleBooksId.Value : null,
BarnesAndNobleId = domainEntity.BarnesAndNobleId.HasValue ? domainEntity.BarnesAndNobleId.Value : null,
AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null,
ISBNs = domainEntity.ISBNs.ToRepositoryEntities().ToList(),
Ratings = domainEntity.Ratings.ToRepositoryEntities().ToList(),
Created = domainEntity.Created,
Updated = domainEntity.Updated.HasValue ? domainEntity.Updated : null
};
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="BookRatingDto"/>.
/// </summary>
public static class BookRatingDtoMapping
{
/// <summary>
/// Converts <paramref name="dto"/> to <see cref="BookRating"/>.
/// </summary>
/// <param name="dto">The DTO to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<BookRating> ToDomainEntity(this BookRatingDto dto)
{
return BookRating.Create(
dto.Value ?? default,
dto.MaxValue ?? default,
Optional<BookRatingSource>.FromNullable(dto.Source),
Optional<int>.FromNullable(dto.VoteCount)
);
}
/// <summary>
/// Converts <paramref name="dtos"/> to a collection of <see cref="BookRating"/>.
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingDto> dtos)
{
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="BookRatingEntity"/>.
/// </summary>
public static class BookRatingEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookRatingDto"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted DTO.</returns>
public static BookRatingDto ToResponse(this BookRatingEntity repositoryEntity)
{
return new BookRatingDto(
repositoryEntity.Value ?? default,
repositoryEntity.MaxValue ?? default,
repositoryEntity.Source,
repositoryEntity.VoteCount
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="BookRatingDto"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted DTOs.</returns>
public static IEnumerable<BookRatingDto> ToResponses(this IEnumerable<BookRatingEntity> repositoryEntities)
{
return repositoryEntities.Select(responseEntity => responseEntity.ToResponse());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="BookRating"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<BookRating> ToDomainEntity(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 entities to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="BookRating"/>.
/// </summary>
public static class BookRatingMapping
{
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="BookRatingEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static BookRatingEntity ToRepositoryEntity(this BookRating domainEntity)
{
return new BookRatingEntity(
domainEntity.Value,
domainEntity.MaxValue,
domainEntity.Source.HasValue ? domainEntity.Source.Value : null,
domainEntity.VoteCount.HasValue ? domainEntity.VoteCount.Value : null
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="BookRatingEntity"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<BookRatingEntity> ToRepositoryEntities(this IEnumerable<BookRating> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity());
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="IsbnDto"/>.
/// </summary>
public static class IsbnDtoMapping
{
/// <summary>
/// Converts <paramref name="dto"/> to <see cref="Isbn"/>.
/// </summary>
/// <param name="dto">The DTO 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> ToDomainEntity(this IsbnDto dto)
{
return Isbn.Create(
dto.Value,
dto.Format ?? IsbnFormat.Isbn13
);
}
/// <summary>
/// Converts <paramref name="dtos"/> to a collection of <see cref="Isbn"/>.
/// </summary>
/// <param name="dtos">The DTOs to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnDto> dtos)
{
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,62 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="IsbnEntity"/>.
/// </summary>
public static class IsbnEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="IsbnDto"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted DTO.</returns>
public static IsbnDto ToResponse(this IsbnEntity repositoryEntity)
{
return new IsbnDto(
repositoryEntity.Value ?? default,
repositoryEntity.Format ?? null
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="IsbnDto"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted DTOs.</returns>
public static IEnumerable<IsbnDto> ToResponses(this IEnumerable<IsbnEntity> repositoryEntities)
{
return repositoryEntities.Select(responseEntity => responseEntity.ToResponse());
}
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="Isbn"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted domain entity.</returns>
public static ErrorOr<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
{
return Isbn.Create(
repositoryEntity.Value ?? default,
repositoryEntity.Format ?? default
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Isbn"/>.
/// </summary>
/// <param name="repositoryEntities">The repository entities to be converted.</param>
/// <returns>The converted domain entities.</returns>
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
{
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Linq;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Extension methods for converting <see cref="Isbn"/>.
/// </summary>
public static class IsbnMapping
{
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="IsbnEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <returns>The converted repository entity.</returns>
public static IsbnEntity ToRepositoryEntity(this Isbn domainEntity)
{
return new IsbnEntity(
domainEntity.Value,
domainEntity.Format
);
}
/// <summary>
/// Converts <paramref name="domainEntities"/> to a collection of <see cref="IsbnEntity"/>.
/// </summary>
/// <param name="domainEntities">The domain entities to be converted.</param>
/// <returns>The converted repository entities.</returns>
public static IEnumerable<IsbnEntity> ToRepositoryEntities(this IEnumerable<Isbn> domainEntities)
{
return domainEntities.Select(domainEntity => domainEntity.ToRepositoryEntity());
}
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Contracts.Responses.UsersManagement.Users;
#endregion
namespace Lumina.Application.Common.Mapping.UsersManagement.Users;
/// <summary>
/// Extension methods for converting <see cref="UserEntity"/>.
/// </summary>
public static class UserEntityMapping
{
/// <summary>
/// Converts <paramref name="repositoryEntity"/> to <see cref="UserResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity to be converted.</param>
/// <returns>The converted response entity.</returns>
public static UserResponse ToResponse(this UserEntity repositoryEntity)
{
return new UserResponse(
repositoryEntity.Id,
repositoryEntity.Username,
repositoryEntity.Created,
repositoryEntity.Updated
);
}
}
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
#endregion
namespace Lumina.Application.Common.Mapping.UsersManagement.Users;
/// <summary>
/// Extension methods for converting <see cref="User"/>.
/// </summary>
public static class UserMapping
{
/// <summary>
/// Converts <paramref name="domainEntity"/> to <see cref="UserEntity"/>.
/// </summary>
/// <param name="domainEntity">The domain entity to be converted.</param>
/// <param name="repositoryEntity">The repository entity containing sensitive information not mapped to the Domain entity.</param>
/// <remarks>
/// Because Authentication and Authorization are Application Layer concerns, the members involved in those concerns are not mirrored in the Domain entity.
/// However, since Entity Framework updates an entire entity, when mapping from the Domain entity to the DAL entity, one still needs to provide the
/// values of the non-included members, such that they are not overriden with <see langword="null"/>. Those values should come in the requested <paramref name="repositoryEntity"/>.
/// </remarks>
/// <returns>The converted repository entity.</returns>
public static UserEntity ToRepositoryEntity(this User domainEntity, UserEntity repositoryEntity)
{
repositoryEntity.Username = domainEntity.Username;
return repositoryEntity;
}
}
@@ -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);
}
}
@@ -1,15 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetDirectories;
/// <summary>
/// Query for retrieving the list of directories at a path.
/// </summary>
/// <param name="Path">The path for which to retrieve the list of directories.</param>
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
public record GetDirectoriesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<DirectoryResponse>>>;
@@ -1,15 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Directories.Queries.GetTreeDirectories;
/// <summary>
/// Query for retrieving the list of directories at a path.
/// </summary>
/// <param name="Path">The path for which to retrieve the list of directories.</param>
/// <param name="IncludeHiddenElements">Whether to include hidden directories or not.</param>
public record GetTreeDirectoriesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
@@ -1,15 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetFiles;
/// <summary>
/// Query for retrieving the list of files at a path.
/// </summary>
/// <param name="Path">The path for which to retrieve the list of files.</param>
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
public record GetFilesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileResponse>>>;
@@ -1,15 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
using System.Collections.Generic;
#endregion
namespace Lumina.Application.Core.FileManagement.Files.Queries.GetTreeFiles;
/// <summary>
/// Query for retrieving the list of files at a path.
/// </summary>
/// <param name="Path">The path for which to retrieve the list of files.</param>
/// <param name="IncludeHiddenElements">Whether to include hidden files and directories or not.</param>
public record GetTreeFilesQuery(string Path, bool IncludeHiddenElements) : IRequest<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>;
@@ -1,16 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Contracts.Responses.FileManagement;
using Mediator;
#endregion
namespace Lumina.Application.Core.FileManagement.Paths.Commands.CombinePath;
/// <summary>
/// Command for combining two file system path.
/// </summary>
/// <param name="OriginalPath">The path to combine to.</param>
/// <param name="NewPath">The path to combine with.</param>
public record CombinePathCommand(
string OriginalPath, string NewPath
) : IRequest<ErrorOr<PathSegmentResponse>>;
Loaded 100 of 853 files, more files were not shown because too many files have changed in this diff. Show more