mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Moves media library scanning to domain layer
This commit is contained in:
1 parent
8b51abe0b2
commit
c4246d2e69
209 files changed
+3793
-641
No files matched your search
+6
-1
@@ -41,10 +41,15 @@ public class LibraryEntity : IStorageEntity, IAuditableEntity
|
||||
public required LibraryType LibraryType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of file system paths that make up the media library.
|
||||
/// Gets the list of file system paths that make up the media library.
|
||||
/// </summary>
|
||||
public required ICollection<LibraryContentLocationEntity> ContentLocations { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of scans of the media library.
|
||||
/// </summary>
|
||||
public ICollection<LibraryScanEntity> LibraryScans { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether this media library is enabled or not. A disabled media library is never shown or changed.
|
||||
/// </summary>
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#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.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id}; Status: {Status}")]
|
||||
public class LibraryScanEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library that is scanned.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the user that initiated the media library scan.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of the media library scan.
|
||||
/// </summary>
|
||||
public required LibraryScanJobStatus Status { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media library that is scanned.
|
||||
/// </summary>
|
||||
public required LibraryEntity Library { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user that initiated the media library scan.
|
||||
/// </summary>
|
||||
public required UserEntity User { get; init; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -48,7 +48,12 @@ public class UserEntity : IStorageEntity, IAuditableEntity
|
||||
/// <summary>
|
||||
/// Gets the collection of libraries owned by this user.
|
||||
/// </summary>
|
||||
public required ICollection<LibraryEntity> Libraries { get; init; } = [];
|
||||
public ICollection<LibraryEntity> Libraries { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of library scans initiated by this user.
|
||||
/// </summary>
|
||||
public ICollection<LibraryScanEntity> LibraryScans { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user roles association that includes this user.
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for media library scans.
|
||||
/// </summary>
|
||||
public interface ILibraryScanRepository : IRepository<LibraryScanEntity>,
|
||||
IGetByIdRepositoryAction<LibraryScanEntity, Guid>,
|
||||
IInsertRepositoryAction<LibraryScanEntity>,
|
||||
IUpdateRepositoryAction<LibraryScanEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the media library scans that belong to a media library identified by <paramref name="libraryId"/>, for the previous month, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryScanEntity"/>, or an error.</returns>
|
||||
Task<ErrorOr<IEnumerable<LibraryScanEntity>>> GetPastMonthScansByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media library scans have a <see cref="LibraryScanJobStatus.Running"/> status, from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="LibraryScanEntity"/>, or an error.</returns>
|
||||
Task<ErrorOr<IEnumerable<LibraryScanEntity>>> GetRunningScansAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public interface IDataSeedService
|
||||
/// <summary>
|
||||
/// Sets up default authorization permissions in the system.
|
||||
/// </summary>
|
||||
/// <param name="adminId">The Id of the admin admin user who will own these permissions.</param>
|
||||
/// <param name="adminId">The unique identifier of the admin admin user who will own these permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<ErrorOr<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken);
|
||||
@@ -23,7 +23,7 @@ public interface IDataSeedService
|
||||
/// <summary>
|
||||
/// Sets up default authorization roles in the system.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the admin user for whom roles will be set.</param>
|
||||
/// <param name="userId">The unique identifier of the admin user for whom roles will be set.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<ErrorOr<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken);
|
||||
@@ -31,7 +31,7 @@ public interface IDataSeedService
|
||||
/// <summary>
|
||||
/// Assigns admin role permissions to the admin user.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the admin user to receive admin role permissions.</param>
|
||||
/// <param name="userId">The unique identifier of the admin user to receive admin role permissions.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<ErrorOr<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken);
|
||||
@@ -39,7 +39,7 @@ public interface IDataSeedService
|
||||
/// <summary>
|
||||
/// Assigns admin role to the admin user.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the admin user to receive the admin role.</param>
|
||||
/// <param name="userId">The unique identifier of the admin user to receive the admin role.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<ErrorOr<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
using FluentValidation;
|
||||
using Lumina.Application.Common.Behaviors;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Cancellation;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.WrittenContent.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queue;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Scanners.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Scanners.WrittenContent;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Tracking;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using Mediator;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -44,17 +45,13 @@ public static class ApplicationLayerServices
|
||||
services.AddScoped<IDomainEventsQueue, DomainEventsQueue>();
|
||||
|
||||
services.AddSingleton<IMediaLibrariesScanQueue, MediaLibrariesScanQueue>();
|
||||
services.AddSingleton<IMediaLibrariesScanTracker, MediaLibrariesScanTracker>();
|
||||
services.AddScoped<IBookLibraryTypeScanner, BookLibraryTypeScanner>();
|
||||
services.AddScoped<IMediaLibraryScanningService, MediaLibraryScanningService>();
|
||||
services.AddScoped<IMediaLibraryScannerFactory, MediaLibraryScannerFactory>();
|
||||
services.AddScoped<IMediaLibraryScanJobFactory, MediaLibraryScanJobFactory>();
|
||||
services.AddSingleton<IMediaLibrariesScanCancellationTracker, MediaLibrariesScanCancellationTracker>();
|
||||
services.AddHostedService<MediaLibraryScanJobProcessorJob>();
|
||||
|
||||
services.AddTransient<FileSystemDiscoveryJob>();
|
||||
services.AddTransient<RepositoryMetadataDiscoveryJob>();
|
||||
services.AddTransient<HashComparerJob>();
|
||||
services.AddTransient<GoodReadsMetadataScrapJob>();
|
||||
services.AddTransient<IFileSystemDiscoveryJob, FileSystemDiscoveryJob>();
|
||||
services.AddTransient<IRepositoryMetadataDiscoveryJob, RepositoryMetadataDiscoveryJob>();
|
||||
services.AddTransient<IHashComparerJob, HashComparerJob>();
|
||||
services.AddTransient<IGoodReadsMetadataScrapJob, GoodReadsMetadataScrapJob>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface IAuthorizationService
|
||||
/// <summary>
|
||||
/// Determines whether the specified user has a specific permission.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user for whom to check the permission.</param>
|
||||
/// <param name="userId">The unique identifier of the user for whom to check the permission.</param>
|
||||
/// <param name="permission">The permission to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the user has the specified permission, <see langword="false"/> otherwise.</returns>
|
||||
@@ -27,7 +27,7 @@ public interface IAuthorizationService
|
||||
/// <summary>
|
||||
/// Determines whether the specified user belongs to a specific role.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user for whom to check the role.</param>
|
||||
/// <param name="userId">The unique identifier of the user for whom to check the role.</param>
|
||||
/// <param name="role">The role to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the user is in the specified role, <see langword="false"/> otherwise.</returns>
|
||||
@@ -37,7 +37,7 @@ public interface IAuthorizationService
|
||||
/// Evaluates whether the specified user meets the conditions defined in the specified authorization policy.
|
||||
/// </summary>
|
||||
/// <typeparam name="TAuthorizationPolicy">The type of authorization policy to evaluate.</typeparam>
|
||||
/// <param name="userId">The Id of the user for whom to evaluate the policy.</param>
|
||||
/// <param name="userId">The unique identifier of the user for whom to evaluate the policy.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the user satisfies the policy, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> EvaluatePolicyAsync<TAuthorizationPolicy>(Guid userId, CancellationToken cancellationToken) where TAuthorizationPolicy : IAuthorizationPolicy;
|
||||
@@ -45,7 +45,7 @@ public interface IAuthorizationService
|
||||
/// <summary>
|
||||
/// Retrieves all authorization roles and permissions of a user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The id of the user for whom to retrieve the authorization roles and permissions.</param>
|
||||
/// <param name="userId">The unique identifier of the user for whom to retrieve the authorization roles and permissions.</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="UserAuthorizationEntity"/>, or an error.</returns>
|
||||
Task<ErrorOr<UserAuthorizationEntity>> GetUserAuthorizationAsync(Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ public interface IAuthorizationPolicy
|
||||
/// <summary>
|
||||
/// Evaluates a policy for a user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user for which to evaluate the policy.</param>
|
||||
/// <param name="userId">The unique identifier of the user for which to evaluate the policy.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns><see langword="true"/> if the policy evaluation succeeds, <see langword="false"/> otherwise.</returns>
|
||||
Task<bool> EvaluateAsync(Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
+2
-2
@@ -7,6 +7,6 @@ namespace Lumina.Application.Common.Infrastructure.Models.Scanning;
|
||||
/// <summary>
|
||||
/// Model for tracking media library scans.
|
||||
/// </summary>
|
||||
/// <param name="ScanId">The Id of the media library scan to be tracked.</param>
|
||||
/// <param name="UserId">The Id of the username who initiated the media library scan.</param>
|
||||
/// <param name="ScanId">The unique identifier of the media library scan to be tracked.</param>
|
||||
/// <param name="UserId">The unique identifier of the username who initiated the media library scan.</param>
|
||||
public record MediaScanTrackerModel(Guid ScanId, Guid UserId);
|
||||
@@ -17,7 +17,9 @@ public static class GenreDtoMapping
|
||||
/// Converts <paramref name="dto"/> to <see cref="GenreDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The DTO to be converted.</param>
|
||||
/// <returns>The converted domain entity.</returns>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Genre> ToDomainEntity(this GenreDto dto)
|
||||
{
|
||||
return Genre.Create(
|
||||
@@ -29,7 +31,9 @@ public static class GenreDtoMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Genre>> ToDomainEntities(this IEnumerable<GenreDto> dtos)
|
||||
{
|
||||
return dtos.Select(repositoryEntity => repositoryEntity.ToDomainEntity());
|
||||
|
||||
@@ -40,7 +40,9 @@ public static class GenreEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Genre> ToDomainEntity(this GenreEntity repositoryEntity)
|
||||
{
|
||||
return Genre.Create(
|
||||
@@ -52,7 +54,9 @@ public static class GenreEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Genre>> ToDomainEntities(this IEnumerable<GenreEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
@@ -17,7 +17,9 @@ public static class TagDtoMapping
|
||||
/// Converts <paramref name="dto"/> to <see cref="Tag"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The DTO to be converted.</param>
|
||||
/// <returns>The converted domain entity.</returns>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Tag> ToDomainEntity(this TagDto dto)
|
||||
{
|
||||
return Tag.Create(
|
||||
@@ -29,7 +31,9 @@ public static class TagDtoMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Tag>> ToDomainEntities(this IEnumerable<TagDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
@@ -40,7 +40,9 @@ public static class TagEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Tag> ToDomainEntity(this TagEntity repositoryEntity)
|
||||
{
|
||||
return Tag.Create(
|
||||
@@ -52,7 +54,9 @@ public static class TagEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Tag>> ToDomainEntities(this IEnumerable<TagEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
+2
-1
@@ -18,7 +18,8 @@ public static class CancelLibraryScanRequestMapping
|
||||
public static CancelLibraryScanCommand ToCommand(this CancelLibraryScanRequest request)
|
||||
{
|
||||
return new CancelLibraryScanCommand(
|
||||
request.Id
|
||||
request.LibraryId,
|
||||
request.ScanId
|
||||
);
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -4,6 +4,8 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -42,12 +44,14 @@ public static class LibraryEntityMapping
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="Library"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted domain entity.</returns>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="Library"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Library> ToDomainEntity(this LibraryEntity repositoryEntity)
|
||||
{
|
||||
return Library.Create(
|
||||
LibraryId.Create(repositoryEntity.Id),
|
||||
repositoryEntity.UserId,
|
||||
UserId.Create(repositoryEntity.UserId),
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.LibraryType,
|
||||
repositoryEntity.ContentLocations.Select(contentLocation => contentLocation.Path),
|
||||
@@ -55,7 +59,8 @@ public static class LibraryEntityMapping
|
||||
repositoryEntity.IsEnabled,
|
||||
repositoryEntity.IsLocked,
|
||||
repositoryEntity.DownloadMedatadaFromWeb,
|
||||
repositoryEntity.SaveMetadataInMediaDirectories
|
||||
repositoryEntity.SaveMetadataInMediaDirectories,
|
||||
repositoryEntity.LibraryScans.Select(libraryScan => ScanId.Create(libraryScan.Id)).ToList()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,7 +68,9 @@ public static class LibraryEntityMapping
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Library"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>The converted responses.</returns>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Library"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Library>> ToDomainEntities(this IEnumerable<LibraryEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(library => library.ToDomainEntity());
|
||||
|
||||
@@ -31,6 +31,18 @@ public static class LibraryMapping
|
||||
IsLocked = domainEntity.IsLocked,
|
||||
DownloadMedatadaFromWeb = domainEntity.DownloadMedatadaFromWeb,
|
||||
SaveMetadataInMediaDirectories = domainEntity.SaveMetadataInMediaDirectories,
|
||||
LibraryScans = domainEntity.ScanIds.Select(scanId => new LibraryScanEntity()
|
||||
{
|
||||
Id = scanId.Value,
|
||||
LibraryId = domainEntity.Id.Value,
|
||||
UserId = domainEntity.UserId.Value, // rest of properties will be populated by EF Core
|
||||
Status = default,
|
||||
User = null!,
|
||||
Library = null!,
|
||||
CreatedBy = default,
|
||||
CreatedOnUtc = default,
|
||||
UpdatedBy = default,
|
||||
}).ToList(),
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="LibraryScanEntity"/>.
|
||||
/// </summary>
|
||||
public static class LibraryScanEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="LibraryScan"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="LibraryScan"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<LibraryScan> ToDomainEntity(this LibraryScanEntity repositoryEntity)
|
||||
{
|
||||
return LibraryScan.Create(
|
||||
ScanId.Create(repositoryEntity.Id),
|
||||
LibraryId.Create(repositoryEntity.LibraryId),
|
||||
UserId.Create(repositoryEntity.UserId),
|
||||
repositoryEntity.Status,
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="LibraryScan"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntities">The repository entities to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="LibraryScan"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<LibraryScan>> ToDomainEntities(this IEnumerable<LibraryScanEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="LibraryScan"/>.
|
||||
/// </summary>
|
||||
public static class LibraryScanMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="LibraryScanEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static LibraryScanEntity ToRepositoryEntity(this LibraryScan domainEntity)
|
||||
{
|
||||
return new LibraryScanEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
UserId = domainEntity.UserId.Value,
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
Status = domainEntity.Status,
|
||||
User = null!,
|
||||
Library = null!,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
UpdatedBy = Guid.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -137,7 +137,7 @@ public static class BookEntityMapping
|
||||
/// <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 successfuly converted <see cref="Book"/>, or error messages.
|
||||
/// An colection of <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Book"/>, or error messages.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Book>> ToDomainEntities(this IEnumerable<BookEntity> repositoryEntities)
|
||||
{
|
||||
|
||||
+6
-2
@@ -19,7 +19,9 @@ public static class BookRatingDtoMapping
|
||||
/// Converts <paramref name="dto"/> to <see cref="BookRating"/>.
|
||||
/// </summary>
|
||||
/// <param name="dto">The DTO to be converted.</param>
|
||||
/// <returns>The converted domain entity.</returns>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<BookRating> ToDomainEntity(this BookRatingDto dto)
|
||||
{
|
||||
return BookRating.Create(
|
||||
@@ -34,7 +36,9 @@ public static class BookRatingDtoMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
+6
-2
@@ -45,7 +45,9 @@ public static class BookRatingEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<BookRating> ToDomainEntity(this BookRatingEntity repositoryEntity)
|
||||
{
|
||||
return BookRating.Create(
|
||||
@@ -60,7 +62,9 @@ public static class BookRatingEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="BookRating"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<BookRating>> ToDomainEntities(this IEnumerable<BookRatingEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
+3
-1
@@ -33,7 +33,9 @@ public static class IsbnDtoMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnDto> dtos)
|
||||
{
|
||||
return dtos.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
+6
-2
@@ -41,7 +41,9 @@ public static class IsbnEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Isbn> ToDomainEntity(this IsbnEntity repositoryEntity)
|
||||
{
|
||||
return Isbn.Create(
|
||||
@@ -54,7 +56,9 @@ public static class IsbnEntityMapping
|
||||
/// 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>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a collection of converted <see cref="Isbn"/>, or an error message.
|
||||
/// </returns>
|
||||
public static IEnumerable<ErrorOr<Isbn>> ToDomainEntities(this IEnumerable<IsbnEntity> repositoryEntities)
|
||||
{
|
||||
return repositoryEntities.Select(domainEntity => domainEntity.ToDomainEntity());
|
||||
|
||||
Reference in new issue
Block a user