mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +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
+103
@@ -0,0 +1,103 @@
|
||||
# Architecture Decision Record (ADR): 0001 - Use of `IServiceScopeFactory` for EF Core Lifetime Management in Library Scan Background Jobs
|
||||
|
||||
## Status
|
||||
**Accepted** (2025-02-15)
|
||||
|
||||
## Context
|
||||
The media library scanning system requires complex job graphs with parent-child relationships that cannot be recreated during execution. The conflict arises from:
|
||||
|
||||
1. **Complex creational pattern**: Library scan jobs have complex parent-child dynamic relationships that needs to be established during the initiation of a library scan. This complex creational logic requires encapsulation (see `IMediaTypeScanner.CreateScanJobsForLibrary()`).
|
||||
2. **Special job execution treatment**: Only top level library scan jobs with no parents are placed on an in-memory queue, from where they will be processed. The children are not placed in this queue because their processing depends on the payload(s) delivered by their parent(s). Therefor, it is the responsibility of the parents to fire the execution of their children's jobs, when their processing is done, and not by the background queue processing job.
|
||||
3. **Discrepancy between user scope and background processing scope**: Processing of queued jobs is done in a singleton context, due to some jobs being long running processes that need to run in a background service. This means that any scoped services created when the user triggered the library scan are long disposed when child jobs are triggered by their parents. This includes unit of works, repositories and DbContexts.
|
||||
1. **EF Core Lifetime Requirements**: DbContext (scoped) becomes disposed before background jobs execute.
|
||||
2. **Domain Integrity Constraints**: Jobs are first-class domain objects with established relationships that must persist.
|
||||
3. **Architecture Layer Boundaries**: Application layer must not reference EF Core directly.
|
||||
|
||||
## Decission
|
||||
`IServiceScopeFactory` will be used in a controlled manner to create execution contexts for background jobs:
|
||||
|
||||
```chsarp
|
||||
// sample job class (simplified)
|
||||
internal sealed class FileSystemDiscoveryJob : MediaLibraryScanJob, IFileSystemDiscoveryJob
|
||||
{
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
|
||||
protected FileSystemDiscoveryJob(IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
_scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync()
|
||||
{
|
||||
await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope();
|
||||
IUnitOfWork unitOfWork = asyncServiceScope.ServiceProvider.GetService<IUnitOfWork>();
|
||||
ILibraryRepository libraryRepository = unitOfWork.GetRepository<ILibraryRepository>();
|
||||
// execution logic
|
||||
}
|
||||
}
|
||||
```
|
||||
## Consequences
|
||||
|
||||
### Positive Outcomes
|
||||
|
||||
| Aspect | Benefit |
|
||||
|-----------------------|-----------------------------------------------------------|
|
||||
| Lifetime Management | Ensures fresh DbContext per job execution |
|
||||
| Domain Model | Preserves job graph relationships |
|
||||
| Performance | Enables parallel processing without shared state |
|
||||
| Layer Integrity | Maintains application layer purity |
|
||||
|
||||
### Risks and Tradeoffs
|
||||
|
||||
| Risk | Mitigation Strategy |
|
||||
|---------------------------|-------------------------------------------------------------------|
|
||||
| Service Locator Pattern | Strictly limit usage to job classes by marking them as `sealed` |
|
||||
| Scope Leakage | `await using` ensures deterministic disposal |
|
||||
| Testing Complexity | Provide base test fixtures for contributors |
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### 1. Job recreation at the background job processor end
|
||||
```csharp
|
||||
internal sealed class MediaLibraryScanJobProcessorJob : BackgroundService
|
||||
{
|
||||
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await foreach (IMediaLibraryScanJob job in _mediaScanQueue.Reader.ReadAllAsync(cancellationToken))
|
||||
{
|
||||
await using AsyncServiceScope scope = _scopeFactory.CreateAsyncScope();
|
||||
{
|
||||
IMediaLibraryScanJob scopedJob = (IMediaLibraryScanJob)scope.ServiceProvider.GetRequiredService(job.GetType());
|
||||
scopedJob.ScanId = originalJob.ScanId;
|
||||
scopedJob.UserId = originalJob.UserId;
|
||||
scopedJob.LibraryId = originalJob.LibraryId;
|
||||
await scopedJob.ExecuteAsync(Guid.NewGuid(), new { }, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Rejected**: Destroys parent-child relationships between jobs. The domain model relies on pre-established directed acyclic graphs that cannot be rehydrated without violating encapsulation (See `IMediaTypeScanner.CreateScanJobsForLibrary()`).
|
||||
|
||||
### 2. Stateful handler pattern
|
||||
```csharp
|
||||
// requires splitting jobs into configuration/execution phases
|
||||
public record JobState(ScanId, UserId, LibraryId);
|
||||
public class JobHandler
|
||||
{
|
||||
public Task ExecuteAsync(JobState state) { /* ... */ }
|
||||
}
|
||||
```
|
||||
|
||||
**Rejected**: Would require complete architectural redesign of the library scanning aggregate, and would not easily scale to multiple jobs requiring different payload types.
|
||||
|
||||
### 3. Registration of `DbContextFactory` instead of `DbContext`
|
||||
```csharp
|
||||
services.AddDbContextFactory<LuminaDbContext>(options =>
|
||||
{
|
||||
options.UseSqlite($"Data Source={Path.Combine(basePath, "Lumina.db")}");
|
||||
}
|
||||
```
|
||||
|
||||
**Rejected**: Would require a dependency on EF Core in the Application layer, and even when using an abstraction, would completely defeat the purpose of using the Repository + Unit of Work patterns used everywhere else in the Application layer.
|
||||
+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());
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
/// <summary>
|
||||
/// Command for deleting an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="RoleId">The Id of the role.</param>
|
||||
/// <param name="RoleId">The unique identifier of the role.</param>
|
||||
[DebuggerDisplay("RoleId: {RoleId}")]
|
||||
public record DeleteRoleCommand(
|
||||
Guid RoleId
|
||||
|
||||
+1
-3
@@ -45,9 +45,7 @@ public class DeleteRoleCommandHandler : IRequestHandler<DeleteRoleCommand, Error
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly deleted <see cref="RoleResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<Deleted>> Handle(DeleteRoleCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// only admins can delete authorization roles
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
/// <summary>
|
||||
/// Command for updating an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="RoleId">The Id of the role.</param>
|
||||
/// <param name="RoleId">The unique identifier of the role.</param>
|
||||
/// <param name="RoleName">The name of the role.</param>
|
||||
/// <param name="Permissions">The collection of Ids of the permissions of the role.</param>
|
||||
[DebuggerDisplay("RoleName: {RoleName}")]
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermi
|
||||
/// <summary>
|
||||
/// Query for getting the authorization permissions of a role identified by <paramref name="RoleId"/>.
|
||||
/// </summary>
|
||||
/// <param name="RoleId">The Id of the authorization role for which to get the list of permissions.</param>
|
||||
/// <param name="RoleId">The unique identifier of the authorization role for which to get the list of permissions.</param>
|
||||
[DebuggerDisplay("RoleId: {RoleId}")]
|
||||
public record GetRolePermissionsQuery(
|
||||
Guid RoleId
|
||||
|
||||
+2
-1
@@ -89,7 +89,8 @@ public class SetupApplicationCommandHandler : IRequestHandler<SetupApplicationCo
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = id
|
||||
CreatedBy = id,
|
||||
LibraryScans = [],
|
||||
};
|
||||
// if the user enabled two factor auth, include a QR with the totp secret
|
||||
if (request.Use2fa)
|
||||
|
||||
+12
-13
@@ -15,6 +15,7 @@ using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -90,7 +91,7 @@ public class AddLibraryCommandHandler : IRequestHandler<AddLibraryCommand, Error
|
||||
|
||||
// create a domain library object
|
||||
ErrorOr<Library> createLibraryResult = Library.Create(
|
||||
_currentUserService.UserId!.Value,
|
||||
UserId.Create(_currentUserService.UserId!.Value),
|
||||
request.Title!,
|
||||
Enum.Parse<LibraryType>(request.LibraryType!),
|
||||
request.ContentLocations!,
|
||||
@@ -98,7 +99,8 @@ public class AddLibraryCommandHandler : IRequestHandler<AddLibraryCommand, Error
|
||||
request.IsEnabled,
|
||||
request.IsLocked,
|
||||
request.DownloadMedatadaFromWeb,
|
||||
request.SaveMetadataInMediaDirectories
|
||||
request.SaveMetadataInMediaDirectories,
|
||||
[]
|
||||
);
|
||||
|
||||
if (createLibraryResult.IsError)
|
||||
@@ -115,22 +117,19 @@ public class AddLibraryCommandHandler : IRequestHandler<AddLibraryCommand, Error
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// retrieve the newly saved media library from the persistence medium and return it
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError)
|
||||
return getLibraryResult.Errors;
|
||||
if (getLibraryResult.Value is null)
|
||||
return ApplicationErrors.Persistence.ErrorPersistingMediaLibrary;
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in createLibraryResult.Value.PopDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
// retrieve the updated media library from the persistence medium and return it
|
||||
ErrorOr<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getCreatedLibraryResult.IsError)
|
||||
return getCreatedLibraryResult.Errors;
|
||||
if (getCreatedLibraryResult.Value is null)
|
||||
return ApplicationErrors.Persistence.ErrorPersistingMediaLibrary;
|
||||
|
||||
// mark the media library as saved
|
||||
createLibraryResult.Value.Save();
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in createLibraryResult.Value.GetDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
return getCreatedLibraryResult.Value.ToResponse();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,6 +6,6 @@ using Mediator;
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrariesScan;
|
||||
|
||||
/// <summary>
|
||||
/// Command for cancelling the previously started scan of all media libraries.
|
||||
/// Command for canceling the previously started scan of all media libraries.
|
||||
/// </summary>
|
||||
public record CancelLibrariesScanCommand : IRequest<ErrorOr<Success>>;
|
||||
+73
-8
@@ -1,8 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Tracking;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
|
||||
using Mediator;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -10,33 +20,88 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibrariesScan;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command for cancelling the scan of all media libraries.
|
||||
/// Handler for the command for canceling the scan of all media libraries.
|
||||
/// </summary>
|
||||
public class CancelLibrariesScanCommandHandler : IRequestHandler<CancelLibrariesScanCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibrariesScanTracker _librariesScanTracker;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IDomainEventsQueue _domainEventsQueue;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CancelLibrariesScanCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="mediaLibraryScanningService">Injected service for scanning media libraries.</param>
|
||||
public CancelLibrariesScanCommandHandler(ICurrentUserService currentUserService, IMediaLibrariesScanTracker librariesScanTracker)
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public CancelLibrariesScanCommandHandler(
|
||||
ICurrentUserService currentUserService,
|
||||
IAuthorizationService authorizationService,
|
||||
IDomainEventsQueue domainEventsQueue,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_librariesScanTracker = librariesScanTracker;
|
||||
_authorizationService = authorizationService;
|
||||
_domainEventsQueue = domainEventsQueue;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command for cancelling the scan of all media libraries.
|
||||
/// Handles the command for canceling the scan of all media libraries.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<Success>> Handle(CancelLibrariesScanCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
_librariesScanTracker.CancelUserScans(_currentUserService.UserId!.Value);
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// get the running library scans of the current user from the repository
|
||||
ErrorOr<IEnumerable<LibraryScanEntity>> getRunningLibraryScansResult = await libraryScanRepository.GetRunningScansAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getRunningLibraryScansResult.IsError)
|
||||
return getRunningLibraryScansResult.Errors;
|
||||
|
||||
// filter the library scans to process
|
||||
List<LibraryScanEntity> authorizedLibraryScans = [];
|
||||
// admins can see all library scans
|
||||
if (await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
|
||||
authorizedLibraryScans.AddRange(getRunningLibraryScansResult.Value);
|
||||
else // for regular users, only take the library scans that belong to them
|
||||
authorizedLibraryScans.AddRange(getRunningLibraryScansResult.Value.Where(libraryScan => libraryScan.UserId == _currentUserService.UserId));
|
||||
|
||||
// convert persistence library scans to domain entities
|
||||
IEnumerable<ErrorOr<LibraryScan>> libraryScansDomainResult = authorizedLibraryScans.ToDomainEntities();
|
||||
|
||||
List<IDomainEvent> domainEvents = [];
|
||||
|
||||
// for each library scan, perform the cancellation
|
||||
foreach (ErrorOr<LibraryScan> libraryScanDomainResult in libraryScansDomainResult)
|
||||
{
|
||||
if (libraryScanDomainResult.IsError)
|
||||
return libraryScanDomainResult.Errors;
|
||||
|
||||
// cancel the media library scan
|
||||
ErrorOr<Success> cancelScanResult = libraryScanDomainResult.Value.CancelScan();
|
||||
if (cancelScanResult.IsError)
|
||||
return cancelScanResult.Errors;
|
||||
|
||||
// update the status of the library scan in the repository
|
||||
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateLibraryScanResult.IsError)
|
||||
return updateLibraryScanResult.Errors;
|
||||
|
||||
// collect all the domain events created during this library scan start
|
||||
domainEvents.AddRange(libraryScanDomainResult.Value.GetDomainEvents());
|
||||
}
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in domainEvents)
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
return await ValueTask.FromResult(Result.Success);
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -8,10 +8,12 @@ using System.Diagnostics;
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
|
||||
|
||||
/// <summary>
|
||||
/// Command for cancelling the scan of a media library by its Id.
|
||||
/// Command for canceling the scan of a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library whose scan is cancelled.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose scan is cancelled.</param>
|
||||
/// <param name="ScanId">The unique identifier of the scan to cancel.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}; ScanId: {ScanId}")]
|
||||
public record CancelLibraryScanCommand(
|
||||
Guid Id
|
||||
Guid LibraryId,
|
||||
Guid ScanId
|
||||
) : IRequest<ErrorOr<Success>>;
|
||||
+59
-14
@@ -3,48 +3,93 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Tracking;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command for cancelling the scan of a media library.
|
||||
/// Handler for the command for canceling the scan of a media library.
|
||||
/// </summary>
|
||||
public class CancelLibraryScanCommandHandler : IRequestHandler<CancelLibraryScanCommand, ErrorOr<Success>>
|
||||
{
|
||||
private readonly IMediaLibraryScanningService _mediaLibraryScanningService;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IDomainEventsQueue _domainEventsQueue;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CancelLibraryScanCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanningService">Injected service for scanning media libraries.</param>
|
||||
public CancelLibraryScanCommandHandler(IMediaLibraryScanningService mediaLibraryScanningService)
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public CancelLibraryScanCommandHandler(
|
||||
IAuthorizationService authorizationService,
|
||||
ICurrentUserService currentUserService,
|
||||
IDomainEventsQueue domainEventsQueue,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_mediaLibraryScanningService = mediaLibraryScanningService;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_domainEventsQueue = domainEventsQueue;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command for cancelling the scan of a media library.
|
||||
/// Handles the command for canceling the scan of a media library.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<Success>> Handle(CancelLibraryScanCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
_mediaLibraryScanningService.CancelScan(request.Id);
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// get the library scan from the repository
|
||||
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(request.ScanId, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryScansResult.IsError)
|
||||
return getLibraryScansResult.Errors;
|
||||
if (getLibraryScansResult.Value is null)
|
||||
return DomainErrors.LibraryScanning.LibraryScanNotFound;
|
||||
|
||||
// if the user that wants to scan the library is not an Admin or is not the owner of the library, they do not have the right to scan it
|
||||
if (getLibraryScansResult.Value.UserId != _currentUserService.UserId ||
|
||||
!await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// convert the repository scan to a domain object
|
||||
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
|
||||
if (libraryScanDomainResult.IsError)
|
||||
return libraryScanDomainResult.Errors;
|
||||
|
||||
// cancel the media library scan
|
||||
ErrorOr<Success> cancelScanResult = libraryScanDomainResult.Value.CancelScan();
|
||||
if (cancelScanResult.IsError)
|
||||
return cancelScanResult.Errors;
|
||||
|
||||
// update the status of the library scan in the repository
|
||||
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateLibraryScanResult.IsError)
|
||||
return updateLibraryScanResult.Errors;
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in libraryScanDomainResult.Value.GetDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
return await ValueTask.FromResult(Result.Success);
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -16,8 +16,11 @@ public class CancelLibraryScanCommandValidator : AbstractValidator<CancelLibrary
|
||||
/// </summary>
|
||||
public CancelLibraryScanCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.Id)
|
||||
RuleFor(x => x.LibraryId)
|
||||
.NotEmpty().WithMessage(Errors.Library.LibraryIdCannotBeEmpty.Description)
|
||||
.Must(id => id != Guid.Empty).WithMessage(Errors.Library.LibraryIdCannotBeEmpty.Description);
|
||||
RuleFor(x => x.ScanId)
|
||||
.NotEmpty().WithMessage(Errors.LibraryScanning.ScanIdCannotBeEmpty.Description)
|
||||
.Must(id => id != Guid.Empty).WithMessage(Errors.LibraryScanning.ScanIdCannotBeEmpty.Description);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary
|
||||
/// <summary>
|
||||
/// Command for deleting a media library by its Id.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library to delete.</param>
|
||||
/// <param name="Id">The unique identifier of the media library to delete.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record DeleteLibraryCommand(
|
||||
Guid Id
|
||||
|
||||
+2
-5
@@ -7,7 +7,6 @@ using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Mediator;
|
||||
@@ -53,9 +52,7 @@ public class DeleteLibraryCommandHandler : IRequestHandler<DeleteLibraryCommand,
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly created <see cref="LibraryResponse"/>, or an error message.
|
||||
/// </returns>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<Deleted>> Handle(DeleteLibraryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// get the library with the specified id from the repository
|
||||
@@ -82,7 +79,7 @@ public class DeleteLibraryCommandHandler : IRequestHandler<DeleteLibraryCommand,
|
||||
return deleteDomainLibraryResult.Errors;
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in createLibraryResult.Value.PopDomainEvents())
|
||||
foreach (IDomainEvent domainEvent in createLibraryResult.Value.GetDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
// perform the deletion
|
||||
|
||||
+58
-9
@@ -3,14 +3,17 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
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.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -26,25 +29,25 @@ public class ScanLibrariesCommandHandler : IRequestHandler<ScanLibrariesCommand,
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibraryScanningService _libraryScanningService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IDomainEventsQueue _domainEventsQueue;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScanLibrariesCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="libraryScanningService">Injected service for scanning media libraries.</param>
|
||||
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public ScanLibrariesCommandHandler(
|
||||
IAuthorizationService authorizationService,
|
||||
ICurrentUserService currentUserService,
|
||||
IMediaLibraryScanningService libraryScanningService,
|
||||
IDomainEventsQueue domainEventsQueue,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_libraryScanningService = libraryScanningService;
|
||||
_domainEventsQueue = domainEventsQueue;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
@@ -56,8 +59,10 @@ public class ScanLibrariesCommandHandler : IRequestHandler<ScanLibrariesCommand,
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<IEnumerable<ScanLibraryResponse>>> Handle(ScanLibrariesCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// get all media libraries that are enabled and unlocked from the persistence medium
|
||||
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// get all media libraries that are enabled and unlocked from the persistence medium
|
||||
ErrorOr<IEnumerable<LibraryEntity>> getLibrariesResult = await libraryRepository.GetAllEnabledAndUnlockedAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (getLibrariesResult.IsError)
|
||||
return getLibrariesResult.Errors;
|
||||
@@ -70,14 +75,58 @@ public class ScanLibrariesCommandHandler : IRequestHandler<ScanLibrariesCommand,
|
||||
domainEntitiesResult = domainEntitiesResult.Where(libraryResult => libraryResult.Value.UserId.Value == _currentUserService.UserId!.Value);
|
||||
|
||||
List<ScanLibraryResponse> responses = [];
|
||||
List<IDomainEvent> domainEvents = [];
|
||||
|
||||
// for each library, start the scan
|
||||
foreach (ErrorOr<Library> domainLibraryResult in domainEntitiesResult)
|
||||
{
|
||||
if (domainLibraryResult.IsError)
|
||||
return domainLibraryResult.Errors;
|
||||
Guid scanId = await _libraryScanningService.StartScanAsync(domainLibraryResult.Value, cancellationToken).ConfigureAwait(false);
|
||||
responses.Add(new ScanLibraryResponse(scanId, domainLibraryResult.Value.Id.Value));
|
||||
|
||||
// get the past month's scans for this library
|
||||
ErrorOr<IEnumerable<LibraryScanEntity>> pastLibraryScansResult =
|
||||
await libraryScanRepository.GetPastMonthScansByLibraryIdAsync(domainLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (pastLibraryScansResult.IsError)
|
||||
return pastLibraryScansResult.Errors;
|
||||
|
||||
// convert the repository scans history to domain objects
|
||||
IEnumerable<ErrorOr<LibraryScan>> pastLibraryScansDomainResult = pastLibraryScansResult.Value.ToDomainEntities();
|
||||
foreach (ErrorOr<LibraryScan> pastLibraryScanDomainResult in pastLibraryScansDomainResult)
|
||||
if (pastLibraryScanDomainResult.IsError)
|
||||
return pastLibraryScanDomainResult.Errors;
|
||||
|
||||
// start the media library scan
|
||||
ErrorOr<LibraryScan> libraryScanResult = LibraryScan.Create(
|
||||
LibraryId.Create(domainLibraryResult.Value.Id.Value),
|
||||
UserId.Create(_currentUserService.UserId!.Value),
|
||||
[.. pastLibraryScansDomainResult.Select(pastLibraryScanDomainResult => pastLibraryScanDomainResult.Value)]
|
||||
);
|
||||
if (libraryScanResult.IsError)
|
||||
return libraryScanResult.Errors;
|
||||
|
||||
ErrorOr<Success> startScanResult = libraryScanResult.Value.QueueScan();
|
||||
// when the user demands a "scan all libraries" action, it would be annoying to receive an error if a library is already being scanned.
|
||||
// instead, just don't start the scan on such a library, and start it on the others that can be started
|
||||
if (startScanResult.IsError)
|
||||
continue;
|
||||
|
||||
// add the library scan to the persistence medium
|
||||
ErrorOr<Created> insertLibraryScanResult = await libraryScanRepository.InsertAsync(libraryScanResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (insertLibraryScanResult.IsError)
|
||||
return insertLibraryScanResult.Errors;
|
||||
|
||||
// collect all the domain events created during this library scan start
|
||||
domainEvents.AddRange(libraryScanResult.Value.GetDomainEvents());
|
||||
|
||||
responses.Add(new ScanLibraryResponse(libraryScanResult.Value.Id.Value, domainLibraryResult.Value.Id.Value));
|
||||
}
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in domainEvents)
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
return responses;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
|
||||
/// <summary>
|
||||
/// Command for initiating the scan of a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the library to scan.</param>
|
||||
/// <param name="Id">The unique identifier of the library to scan.</param>
|
||||
public record ScanLibraryCommand(
|
||||
Guid Id
|
||||
) : IRequest<ErrorOr<ScanLibraryResponse>>;
|
||||
+53
-13
@@ -3,14 +3,20 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
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 Mediator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -26,25 +32,25 @@ public class ScanLibraryCommandHandler : IRequestHandler<ScanLibraryCommand, Err
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibraryScanningService _mediaLibraryScanningService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IDomainEventsQueue _domainEventsQueue;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScanLibraryCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="mediaLibraryScanningService">Injected service for scanning media libraries.</param>
|
||||
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public ScanLibraryCommandHandler(
|
||||
IAuthorizationService authorizationService,
|
||||
ICurrentUserService currentUserService,
|
||||
IMediaLibraryScanningService mediaLibraryScanningService,
|
||||
IDomainEventsQueue domainEventsQueue,
|
||||
IUnitOfWork unitOfWork)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_mediaLibraryScanningService = mediaLibraryScanningService;
|
||||
_domainEventsQueue = domainEventsQueue;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
@@ -56,8 +62,10 @@ public class ScanLibraryCommandHandler : IRequestHandler<ScanLibraryCommand, Err
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async ValueTask<ErrorOr<ScanLibraryResponse>> Handle(ScanLibraryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// get the media library from the persistence medium
|
||||
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// get the media library from the persistence medium
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError)
|
||||
return getLibraryResult.Errors;
|
||||
@@ -65,7 +73,7 @@ public class ScanLibraryCommandHandler : IRequestHandler<ScanLibraryCommand, Err
|
||||
if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// if the user that wants to delete the library is not an Admin or is not the owner of the library, they do not have the right to scan it
|
||||
// if the user that wants to scan the library is not an Admin or is not the owner of the library, they do not have the right to scan it
|
||||
if (getLibraryResult.Value.UserId != _currentUserService.UserId ||
|
||||
!await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false))
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
@@ -77,14 +85,46 @@ public class ScanLibraryCommandHandler : IRequestHandler<ScanLibraryCommand, Err
|
||||
if (getLibraryResult.Value.IsLocked)
|
||||
return DomainErrors.Library.CannotScanLockedLibrary;
|
||||
|
||||
// convert persistence libraries to domain entities
|
||||
// convert the persistence library to a domain entity
|
||||
ErrorOr<Library> domainLibraryResult = getLibraryResult.Value.ToDomainEntity();
|
||||
|
||||
if (domainLibraryResult.IsError)
|
||||
return domainLibraryResult.Errors;
|
||||
|
||||
// start the media library scan
|
||||
Guid scanId = await _mediaLibraryScanningService.StartScanAsync(domainLibraryResult.Value, cancellationToken).ConfigureAwait(false);
|
||||
return new ScanLibraryResponse(scanId, domainLibraryResult.Value.Id.Value);
|
||||
// get the past month's scans for this library
|
||||
ErrorOr<IEnumerable<LibraryScanEntity>> pastLibraryScansResult = await libraryScanRepository.GetPastMonthScansByLibraryIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (pastLibraryScansResult.IsError)
|
||||
return pastLibraryScansResult.Errors;
|
||||
|
||||
// convert the repository scans history to domain objects
|
||||
IEnumerable<ErrorOr<LibraryScan>> pastLibraryScansDomainResult = pastLibraryScansResult.Value.ToDomainEntities();
|
||||
foreach (ErrorOr<LibraryScan> pastLibraryScanDomainResult in pastLibraryScansDomainResult)
|
||||
if (pastLibraryScanDomainResult.IsError)
|
||||
return pastLibraryScanDomainResult.Errors;
|
||||
|
||||
// queue the media library scan
|
||||
ErrorOr<LibraryScan> libraryScanResult = LibraryScan.Create(
|
||||
LibraryId.Create(request.Id),
|
||||
UserId.Create(_currentUserService.UserId!.Value),
|
||||
[.. pastLibraryScansDomainResult.Select(pastLibraryScanDomainResult => pastLibraryScanDomainResult.Value)]
|
||||
);
|
||||
if (libraryScanResult.IsError)
|
||||
return libraryScanResult.Errors;
|
||||
|
||||
ErrorOr<Success> queueScanResult = libraryScanResult.Value.QueueScan();
|
||||
if (queueScanResult.IsError)
|
||||
return queueScanResult.Errors;
|
||||
|
||||
// add the library scan to the persistence medium
|
||||
ErrorOr<Created> insertLibraryScanResult = await libraryScanRepository.InsertAsync(libraryScanResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (insertLibraryScanResult.IsError)
|
||||
return insertLibraryScanResult.Errors;
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in libraryScanResult.Value.GetDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
return new ScanLibraryResponse(libraryScanResult.Value.Id.Value, domainLibraryResult.Value.Id.Value);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -11,8 +11,8 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary
|
||||
/// <summary>
|
||||
/// Command for updating a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library.</param>
|
||||
/// <param name="OwnerId">The Id of the user owning the media library.</param>
|
||||
/// <param name="Id">The unique identifier of the media library.</param>
|
||||
/// <param name="OwnerId">The unique identifier of the user owning the media library.</param>
|
||||
/// <param name="Title">The title of the media library.</param>
|
||||
/// <param name="LibraryType">The type of the media library.</param>
|
||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located.</param>
|
||||
|
||||
+16
-7
@@ -16,8 +16,11 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
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 Mediator;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -83,13 +86,14 @@ public class UpdateLibraryCommandHandler : IRequestHandler<UpdateLibraryCommand,
|
||||
return DomainErrors.Library.CoverFileMustBeAnImage;
|
||||
}
|
||||
|
||||
// get a library repository
|
||||
// get a library repository and retrieve the library to update
|
||||
ILibraryRepository libraryRepository = _unitOfWork.GetRepository<ILibraryRepository>();
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(request.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError)
|
||||
return getLibraryResult.Errors;
|
||||
else if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// if the user that made the request is not an Admin or is not the owner of the library, they do not have the right to update it
|
||||
if (getLibraryResult.Value.UserId != _currentUserService.UserId ||
|
||||
(!await _authorizationService.IsInRoleAsync(_currentUserService.UserId!.Value, "Admin", cancellationToken).ConfigureAwait(false) &&
|
||||
@@ -99,7 +103,7 @@ public class UpdateLibraryCommandHandler : IRequestHandler<UpdateLibraryCommand,
|
||||
// create a domain library object
|
||||
ErrorOr<Library> createLibraryResult = Library.Create(
|
||||
LibraryId.Create(request.Id),
|
||||
request.OwnerId,
|
||||
UserId.Create(request.OwnerId),
|
||||
request.Title!,
|
||||
Enum.Parse<LibraryType>(request.LibraryType!),
|
||||
request.ContentLocations!,
|
||||
@@ -107,7 +111,8 @@ public class UpdateLibraryCommandHandler : IRequestHandler<UpdateLibraryCommand,
|
||||
request.IsEnabled,
|
||||
request.IsLocked,
|
||||
request.DownloadMedatadaFromWeb,
|
||||
request.SaveMetadataInMediaDirectories
|
||||
request.SaveMetadataInMediaDirectories,
|
||||
getLibraryResult.Value.LibraryScans.Select(libraryScan => ScanId.Create(libraryScan.Id)).ToList()
|
||||
);
|
||||
if (createLibraryResult.IsError)
|
||||
return createLibraryResult.Errors;
|
||||
@@ -120,16 +125,20 @@ public class UpdateLibraryCommandHandler : IRequestHandler<UpdateLibraryCommand,
|
||||
return updateLibraryResult.Errors;
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in createLibraryResult.Value.PopDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
// retrieve the updated media library from the persistence medium and return it
|
||||
ErrorOr<LibraryEntity?> getCreatedLibraryResult = await libraryRepository.GetByIdAsync(createLibraryResult.Value.Id.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getCreatedLibraryResult.IsError)
|
||||
return getCreatedLibraryResult.Errors;
|
||||
if (getCreatedLibraryResult.Value is null)
|
||||
return ApplicationErrors.Persistence.ErrorPersistingMediaLibrary;
|
||||
|
||||
// mark the media library as saved
|
||||
createLibraryResult.Value.Save();
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent domainEvent in createLibraryResult.Value.GetDomainEvents())
|
||||
_domainEventsQueue.Enqueue(domainEvent);
|
||||
|
||||
return getCreatedLibraryResult.Value.ToResponse();
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -111,7 +111,7 @@ public class LibrarySavedDomainEventHandler : INotificationHandler<LibrarySavedD
|
||||
/// <summary>
|
||||
/// Saves the cover image of a media library to the internal media directory.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the library for which to save the cover image.</param>
|
||||
/// <param name="libraryId">The unique identifier of the library for which to save the cover image.</param>
|
||||
/// <param name="imagePath">The file path of the image file that will be copied to the media directory.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
@@ -200,14 +200,10 @@ public class LibrarySavedDomainEventHandler : INotificationHandler<LibrarySavedD
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the cover image of a media library to the internal media directory.
|
||||
/// Deletes the cover image from the media directory.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the library for which to save the cover image.</param>
|
||||
/// <param name="imagePath">The file path of the image file that will be copied to the media directory.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either the location of the new cover image, or an error message.
|
||||
/// </returns>
|
||||
/// <param name="libraryPath">The path where the library content is located.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
private ErrorOr<Deleted> DeleteCoverImageFromMediaDirectory(string libraryPath)
|
||||
{
|
||||
|
||||
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the event raised when a media library scan is cancelled.
|
||||
/// </summary>
|
||||
public class LibraryScanCancelledDomainEventHandler : INotificationHandler<LibraryScanCancelledDomainEvent>
|
||||
{
|
||||
private readonly IMediaLibraryScanningService _mediaLibraryScanningService;
|
||||
private readonly ILibraryScanRepository _libraryScanRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanCancelledDomainEventHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanningService">Injected service for scanning media libraries.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public LibraryScanCancelledDomainEventHandler(IMediaLibraryScanningService mediaLibraryScanningService, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_mediaLibraryScanningService = mediaLibraryScanningService;
|
||||
_libraryScanRepository = unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the event raised when a media library scan is cancelled.
|
||||
/// </summary>
|
||||
/// <param name="domainEvent">The domain event to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async ValueTask Handle(LibraryScanCancelledDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
// get the library scan from the repository
|
||||
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await _libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryScansResult.IsError)
|
||||
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
|
||||
if (getLibraryScansResult.Value is null)
|
||||
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
|
||||
|
||||
// convert the repository scan to a domain object
|
||||
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
|
||||
if (libraryScanDomainResult.IsError)
|
||||
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
|
||||
|
||||
// cancel the media library scan
|
||||
ErrorOr<Success> cancelScanResult = _mediaLibraryScanningService.CancelScan(libraryScanDomainResult.Value);
|
||||
if (cancelScanResult.IsError)
|
||||
throw new EventualConsistencyException(cancelScanResult.FirstError, cancelScanResult.Errors);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the event raised when a media library scan has failed.
|
||||
/// </summary>
|
||||
public class LibraryScanFailedDomainEventHandler : INotificationHandler<LibraryScanFailedDomainEvent>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanCancelledDomainEventHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public LibraryScanFailedDomainEventHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the event raised when a media library scan has failed.
|
||||
/// </summary>
|
||||
/// <param name="domainEvent">The domain event to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async ValueTask Handle(LibraryScanFailedDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// get the library scan from the repository
|
||||
ErrorOr<LibraryScanEntity?> getLibraryScansResult = await libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryScansResult.IsError)
|
||||
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
|
||||
if (getLibraryScansResult.Value is null)
|
||||
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
|
||||
|
||||
// convert the repository scan to a domain object
|
||||
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
|
||||
if (libraryScanDomainResult.IsError)
|
||||
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
|
||||
|
||||
// mark the media library scan as failed
|
||||
ErrorOr<Success> failScanResult = libraryScanDomainResult.Value.FailScan();
|
||||
// we're going to ignore errors in this point, because scan jobs run in parallel, and two concurrent jobs might trigger this domain event,
|
||||
// trying to set as failed a scan that has already been marked as failed by a concurrent job
|
||||
if (!failScanResult.IsError)
|
||||
{
|
||||
// update the status of the library scan in the repository
|
||||
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(libraryScanDomainResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateLibraryScanResult.IsError)
|
||||
throw new EventualConsistencyException(updateLibraryScanResult.FirstError, updateLibraryScanResult.Errors);
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the event raised when a media library's scan progress changes.
|
||||
/// </summary>
|
||||
public class LibraryScanProgressChangedDomainEventHandler : INotificationHandler<LibraryScanProgressChangedDomainEvent>
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the event raised when a media library's scan progress changes.
|
||||
/// </summary>
|
||||
/// <param name="domainEvent">The domain event to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async ValueTask Handle(LibraryScanProgressChangedDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the event raised when a media library scan is queued.
|
||||
/// </summary>
|
||||
public class LibraryScanQueuedDomainEventHandler : INotificationHandler<LibraryScanQueuedDomainEvent>
|
||||
{
|
||||
private readonly IMediaLibraryScanningService _mediaLibraryScanningService;
|
||||
private readonly IDomainEventsQueue _domainEventsQueue;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanQueuedDomainEventHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaLibraryScanningService">Injected service for scanning media libraries.</param>
|
||||
/// <param name="domainEventsQueue">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="domainEventsQueue">Injected service for the queue of domain events.</param>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public LibraryScanQueuedDomainEventHandler(IMediaLibraryScanningService mediaLibraryScanningService, IDomainEventsQueue domainEventsQueue, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_mediaLibraryScanningService = mediaLibraryScanningService;
|
||||
_domainEventsQueue = domainEventsQueue;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the event raised when a media library scan is queued.
|
||||
/// </summary>
|
||||
/// <param name="domainEvent">The domain event to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async ValueTask Handle(LibraryScanQueuedDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// get the library scan that was queued, from the repository
|
||||
ErrorOr<LibraryScanEntity?> getLibraryScanResult = await libraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryScanResult.IsError || getLibraryScanResult.Value is null)
|
||||
throw new EventualConsistencyException(getLibraryScanResult.FirstError, getLibraryScanResult.Errors);
|
||||
|
||||
// convert the repository entity to a domain entity
|
||||
ErrorOr<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
|
||||
if (libraryScanDomainResult.IsError)
|
||||
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
|
||||
|
||||
// start the media library scan
|
||||
ErrorOr<Success> startScanResult = await _mediaLibraryScanningService.StartScanAsync(
|
||||
libraryScanDomainResult.Value, getLibraryScanResult.Value.Library.LibraryType, getLibraryScanResult.Value.Library.DownloadMedatadaFromWeb, cancellationToken).ConfigureAwait(false);
|
||||
if (startScanResult.IsError)
|
||||
throw new EventualConsistencyException(startScanResult.FirstError, startScanResult.Errors);
|
||||
|
||||
// queue any domain events
|
||||
foreach (IDomainEvent queuedDomainEvent in libraryScanDomainResult.Value.GetDomainEvents())
|
||||
_domainEventsQueue.Enqueue(queuedDomainEvent);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Exceptions;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Mediator;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the event raised when a media library scan is started.
|
||||
/// </summary>
|
||||
public class LibraryScanStartedDomainEventHandler : INotificationHandler<LibraryScanStartedDomainEvent>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanStartedDomainEventHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public LibraryScanStartedDomainEventHandler(IUnitOfWork unitOfWork)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the event raised when a media library scan is started.
|
||||
/// </summary>
|
||||
/// <param name="domainEvent">The domain event to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async ValueTask Handle(LibraryScanStartedDomainEvent domainEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
ILibraryScanRepository libraryScanRepository = _unitOfWork.GetRepository<ILibraryScanRepository>();
|
||||
|
||||
// update the status of the library scan in the repository
|
||||
ErrorOr<Updated> updateLibraryScanResult = await libraryScanRepository.UpdateAsync(domainEvent.LibraryScan.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateLibraryScanResult.IsError)
|
||||
throw new EventualConsistencyException(updateLibraryScanResult.FirstError, updateLibraryScanResult.Errors);
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
|
||||
/// <summary>
|
||||
/// Query for getting a media library by its Id.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library to get.</param>
|
||||
/// <param name="Id">The unique identifier of the media library to get.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record GetLibraryQuery(
|
||||
Guid Id
|
||||
|
||||
+11
-10
@@ -1,16 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Models.Scanning;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Tracking;
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Cancellation;
|
||||
|
||||
/// <summary>
|
||||
/// Tracker used for in-progress media library scans.
|
||||
/// Tracker used for canceling in-memory media library scans.
|
||||
/// </summary>
|
||||
internal class MediaLibrariesScanTracker : IMediaLibrariesScanTracker, IDisposable
|
||||
internal class MediaLibrariesScanCancellationTracker : IMediaLibrariesScanCancellationTracker, IDisposable
|
||||
{
|
||||
private readonly ConcurrentDictionary<MediaScanTrackerModel, CancellationTokenSource> _runningScans = new();
|
||||
private bool _disposed;
|
||||
@@ -18,8 +19,8 @@ internal class MediaLibrariesScanTracker : IMediaLibrariesScanTracker, IDisposab
|
||||
/// <summary>
|
||||
/// Registers a new scan operation for tracking.
|
||||
/// </summary>
|
||||
/// <param name="scanId">The Id of the scan operation to track.</param>
|
||||
/// <param name="userId">The Id of the user who initiated the scan to track.</param>
|
||||
/// <param name="scanId">The unique identifier of the scan operation to track.</param>
|
||||
/// <param name="userId">The unique identifier of the user who initiated the scan to track.</param>
|
||||
public void RegisterScan(Guid scanId, Guid userId)
|
||||
{
|
||||
_runningScans.TryAdd(new MediaScanTrackerModel(scanId, userId), new CancellationTokenSource());
|
||||
@@ -28,8 +29,8 @@ internal class MediaLibrariesScanTracker : IMediaLibrariesScanTracker, IDisposab
|
||||
/// <summary>
|
||||
/// Gets the cancellation token for a scan identified by <paramref name="scanId"/> and <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="scanId">The Id of the scan to get the cancellation token for<./param>
|
||||
/// <param name="userId">The Id of the user who initiated the scan for which to get the cancellation token.</param>
|
||||
/// <param name="scanId">The unique identifier of the scan to get the cancellation token for<./param>
|
||||
/// <param name="userId">The unique identifier of the user who initiated the scan for which to get the cancellation token.</param>
|
||||
/// <returns>A cancellation token for the specified scan.</returns>
|
||||
public CancellationToken GetTokenForScan(Guid scanId, Guid userId)
|
||||
{
|
||||
@@ -41,8 +42,8 @@ internal class MediaLibrariesScanTracker : IMediaLibrariesScanTracker, IDisposab
|
||||
/// <summary>
|
||||
/// Cancels a scan identified by <paramref name="scanId"/> and <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="scanId">The Id of the scan operation to cancel.</param>
|
||||
/// <param name="userId">The Id of the user requesting the cancellation.</param>
|
||||
/// <param name="scanId">The unique identifier of the scan operation to cancel.</param>
|
||||
/// <param name="userId">The unique identifier of the user requesting the cancellation.</param>
|
||||
public void CancelScan(Guid scanId, Guid userId)
|
||||
{
|
||||
foreach (MediaScanTrackerModel key in _runningScans.Keys)
|
||||
@@ -63,7 +64,7 @@ internal class MediaLibrariesScanTracker : IMediaLibrariesScanTracker, IDisposab
|
||||
/// <summary>
|
||||
/// Cancels all active scan operations for a user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user whose scans should be cancelled.</param>
|
||||
/// <param name="userId">The unique identifier of the user whose scans should be canceled.</param>
|
||||
public void CancelUserScans(Guid userId)
|
||||
{
|
||||
foreach (MediaScanTrackerModel key in _runningScans.Keys)
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service used to scan a media library.
|
||||
/// </summary>
|
||||
public interface IMediaLibraryScanningService
|
||||
{
|
||||
/// <summary>
|
||||
/// Starts the scan of <paramref name="library"/>.
|
||||
/// </summary>
|
||||
/// <param name="library">The media library to scan.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The Id of the media library scan.</returns>
|
||||
Task<Guid> StartScanAsync(Library library, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels the scan identified by <paramref name="scanId"/>.
|
||||
/// </summary>
|
||||
/// <param name="scanId">The Id of the scan to cancel.</param>
|
||||
void CancelScan(Guid scanId);
|
||||
}
|
||||
+70
-6
@@ -1,5 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DomainEvents;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Payloads;
|
||||
using Lumina.Domain.Common.Enums.FileSystem;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
@@ -7,6 +12,12 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Mediator;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -18,20 +29,26 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs
|
||||
/// <summary>
|
||||
/// Media library scan job for discovering file system items.
|
||||
/// </summary>
|
||||
internal class FileSystemDiscoveryJob : MediaLibraryScanJob
|
||||
internal sealed class FileSystemDiscoveryJob : MediaLibraryScanJob, IFileSystemDiscoveryJob
|
||||
{
|
||||
private readonly IDirectoryService _directoryService;
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IServiceScopeFactory _serviceScopeFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemDiscoveryJob"/> class.
|
||||
/// </summary>
|
||||
/// <param name="directoryService">Injected service for handling directories.</param>
|
||||
/// <param name="fileService">Injected service for handling files.</param>
|
||||
public FileSystemDiscoveryJob(IDirectoryService directoryService, IFileService fileService)
|
||||
/// <param name="serviceScopeFactory">
|
||||
/// Injected factory for creating scopes in which services are requested.
|
||||
/// See docs/technical/achitecture/architecture-knowledge-management/architecture-decision-log/architecture-decission-record-0001.md for details.
|
||||
/// </param>
|
||||
public FileSystemDiscoveryJob(IDirectoryService directoryService, IFileService fileService, IServiceScopeFactory serviceScopeFactory)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
_fileService = fileService;
|
||||
_serviceScopeFactory = serviceScopeFactory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -44,9 +61,45 @@ internal class FileSystemDiscoveryJob : MediaLibraryScanJob
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
|
||||
Console.WriteLine("started file discovering");
|
||||
// see docs/technical/achitecture/architecture-knowledge-management/architecture-decision-log/architecture-decission-record-0001.md for details:
|
||||
await using AsyncServiceScope asyncServiceScope = _serviceScopeFactory.CreateAsyncScope();
|
||||
IUnitOfWork? unitOfWork = asyncServiceScope.ServiceProvider.GetService<IUnitOfWork>();
|
||||
IPublisher? publisher = asyncServiceScope.ServiceProvider.GetService<IPublisher>();
|
||||
ILibraryRepository libraryRepository = unitOfWork!.GetRepository<ILibraryRepository>();
|
||||
|
||||
// get the library from the repository
|
||||
ErrorOr<LibraryEntity?> getLibraryResult = await libraryRepository.GetByIdAsync(LibraryId.Value, cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsError || getLibraryResult.Value is null)
|
||||
{
|
||||
await publisher!.Publish(new LibraryScanFailedDomainEvent(Guid.NewGuid(), ScanId, LibraryId, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// convert it to a domain object
|
||||
ErrorOr<Library> domainLibraryResult = getLibraryResult.Value.ToDomainEntity();
|
||||
if (domainLibraryResult.IsError)
|
||||
{
|
||||
await publisher!.Publish(new LibraryScanFailedDomainEvent(Guid.NewGuid(), ScanId, LibraryId, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// set the initial progress of the scan job
|
||||
ErrorOr<ScanJobProgress> scanJobProgressResult = ScanJobProgress.Create(0, domainLibraryResult.Value.ContentLocations.Count, "DiscoveringFiles");
|
||||
if (scanJobProgressResult.IsError)
|
||||
{
|
||||
await publisher!.Publish(new LibraryScanFailedDomainEvent(Guid.NewGuid(), ScanId, LibraryId, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
_jobProgress = scanJobProgressResult.Value;
|
||||
await publisher!.Publish(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), ScanId, LibraryId, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
Console.WriteLine($"Reporting job progress in file discovery. Total: {_jobProgress.TotalItems}; Completed: {_jobProgress.CompletedItems}; Current: {_jobProgress.CurrentOperation}");
|
||||
// recursively get the file system tree for each of the media library content locations
|
||||
List<FileSystemTreeNode> contentLocationTrees = [];
|
||||
foreach (FileSystemPathId contentLocation in Library.ContentLocations)
|
||||
foreach (FileSystemPathId contentLocation in domainLibraryResult.Value.ContentLocations)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ErrorOr<FileSystemTreeNode> treeResult = BuildTree(contentLocation, includeHiddenElements: true, cancellationToken);
|
||||
@@ -57,16 +110,27 @@ internal class FileSystemDiscoveryJob : MediaLibraryScanJob
|
||||
}
|
||||
else
|
||||
contentLocationTrees.Add(treeResult.Value);
|
||||
|
||||
// increment the number of processed elements progress
|
||||
scanJobProgressResult = ScanJobProgress.Create(
|
||||
scanJobProgressResult.Value.CompletedItems + 1, domainLibraryResult.Value.ContentLocations.Count, "DiscoveringFiles");
|
||||
if (scanJobProgressResult.IsError)
|
||||
{
|
||||
await publisher!.Publish(new LibraryScanFailedDomainEvent(Guid.NewGuid(), ScanId, LibraryId, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await publisher!.Publish(new LibraryScanProgressChangedDomainEvent(Guid.NewGuid(), ScanId, LibraryId, DateTime.UtcNow), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
Console.WriteLine("ended file discovering");
|
||||
Status = LibraryScanJobStatus.Completed;
|
||||
// call each linked child with the obtained payload
|
||||
foreach (MediaLibraryScanJob children in Children)
|
||||
foreach (IMediaLibraryScanJob children in Children)
|
||||
await children.ExecuteAsync(id, contentLocationTrees, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Cancelled;
|
||||
Status = LibraryScanJobStatus.Canceled;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -77,7 +141,7 @@ internal class FileSystemDiscoveryJob : MediaLibraryScanJob
|
||||
/// <param name="path">The identifier of the root path from which to build the tree.</param>
|
||||
/// <param name="includeHiddenElements">Specifies whether hidden files and directories should be included in the tree.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a <see cref="FileSystemTreeNode"/>, or an error.</returns>
|
||||
public ErrorOr<FileSystemTreeNode> BuildTree(FileSystemPathId path, bool includeHiddenElements = false, CancellationToken cancellationToken = default)
|
||||
private ErrorOr<FileSystemTreeNode> BuildTree(FileSystemPathId path, bool includeHiddenElements = false, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// validate the path and get the root directory node
|
||||
ErrorOr<Directory> rootDirectoryResult = Directory.Create(path, path.Path, Optional<DateTime>.None(), Optional<DateTime>.None());
|
||||
|
||||
+12
-3
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -11,7 +12,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs
|
||||
/// <summary>
|
||||
/// Media library scan job for comparing hashes.
|
||||
/// </summary>
|
||||
internal class HashComparerJob : MediaLibraryScanJob
|
||||
internal sealed class HashComparerJob : MediaLibraryScanJob, IHashComparerJob
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override async Task ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken cancellationToken)
|
||||
@@ -23,16 +24,24 @@ internal class HashComparerJob : MediaLibraryScanJob
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
Console.WriteLine("started file hashing");
|
||||
List<int> ints = [1, 2, 3];
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(1111, cancellationToken).ConfigureAwait(false);
|
||||
Console.WriteLine("ticking");
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
Status = LibraryScanJobStatus.Completed;
|
||||
Console.WriteLine("ended file hashing");
|
||||
// call each linked child with the obtained payload
|
||||
foreach (MediaLibraryScanJob children in Children)
|
||||
foreach (IMediaLibraryScanJob children in Children)
|
||||
await children.ExecuteAsync(id, ints, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Cancelled;
|
||||
Status = LibraryScanJobStatus.Canceled;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -11,7 +12,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs
|
||||
/// <summary>
|
||||
/// Media library scan job for retrieving persistence data from any eventual previous scans.
|
||||
/// </summary>
|
||||
internal class RepositoryMetadataDiscoveryJob : MediaLibraryScanJob
|
||||
internal sealed class RepositoryMetadataDiscoveryJob : MediaLibraryScanJob, IRepositoryMetadataDiscoveryJob
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override async Task ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken cancellationToken)
|
||||
@@ -23,16 +24,18 @@ internal class RepositoryMetadataDiscoveryJob : MediaLibraryScanJob
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
Console.WriteLine("started repo discovering");
|
||||
List<int> ints = [1, 2, 3];
|
||||
Status = LibraryScanJobStatus.Completed;
|
||||
Console.WriteLine("ended repo discovering");
|
||||
// call each linked child with the obtained payload
|
||||
foreach (MediaLibraryScanJob children in Children)
|
||||
foreach (IMediaLibraryScanJob children in Children)
|
||||
await children.ExecuteAsync(id, ints, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Cancelled;
|
||||
Status = LibraryScanJobStatus.Canceled;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Common;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -12,7 +13,7 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs
|
||||
/// <summary>
|
||||
/// Media library scan job for retrieving written content metadata from GoodReads.
|
||||
/// </summary>
|
||||
internal class GoodReadsMetadataScrapJob : MediaLibraryScanJob
|
||||
internal sealed class GoodReadsMetadataScrapJob : MediaLibraryScanJob, IGoodReadsMetadataScrapJob
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override async Task ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken cancellationToken)
|
||||
@@ -24,16 +25,18 @@ internal class GoodReadsMetadataScrapJob : MediaLibraryScanJob
|
||||
if (Parents.Count == 0 || parentsPayloadsExecuted == Parents.Count)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Running;
|
||||
Console.WriteLine("started goodreads metadata");
|
||||
List<int> ints = [1, 2, 3];
|
||||
Status = LibraryScanJobStatus.Completed;
|
||||
Console.WriteLine("ended goodreads metadata");
|
||||
// call each linked child with the obtained payload
|
||||
foreach (MediaLibraryScanJob children in Children)
|
||||
foreach (IMediaLibraryScanJob children in Children)
|
||||
await children.ExecuteAsync(id, ints, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Status = LibraryScanJobStatus.Cancelled;
|
||||
Status = LibraryScanJobStatus.Canceled;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Common;
|
||||
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.Tracking;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning;
|
||||
|
||||
/// <summary>
|
||||
/// Service used to scan a media library.
|
||||
/// </summary>
|
||||
internal class MediaLibraryScanningService : IMediaLibraryScanningService
|
||||
{
|
||||
private readonly IMediaLibrariesScanQueue _mediaScanQueue;
|
||||
private readonly IMediaLibraryScannerFactory _libraryScannerFactory;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMediaLibrariesScanTracker _librariesScanTracker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaLibraryScanningService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaScanQueue">Injected queue used for processing media libraries scan jobs.</param>
|
||||
/// <param name="libraryScannerFactory">Injected factory for creating media library scanners.</param>
|
||||
public MediaLibraryScanningService(
|
||||
IMediaLibrariesScanQueue mediaScanQueue,
|
||||
IMediaLibraryScannerFactory libraryScannerFactory,
|
||||
IMediaLibrariesScanTracker librariesScanTracker,
|
||||
ICurrentUserService currentUserService)
|
||||
{
|
||||
_mediaScanQueue = mediaScanQueue;
|
||||
_libraryScannerFactory = libraryScannerFactory;
|
||||
_currentUserService = currentUserService;
|
||||
_librariesScanTracker = librariesScanTracker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the scan of <paramref name="library"/>.
|
||||
/// </summary>
|
||||
/// <param name="library">The media library to scan.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The Id of the media library scan.</returns>
|
||||
public async Task<Guid> StartScanAsync(Library library, CancellationToken cancellationToken)
|
||||
{
|
||||
Guid scanId = Guid.NewGuid();
|
||||
_librariesScanTracker.RegisterScan(scanId, _currentUserService.UserId!.Value);
|
||||
|
||||
try
|
||||
{
|
||||
// link the user's cancellation token with the scan's token
|
||||
CancellationTokenSource linkedSource = CancellationTokenSource
|
||||
.CreateLinkedTokenSource(cancellationToken, _librariesScanTracker.GetTokenForScan(scanId, _currentUserService.UserId!.Value));
|
||||
|
||||
// get a media library scanner for the provided media library type
|
||||
IMediaTypeScanner scanner = _libraryScannerFactory.CreateLibraryScanner(library.LibraryType);
|
||||
// get the list of scan jobs for the retrieved scanner
|
||||
IEnumerable<MediaLibraryScanJob> jobs = scanner.CreateScanJobsForLibrary(library);
|
||||
// enqueue the jobs on the channel from where they will be processed
|
||||
foreach (MediaLibraryScanJob job in jobs)
|
||||
{
|
||||
job.ScanId = scanId;
|
||||
job.UserId = _currentUserService.UserId!.Value;
|
||||
await _mediaScanQueue.Writer.WriteAsync(job, linkedSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (NotImplementedException) { }
|
||||
return scanId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancels the scan identified by <paramref name="scanId"/>.
|
||||
/// </summary>
|
||||
/// <param name="scanId">The Id of the scan to cancel.</param>
|
||||
public void CancelScan(Guid scanId)
|
||||
{
|
||||
_librariesScanTracker.CancelScan(scanId, _currentUserService.UserId!.Value);
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Common;
|
||||
using System.Threading.Channels;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queue;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the message queue for handling <see cref="MediaLibraryScanJob"/> instances.
|
||||
/// </summary>
|
||||
internal interface IMediaLibrariesScanQueue
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the writer for the queue, allowing producers to enqueue <see cref="MediaLibraryScanJob"/> instances.
|
||||
/// </summary>
|
||||
public ChannelWriter<MediaLibraryScanJob> Writer { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reader for the queue, allowing consumers to dequeue <see cref="MediaLibraryScanJob"/> instances.
|
||||
/// </summary>
|
||||
public ChannelReader<MediaLibraryScanJob> Reader { get; }
|
||||
}
|
||||
+13
-13
@@ -1,30 +1,30 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue;
|
||||
using System.Threading.Channels;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queue;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an in-memory message queue for handling <see cref="MediaLibraryScanJob"/> instances.
|
||||
/// Provides an in-memory message queue for handling <see cref="IMediaLibraryScanJob"/> instances.
|
||||
/// </summary>
|
||||
internal class MediaLibrariesScanQueue : IMediaLibrariesScanQueue
|
||||
{
|
||||
private readonly Channel<MediaLibraryScanJob> _channel = Channel.CreateUnbounded<MediaLibraryScanJob>();
|
||||
private readonly Channel<IMediaLibraryScanJob> _channel = Channel.CreateUnbounded<IMediaLibraryScanJob>(new UnboundedChannelOptions
|
||||
{
|
||||
SingleWriter = false,
|
||||
SingleReader = false,
|
||||
AllowSynchronousContinuations = true
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Gets the writer for the queue, allowing producers to enqueue <see cref="MediaLibraryScanJob"/> instances.
|
||||
/// Gets the writer for the queue, allowing producers to enqueue <see cref="IMediaLibraryScanJob"/> instances.
|
||||
/// </summary>
|
||||
public ChannelWriter<MediaLibraryScanJob> Writer
|
||||
{
|
||||
get { return _channel.Writer; }
|
||||
}
|
||||
public ChannelWriter<IMediaLibraryScanJob> Writer => _channel.Writer;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reader for the queue, allowing consumers to dequeue <see cref="MediaLibraryScanJob"/> instances.
|
||||
/// Gets the reader for the queue, allowing consumers to dequeue <see cref="IMediaLibraryScanJob"/> instances.
|
||||
/// </summary>
|
||||
public ChannelReader<MediaLibraryScanJob> Reader
|
||||
{
|
||||
get { return _channel.Reader; }
|
||||
}
|
||||
public ChannelReader<IMediaLibraryScanJob> Reader => _channel.Reader;
|
||||
}
|
||||
+9
-7
@@ -1,7 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Jobs.Common;
|
||||
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 Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -16,16 +17,17 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Queu
|
||||
internal sealed class MediaLibraryScanJobProcessorJob : BackgroundService
|
||||
{
|
||||
private readonly IMediaLibrariesScanQueue _mediaScanQueue;
|
||||
private readonly IMediaLibrariesScanTracker _librariesScanTracker;
|
||||
private readonly IMediaLibrariesScanCancellationTracker _mediaLibrariesScanCancellationTracker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaLibraryScanJobProcessorJob"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaScanQueue">Injected queue used for processing media libraries scan jobs.</param>
|
||||
public MediaLibraryScanJobProcessorJob(IMediaLibrariesScanQueue mediaScanQueue, IMediaLibrariesScanTracker librariesScanTracker)
|
||||
/// <param name="mediaLibrariesScanCancellationTracker">Injected service for scanning media libraries.</param>
|
||||
public MediaLibraryScanJobProcessorJob(IMediaLibrariesScanQueue mediaScanQueue, IMediaLibrariesScanCancellationTracker mediaLibrariesScanCancellationTracker)
|
||||
{
|
||||
_mediaScanQueue = mediaScanQueue;
|
||||
_librariesScanTracker = librariesScanTracker;
|
||||
_mediaLibrariesScanCancellationTracker = mediaLibrariesScanCancellationTracker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,10 +40,10 @@ internal sealed class MediaLibraryScanJobProcessorJob : BackgroundService
|
||||
// remark: since only top level scan jobs are placed on the bus, but they themselves trigger the execution of their children jobs, and so on,
|
||||
// their completion should not be awaited here due to some of them being long running tasks; therefor they are just fired synchronously
|
||||
// without being awaited, while still properly handling any exceptions they might throw in their asynchronous execution
|
||||
await foreach (MediaLibraryScanJob mediaScanJob in _mediaScanQueue.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false))
|
||||
await foreach (IMediaLibraryScanJob mediaScanJob in _mediaScanQueue.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
// get the cancellation token that was associated with this library scan
|
||||
CancellationToken scanToken = _librariesScanTracker.GetTokenForScan(mediaScanJob.ScanId, mediaScanJob.UserId);
|
||||
CancellationToken scanToken = _mediaLibrariesScanCancellationTracker.GetTokenForScan(mediaScanJob.ScanId.Value, mediaScanJob.UserId.Value);
|
||||
// create linked token to handle both scan cancellation and service shutdown
|
||||
CancellationTokenSource linkedSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, scanToken);
|
||||
mediaScanJob.ExecuteAsync(Guid.NewGuid(), new { }, linkedSource.Token).FireAndForgetSafeAsync(() => linkedSource.Dispose());
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Scanners.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.Management.Services.Scanning.Scanners.WrittenContent;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining a media library scanner for a books media library type.
|
||||
/// </summary>
|
||||
internal interface IBookLibraryTypeScanner : IMediaTypeScanner
|
||||
{
|
||||
}
|
||||
+2
-1
@@ -81,7 +81,8 @@ public class RegisterUserCommandHandler : IRequestHandler<RegisterUserCommand, E
|
||||
Libraries = [],
|
||||
UserPermissions = [],
|
||||
UserRole = null,
|
||||
CreatedBy = id
|
||||
CreatedBy = id,
|
||||
LibraryScans = [],
|
||||
};
|
||||
// if the user enabled two factor auth, include a QR with the totp secret
|
||||
if (request.Use2fa)
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateU
|
||||
/// <summary>
|
||||
/// Command for updating the authorization role and permissions of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user.</param>
|
||||
/// <param name="RoleId">The Id of the role.</param>
|
||||
/// <param name="UserId">The unique identifier of the user.</param>
|
||||
/// <param name="RoleId">The unique identifier of the role.</param>
|
||||
/// <param name="Permissions">The collection of Ids of the permissions of the user.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
public record UpdateUserRoleAndPermissionsCommand(
|
||||
|
||||
+2
-1
@@ -125,7 +125,8 @@ public class UpdateUserRoleAndPermissionsCommandHandler : IRequestHandler<Update
|
||||
PermissionId = permissionId,
|
||||
Permission = getPermissionsResult.Value.First(permission => permission.Id == permissionId),
|
||||
User = userToUpdate
|
||||
}).ToList()
|
||||
}).ToList(),
|
||||
LibraryScans = userToUpdate.LibraryScans
|
||||
};
|
||||
|
||||
// save changes and return result
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAutho
|
||||
/// <summary>
|
||||
/// Query for retrieving the authorization roles and permissions of an account.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom to get the authorization.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom to get the authorization.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
public record GetAuthorizationQuery(
|
||||
Guid? UserId
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserP
|
||||
/// <summary>
|
||||
/// Query for retrieving the authorization permissions of a user identified by <paramref name="UserId"/>.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom to get the authorization permissions.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom to get the authorization permissions.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
public record GetUserPermissionsQuery(
|
||||
Guid? UserId
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserR
|
||||
/// <summary>
|
||||
/// Query for retrieving the authorization role of a user identified by <paramref name="UserId"/>.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom to get the authorization role.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom to get the authorization role.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
public record GetUserRoleQuery(
|
||||
Guid? UserId
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Lumina.Contracts.DTO.Authentication;
|
||||
/// <summary>
|
||||
/// Data transfer object for an authorization permission.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the permission.</param>
|
||||
/// <param name="Id">The unique identifier of the permission.</param>
|
||||
/// <param name="PermissionName">The name of the permission.</param>
|
||||
[DebuggerDisplay("Id: {Id}, PermissionName: {PermissionName}")]
|
||||
public record PermissionDto(
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.DTO.Authentication;
|
||||
/// <summary>
|
||||
/// Data transfer object for an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the role.</param>
|
||||
/// <param name="Id">The unique identifier of the role.</param>
|
||||
/// <param name="RoleName">The name of the role.</param>
|
||||
[DebuggerDisplay("Id: {Id}, RoleName: {RoleName}")]
|
||||
public record RoleDto(
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Requests.Authorization;
|
||||
/// <summary>
|
||||
/// Represents a request for deleting an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="RoleId">The Id of the role. Required.</param>
|
||||
/// <param name="RoleId">The unique identifier of the role. Required.</param>
|
||||
[DebuggerDisplay("RoleId: {RoleId}")]
|
||||
public record DeleteRoleRequest(
|
||||
Guid? RoleId
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Lumina.Contracts.Requests.Authorization;
|
||||
/// <summary>
|
||||
/// Represents the request model for retrieving account authorization information.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom to get the authorization. Required.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom to get the authorization. Required.</param>
|
||||
public record GetAuthorizationRequest(
|
||||
Guid? UserId
|
||||
);
|
||||
@@ -7,7 +7,7 @@ namespace Lumina.Contracts.Requests.Authorization;
|
||||
/// <summary>
|
||||
/// Represents the request model for retrieving the authorization permissions of a user identified by <paramref name="UserId"/>.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom to get the authorization permissions. Required.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom to get the authorization permissions. Required.</param>
|
||||
public record GetUserPermissionsRequest(
|
||||
Guid? UserId
|
||||
);
|
||||
@@ -7,7 +7,7 @@ namespace Lumina.Contracts.Requests.Authorization;
|
||||
/// <summary>
|
||||
/// Represents the request model for retrieving the authorization role of a user identified by <paramref name="UserId"/>.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom to get the authorization role. Required.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom to get the authorization role. Required.</param>
|
||||
public record GetUserRoleRequest(
|
||||
Guid? UserId
|
||||
);
|
||||
@@ -9,7 +9,7 @@ namespace Lumina.Contracts.Requests.Authorization;
|
||||
/// <summary>
|
||||
/// Represents a request for updating an existing authorization role.
|
||||
/// </summary>
|
||||
/// <param name="RoleId">The Id of the role. Required.</param>
|
||||
/// <param name="RoleId">The unique identifier of the role. Required.</param>
|
||||
/// <param name="RoleName">The name of the role. Required.</param>
|
||||
/// <param name="Permissions">The collection of Ids of the permissions of the role. Required.</param>
|
||||
[DebuggerDisplay("RoleName: {RoleName}")]
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Lumina.Contracts.Requests.Authorization;
|
||||
/// <summary>
|
||||
/// Represents a request for updating the authorization role and permissions of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user. Required.</param>
|
||||
/// <param name="RoleId">The Id of the role. Optional.</param>
|
||||
/// <param name="UserId">The unique identifier of the user. Required.</param>
|
||||
/// <param name="RoleId">The unique identifier of the role. Optional.</param>
|
||||
/// <param name="Permissions">The collection of Ids of the permissions of the role. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
public record UpdateUserRoleAndPermissionsRequest(
|
||||
|
||||
@@ -6,10 +6,12 @@ using System.Diagnostics;
|
||||
namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to cancel the scan of a media library by its Id.
|
||||
/// Represents a request to cancel the scan of a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library whose scan is cancelled. Required.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose scan is cancelled. Required.</param>
|
||||
/// <param name="ScanId">The Id of scan to cancel. Required.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}; ScanId: {ScanId}")]
|
||||
public record CancelLibraryScanRequest(
|
||||
Guid Id
|
||||
Guid LibraryId,
|
||||
Guid ScanId
|
||||
);
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
/// <summary>
|
||||
/// Represents a request to delete a media library by its Id.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library to be deleted. Required.</param>
|
||||
/// <param name="Id">The unique identifier of the media library to be deleted. Required.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record DeleteLibraryRequest(
|
||||
Guid Id
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
/// <summary>
|
||||
/// Represents a request to get a media library by its Id.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library. Required.</param>
|
||||
/// <param name="Id">The unique identifier of the media library. Required.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record GetLibraryRequest(
|
||||
Guid Id
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
/// <summary>
|
||||
/// Represents a request to scan a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library to be scanned. Required.</param>
|
||||
/// <param name="Id">The unique identifier of the media library to be scanned. Required.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record ScanLibraryRequest(
|
||||
Guid Id
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
/// <summary>
|
||||
/// Represents a request to update a media library.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library. Required.</param>
|
||||
/// <param name="UserId">The Id of the user owning the media library. Required.</param>
|
||||
/// <param name="Id">The unique identifier of the media library. Required.</param>
|
||||
/// <param name="UserId">The unique identifier of the user owning the media library. Required.</param>
|
||||
/// <param name="Title">The title of the media library. Required.</param>
|
||||
/// <param name="LibraryType">The type of the media library. Required.</param>
|
||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located. Required.</param>
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibra
|
||||
/// <summary>
|
||||
/// Represents a request to get a book by the specified Id.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the book to retrieve.</param>
|
||||
/// <param name="Id">The unique identifier of the book to retrieve.</param>
|
||||
[DebuggerDisplay("Id: {Id}")]
|
||||
public record GetBookRequest(
|
||||
string? Id
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Responses.Authentication;
|
||||
/// <summary>
|
||||
/// Represents the response model for user authentication.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the user to authenticate.</param>
|
||||
/// <param name="Id">The unique identifier of the user to authenticate.</param>
|
||||
/// <param name="Username">The username of the user to authenticate.</param>
|
||||
/// <param name="Token">The authentication token used for subsequent requests.</param>
|
||||
/// <param name="UsesTotp">Whether the user uses 2FA authentication, or not.</param>
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Responses.Authentication;
|
||||
/// <summary>
|
||||
/// Represents the response model for user registration.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the user.</param>
|
||||
/// <param name="Id">The unique identifier of the user.</param>
|
||||
/// <param name="Username">The username of the user.</param>
|
||||
/// <param name="TotpSecret">The TOTP (Time-Based One-Time Password) secret used for two-factor authentication.</param>
|
||||
[DebuggerDisplay("Username: {Username}")]
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Lumina.Contracts.Responses.Authorization;
|
||||
/// <summary>
|
||||
/// Represents the response model for an account authorization request.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user for whom the authorization is retrieved.</param>
|
||||
/// <param name="UserId">The unique identifier of the user for whom the authorization is retrieved.</param>
|
||||
/// <param name="Role">The collection of roles associated to the user.</param>
|
||||
/// <param name="Permissions">The collection of permissions associated to the user.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Lumina.Contracts.Responses.Authorization;
|
||||
/// <summary>
|
||||
/// Represents the response model for a request for an of authorization permission.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the requested authorization permission.</param>
|
||||
/// <param name="Id">The unique identifier of the requested authorization permission.</param>
|
||||
/// <param name="PermissionName">The requested authorization permission.</param>
|
||||
public record PermissionResponse(
|
||||
Guid Id,
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Lumina.Contracts.Responses.Authorization;
|
||||
/// <summary>
|
||||
/// Represents the response model for a request for an authorization role.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the requested authorization role.</param>
|
||||
/// <param name="Id">The unique identifier of the requested authorization role.</param>
|
||||
/// <param name="RoleName">The requested authorization role.</param>
|
||||
public record RoleResponse(
|
||||
Guid Id,
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
/// <summary>
|
||||
/// Represents a media library response.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the media library.</param>
|
||||
/// <param name="UserId">The Id of the user owning the media library.</param>
|
||||
/// <param name="Id">The unique identifier of the media library.</param>
|
||||
/// <param name="UserId">The unique identifier of the user owning the media library.</param>
|
||||
/// <param name="Title">The title of the media library.</param>
|
||||
/// <param name="LibraryType">The type of the media library.</param>
|
||||
/// <param name="ContentLocations">The file system paths of the directories where the media library elements are located.</param>
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
/// <summary>
|
||||
/// Represents a media library scan response.
|
||||
/// </summary>
|
||||
/// <param name="ScanId">The Id of the media library scan.</param>
|
||||
/// <param name="LibraryId">The Id of the scanned media library.</param>
|
||||
/// <param name="ScanId">The unique identifier of the media library scan.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the scanned media library.</param>
|
||||
[DebuggerDisplay("ScanId: {ScanId} LibraryId: {LibraryId}")]
|
||||
public record ScanLibraryResponse(
|
||||
Guid ScanId,
|
||||
|
||||
@@ -202,6 +202,23 @@ public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
|
||||
.HasMaxLength(6)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
// audit
|
||||
builder.Property(permission => permission.CreatedOnUtc)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(32);
|
||||
|
||||
builder.Property(permission => permission.CreatedBy)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(33);
|
||||
|
||||
builder.Property(permission => permission.UpdatedOnUtc)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(34);
|
||||
|
||||
builder.Property(permission => permission.UpdatedBy)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(35);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,12 @@ public class LibraryConfiguration : IEntityTypeConfiguration<LibraryEntity>
|
||||
.HasForeignKey(library => library.UserId)
|
||||
.IsRequired();
|
||||
|
||||
// one library with many scans
|
||||
builder.HasMany(library => library.LibraryScans)
|
||||
.WithOne(libraryScan => libraryScan.Library)
|
||||
.HasForeignKey(libraryScan => libraryScan.LibraryId)
|
||||
.OnDelete(DeleteBehavior.Cascade); // deleting a library deletes library scans
|
||||
|
||||
// using OwnsMany because paths are domain Value Objects, thus they have no independent identity, and their lifecycle is bound to the Library
|
||||
builder.OwnsMany(library => library.ContentLocations, contentLocationBuilder =>
|
||||
{
|
||||
@@ -75,5 +81,22 @@ public class LibraryConfiguration : IEntityTypeConfiguration<LibraryEntity>
|
||||
.HasMaxLength(260)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
// audit
|
||||
builder.Property(permission => permission.CreatedOnUtc)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(8);
|
||||
|
||||
builder.Property(permission => permission.CreatedBy)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(9);
|
||||
|
||||
builder.Property(permission => permission.UpdatedOnUtc)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(10);
|
||||
|
||||
builder.Property(permission => permission.UpdatedBy)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(11);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the entity mapping for the <see cref="LibraryScanEntity"/> entity.
|
||||
/// </summary>
|
||||
public class LibraryScanConfiguration : IEntityTypeConfiguration<LibraryScanEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the <see cref="LibraryScanEntity"/> entity.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to be used to configure the entity.</param>
|
||||
public void Configure(EntityTypeBuilder<LibraryScanEntity> builder)
|
||||
{
|
||||
builder.ToTable("LibraryScans");
|
||||
builder.HasKey(library => library.Id);
|
||||
builder.Property(library => library.Id)
|
||||
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
|
||||
.HasColumnOrder(0);
|
||||
|
||||
// one user with many library scans
|
||||
builder.HasOne(libraryScan => libraryScan.User)
|
||||
.WithMany(user => user.LibraryScans)
|
||||
.HasForeignKey(libraryScan => libraryScan.UserId)
|
||||
.IsRequired();
|
||||
|
||||
// one library with many library scans
|
||||
builder.HasOne(libraryScan => libraryScan.Library)
|
||||
.WithMany(library => library.LibraryScans)
|
||||
.HasForeignKey(libraryScan => libraryScan.LibraryId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(libraryScan => libraryScan.Status)
|
||||
.IsRequired()
|
||||
.HasConversion<string>()
|
||||
.HasColumnOrder(1);
|
||||
|
||||
// audit
|
||||
builder.Property(permission => permission.CreatedOnUtc)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(2);
|
||||
|
||||
builder.Property(permission => permission.CreatedBy)
|
||||
.IsRequired()
|
||||
.HasColumnOrder(3);
|
||||
|
||||
builder.Property(permission => permission.UpdatedOnUtc)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(4);
|
||||
|
||||
builder.Property(permission => permission.UpdatedBy)
|
||||
.HasDefaultValue(null)
|
||||
.HasColumnOrder(5);
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public sealed class UpdateAuditableEntitiesInterceptor : SaveChangesInterceptor
|
||||
/// Sets the creation audit properties for a newly added entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity being created.</param>
|
||||
/// <param name="userId">The Id of the user creating the entity.</param>
|
||||
/// <param name="userId">The unique identifier of the user creating the entity.</param>
|
||||
/// <param name="utcNow">The current UTC timestamp.</param>
|
||||
private static void SetCreationProperties(IAuditableEntity entity, Guid? userId, DateTime utcNow)
|
||||
{
|
||||
@@ -96,7 +96,7 @@ public sealed class UpdateAuditableEntitiesInterceptor : SaveChangesInterceptor
|
||||
/// Sets the modification audit properties for an updated entity while protecting creation properties.
|
||||
/// </summary>
|
||||
/// <param name="entry">The entity entry being modified.</param>
|
||||
/// <param name="userId">The Id of the user modifying the entity.</param>
|
||||
/// <param name="userId">The unique identifier of the user modifying the entity.</param>
|
||||
/// <param name="utcNow">The current UTC timestamp.</param>
|
||||
private static void SetModificationProperties(EntityEntry<IAuditableEntity> entry, Guid? userId, DateTime utcNow)
|
||||
{
|
||||
|
||||
Generated
+808
@@ -0,0 +1,808 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
[DbContext(typeof(LuminaDbContext))]
|
||||
[Migration("20250215190409_AddsMediaLibraryScanTable")]
|
||||
partial class AddsMediaLibraryScanTable
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.0");
|
||||
|
||||
modelBuilder.Entity("BookGenres", b =>
|
||||
{
|
||||
b.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GenreId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("BookId", "GenreId");
|
||||
|
||||
b.HasIndex("GenreId");
|
||||
|
||||
b.ToTable("BookGenres", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookTags", b =>
|
||||
{
|
||||
b.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("BookId", "TagId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("BookTags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<string>("PermissionName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Permissions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<string>("RoleName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Roles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("PermissionId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.HasKey("RoleId", "PermissionId");
|
||||
|
||||
b.HasIndex("PermissionId");
|
||||
|
||||
b.HasIndex("RoleId", "PermissionId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("RolePermissions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("PermissionId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.HasKey("UserId", "PermissionId");
|
||||
|
||||
b.HasIndex("PermissionId");
|
||||
|
||||
b.HasIndex("UserId", "PermissionId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("UserPermissions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid>("RoleId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.HasKey("UserId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.HasIndex("UserId", "RoleId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("UserRoles", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Genres", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Tags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<string>("CoverImage")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(9);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(8);
|
||||
|
||||
b.Property<bool>("DownloadMedatadaFromWeb")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(true)
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(true)
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<bool>("IsLocked")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<string>("LibraryType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<bool>("SaveMetadataInMediaDirectories")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(7);
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(11);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(10);
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Libraries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<Guid>("LibraryId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LibraryId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("LibraryScans", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<string>("ASIN")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(21);
|
||||
|
||||
b.Property<string>("AppleBooksId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(29);
|
||||
|
||||
b.Property<string>("BarnesAndNobleId")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(28);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(33);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(32);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<string>("Edition")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(19);
|
||||
|
||||
b.Property<string>("Format")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(18);
|
||||
|
||||
b.Property<string>("GoodreadsId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(22);
|
||||
|
||||
b.Property<string>("GoogleBooksId")
|
||||
.HasMaxLength(12)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(27);
|
||||
|
||||
b.Property<string>("LCCN")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(23);
|
||||
|
||||
b.Property<string>("LanguageCode")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(10);
|
||||
|
||||
b.Property<string>("LanguageName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(11);
|
||||
|
||||
b.Property<string>("LanguageNativeName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(12);
|
||||
|
||||
b.Property<string>("LibraryThingId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(26);
|
||||
|
||||
b.Property<string>("OCLCNumber")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(24);
|
||||
|
||||
b.Property<string>("OpenLibraryId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(25);
|
||||
|
||||
b.Property<string>("OriginalLanguageCode")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(13);
|
||||
|
||||
b.Property<string>("OriginalLanguageName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(14);
|
||||
|
||||
b.Property<string>("OriginalLanguageNativeName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(15);
|
||||
|
||||
b.Property<DateOnly?>("OriginalReleaseDate")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<int?>("OriginalReleaseYear")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<string>("OriginalTitle")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<int?>("PageCount")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(17);
|
||||
|
||||
b.Property<string>("Publisher")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(16);
|
||||
|
||||
b.Property<DateOnly?>("ReReleaseDate")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<int?>("ReReleaseYear")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(7);
|
||||
|
||||
b.Property<string>("ReleaseCountry")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(8);
|
||||
|
||||
b.Property<string>("ReleaseVersion")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(9);
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(35);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(34);
|
||||
|
||||
b.Property<int?>("VolumeNumber")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(20);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(7);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<string>("TempPassword")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<DateTime?>("TempPasswordCreated")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<string>("TotpSecret")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(9);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(8);
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookGenres", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.GenreEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("GenreId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookTags", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.Common.TagEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RolePermissionEntity", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission")
|
||||
.WithMany("RolePermissions")
|
||||
.HasForeignKey("PermissionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role")
|
||||
.WithMany("RolePermissions")
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Permission");
|
||||
|
||||
b.Navigation("Role");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserPermissionEntity", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", "Permission")
|
||||
.WithMany("UserPermissions")
|
||||
.HasForeignKey("PermissionId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
|
||||
.WithMany("UserPermissions")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Permission");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", "Role")
|
||||
.WithMany("UserRoles")
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
|
||||
.WithOne("UserRole")
|
||||
.HasForeignKey("Lumina.Application.Common.DataAccess.Entities.Authorization.UserRoleEntity", "UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Role");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
|
||||
.WithMany("Libraries")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryContentLocationEntity", "ContentLocations", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<Guid>("LibraryId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Path")
|
||||
.IsRequired()
|
||||
.HasMaxLength(260)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("Path");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("LibraryId");
|
||||
|
||||
b1.ToTable("LibraryContentLocations", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("LibraryId");
|
||||
});
|
||||
|
||||
b.Navigation("ContentLocations");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library")
|
||||
.WithMany("LibraryScans")
|
||||
.HasForeignKey("LibraryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
|
||||
.WithMany("LibraryScans")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Library");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
|
||||
{
|
||||
b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<decimal>("MaxValue")
|
||||
.HasColumnType("decimal(3,2)");
|
||||
|
||||
b1.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasColumnType("decimal(3,2)");
|
||||
|
||||
b1.Property<int?>("VoteCount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("BookId");
|
||||
|
||||
b1.ToTable("BookRatings", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
});
|
||||
|
||||
b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.IsbnEntity", "ISBNs", b1 =>
|
||||
{
|
||||
b1.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Format")
|
||||
.IsRequired()
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(13)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("ISBN");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("BookId");
|
||||
|
||||
b1.ToTable("BookISBNs", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
});
|
||||
|
||||
b.Navigation("ISBNs");
|
||||
|
||||
b.Navigation("Ratings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.PermissionEntity", b =>
|
||||
{
|
||||
b.Navigation("RolePermissions");
|
||||
|
||||
b.Navigation("UserPermissions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.Authorization.RoleEntity", b =>
|
||||
{
|
||||
b.Navigation("RolePermissions");
|
||||
|
||||
b.Navigation("UserRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
|
||||
{
|
||||
b.Navigation("LibraryScans");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b =>
|
||||
{
|
||||
b.Navigation("Libraries");
|
||||
|
||||
b.Navigation("LibraryScans");
|
||||
|
||||
b.Navigation("UserPermissions");
|
||||
|
||||
b.Navigation("UserRole");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations;
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class AddsMediaLibraryScanTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedOnUtc",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 10);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "UpdatedBy",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 11);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "CreatedOnUtc",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 8);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CreatedBy",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 9);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedOnUtc",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 34)
|
||||
.OldAnnotation("Relational:ColumnOrder", 31);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "UpdatedBy",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 35);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "CreatedOnUtc",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 32)
|
||||
.OldAnnotation("Relational:ColumnOrder", 30);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CreatedBy",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 33);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "LibraryScans",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Status = table.Column<string>(type: "TEXT", nullable: false),
|
||||
CreatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
CreatedBy = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UpdatedOnUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
|
||||
UpdatedBy = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||
LibraryId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
UserId = table.Column<Guid>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_LibraryScans", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_LibraryScans_Libraries_LibraryId",
|
||||
column: x => x.LibraryId,
|
||||
principalTable: "Libraries",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_LibraryScans_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_LibraryScans_LibraryId",
|
||||
table: "LibraryScans",
|
||||
column: "LibraryId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_LibraryScans_UserId",
|
||||
table: "LibraryScans",
|
||||
column: "UserId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "LibraryScans");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedOnUtc",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.OldAnnotation("Relational:ColumnOrder", 10);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "UpdatedBy",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.OldAnnotation("Relational:ColumnOrder", 11);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "CreatedOnUtc",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT")
|
||||
.OldAnnotation("Relational:ColumnOrder", 8);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CreatedBy",
|
||||
table: "Libraries",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT")
|
||||
.OldAnnotation("Relational:ColumnOrder", 9);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedOnUtc",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 31)
|
||||
.OldAnnotation("Relational:ColumnOrder", 34);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "UpdatedBy",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: true,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT",
|
||||
oldNullable: true)
|
||||
.OldAnnotation("Relational:ColumnOrder", 35);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "CreatedOnUtc",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "TEXT")
|
||||
.Annotation("Relational:ColumnOrder", 30)
|
||||
.OldAnnotation("Relational:ColumnOrder", 32);
|
||||
|
||||
migrationBuilder.AlterColumn<Guid>(
|
||||
name: "CreatedBy",
|
||||
table: "Books",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
oldClrType: typeof(Guid),
|
||||
oldType: "TEXT")
|
||||
.OldAnnotation("Relational:ColumnOrder", 33);
|
||||
}
|
||||
}
|
||||
@@ -251,10 +251,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(9);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(8);
|
||||
|
||||
b.Property<bool>("DownloadMedatadaFromWeb")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -288,10 +290,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(11);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(10);
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
@@ -303,6 +307,48 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
b.ToTable("Libraries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<Guid>("LibraryId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LibraryId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("LibraryScans", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
@@ -324,11 +370,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnOrder(28);
|
||||
|
||||
b.Property<Guid>("CreatedBy")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(33);
|
||||
|
||||
b.Property<DateTime>("CreatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(30);
|
||||
.HasColumnOrder(32);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
@@ -440,11 +487,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<Guid?>("UpdatedBy")
|
||||
.HasColumnType("TEXT");
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(35);
|
||||
|
||||
b.Property<DateTime?>("UpdatedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(31);
|
||||
.HasColumnOrder(34);
|
||||
|
||||
b.Property<int?>("VolumeNumber")
|
||||
.HasColumnType("INTEGER")
|
||||
@@ -633,6 +681,25 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryScanEntity", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", "Library")
|
||||
.WithMany("LibraryScans")
|
||||
.HasForeignKey("LibraryId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", "User")
|
||||
.WithMany("LibraryScans")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Library");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookEntity", b =>
|
||||
{
|
||||
b.OwnsMany("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary.BookRatingEntity", "Ratings", b1 =>
|
||||
@@ -717,10 +784,17 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
b.Navigation("UserRoles");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management.LibraryEntity", b =>
|
||||
{
|
||||
b.Navigation("LibraryScans");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.DataAccess.Entities.UsersManagement.UserEntity", b =>
|
||||
{
|
||||
b.Navigation("Libraries");
|
||||
|
||||
b.Navigation("LibraryScans");
|
||||
|
||||
b.Navigation("UserPermissions");
|
||||
|
||||
b.Navigation("UserRole");
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.Repositories.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Repository for media library scans.
|
||||
/// </summary>
|
||||
internal sealed class LibraryScanRepository : ILibraryScanRepository
|
||||
{
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryScanRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
public LibraryScanRepository(LuminaDbContext luminaDbContext)
|
||||
{
|
||||
_luminaDbContext = luminaDbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new library scan.
|
||||
/// </summary>
|
||||
/// <param name="libraryScan">The library scan to add.</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>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(LibraryScanEntity libraryScan, CancellationToken cancellationToken)
|
||||
{
|
||||
bool libraryScanExists = await _luminaDbContext.LibraryScans.AnyAsync(
|
||||
repositoryScanLibrary => repositoryScanLibrary.Id == libraryScan.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (libraryScanExists)
|
||||
return Errors.LibraryScanning.LibraryScanAlreadyExists;
|
||||
|
||||
_luminaDbContext.LibraryScans.Add(libraryScan);
|
||||
return Result.Created;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="LibraryScanEntity"/> identified by <paramref name="id"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the library scan 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="LibraryScanEntity"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<LibraryScanEntity?>> GetByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScans
|
||||
.Include(libraryScan => libraryScan.Library)
|
||||
.Include(libraryScan => libraryScan.User)
|
||||
.FirstOrDefaultAsync(libraryScan => libraryScan.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryScanEntity>>> GetPastMonthScansByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScans
|
||||
.Include(library => library.Library)
|
||||
.Where(library => library.LibraryId == libraryId && library.CreatedOnUtc >= DateTime.UtcNow.AddMonths(-1))
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media library scans that 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>
|
||||
public async Task<ErrorOr<IEnumerable<LibraryScanEntity>>> GetRunningScansAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.LibraryScans
|
||||
.Include(library => library.Library)
|
||||
.Where(library => library.Status == LibraryScanJobStatus.Running)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a media library scan.
|
||||
/// </summary>
|
||||
/// <param name="data">The media library scan to update.</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>
|
||||
public async Task<ErrorOr<Updated>> UpdateAsync(LibraryScanEntity data, CancellationToken cancellationToken)
|
||||
{
|
||||
LibraryScanEntity? foundLibraryScan = await _luminaDbContext.LibraryScans
|
||||
.Include(libraryScan => libraryScan.Library)
|
||||
.FirstOrDefaultAsync(libraryScan => libraryScan.Id == data.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (foundLibraryScan is null)
|
||||
return Errors.LibraryScanning.LibraryScanNotFound;
|
||||
// update scalar properties
|
||||
_luminaDbContext.Entry(foundLibraryScan).CurrentValues.SetValues(data);
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class DataSeedService : 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>
|
||||
public async Task<ErrorOr<Created>> SetDefaultAuthorizationPermissionsAsync(Guid adminId, CancellationToken cancellationToken)
|
||||
@@ -66,7 +66,7 @@ public class DataSeedService : 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>
|
||||
public async Task<ErrorOr<Created>> SetDefaultAuthorizationRolesAsync(Guid userId, CancellationToken cancellationToken)
|
||||
@@ -91,7 +91,7 @@ public class DataSeedService : 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>
|
||||
public async Task<ErrorOr<Created>> SetAdminRolePermissionsAsync(Guid userId, CancellationToken cancellationToken)
|
||||
@@ -136,7 +136,7 @@ public class DataSeedService : 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>
|
||||
public async Task<ErrorOr<Created>> SetAdminRoleToAdministratorAccount(Guid userId, CancellationToken cancellationToken)
|
||||
|
||||
@@ -18,6 +18,7 @@ public class LuminaDbContext : DbContext
|
||||
public virtual DbSet<BookEntity> Books { get; set; } = null!;
|
||||
public virtual DbSet<UserEntity> Users { get; set; } = null!;
|
||||
public virtual DbSet<LibraryEntity> Libraries { get; set; } = null!;
|
||||
public virtual DbSet<LibraryScanEntity> LibraryScans { get; set; } = null!;
|
||||
public virtual DbSet<RoleEntity> Roles { get; set; } = null!;
|
||||
public virtual DbSet<UserRoleEntity> UserRoles { get; set; } = null!;
|
||||
public virtual DbSet<PermissionEntity> Permissions { get; set; } = null!;
|
||||
|
||||
@@ -3,6 +3,10 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Abstractions;
|
||||
@@ -41,6 +45,10 @@ public static class DomainLayerServices
|
||||
services.AddScoped<IWindowsPathStrategy, WindowsPathStrategy>();
|
||||
services.AddScoped<IOperatingSystemInfo, OperatingSystemInfo>();
|
||||
services.AddScoped<IFileSystemStructureSeedService, FileSystemStructureSeedService>();
|
||||
services.AddScoped<IMediaLibraryScanJobFactory, MediaLibraryScanJobFactory>();
|
||||
services.AddScoped<IMediaLibraryScanningService, MediaLibraryScanningService>();
|
||||
services.AddScoped<IBookLibraryTypeScanner, BookLibraryTypeScanner>();
|
||||
services.AddScoped<IMediaLibraryScannerFactory, MediaLibraryScannerFactory>();
|
||||
services.AddSingleton<IFileSystem, FileSystem>();
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ public enum LibraryScanJobStatus
|
||||
Completed,
|
||||
|
||||
/// <summary>
|
||||
/// Job has been cancelled.
|
||||
/// Job has been canceled.
|
||||
/// </summary>
|
||||
Cancelled,
|
||||
Canceled,
|
||||
|
||||
/// <summary>
|
||||
/// Job has failed.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Media Library Scan error types.
|
||||
/// </summary>
|
||||
public static partial class Errors
|
||||
{
|
||||
public static class LibraryScanning
|
||||
{
|
||||
public static Error CanOnlyStartPendingScans => Error.Forbidden(description: nameof(CanOnlyStartPendingScans));
|
||||
public static Error CanOnlyCancelRunningScans => Error.Forbidden(description: nameof(CanOnlyCancelRunningScans));
|
||||
public static Error CanOnlyFailRunningScans => Error.Forbidden(description: nameof(CanOnlyFailRunningScans));
|
||||
public static Error ScanIdCannotBeEmpty => Error.Validation(description: nameof(ScanIdCannotBeEmpty));
|
||||
public static Error LibraryScanAlreadyExists => Error.Conflict(description: nameof(LibraryScanAlreadyExists));
|
||||
public static Error LibraryAlreadyBeingScanned => Error.Forbidden(description: nameof(LibraryAlreadyBeingScanned));
|
||||
public static Error LibraryScanNotFound => Error.NotFound(description: nameof(LibraryScanNotFound));
|
||||
public static Error TotalScanJobItemsCountMustBePositive => Error.Validation(description: nameof(TotalScanJobItemsCountMustBePositive));
|
||||
public static Error CompletedScanJobItemsCountMustBePositive => Error.Validation(description: nameof(CompletedScanJobItemsCountMustBePositive));
|
||||
public static Error CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount => Error.Validation(description: nameof(CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount));
|
||||
public static Error ScanJobCurrentOperationCannotBeEmpty => Error.Validation(description: nameof(ScanJobCurrentOperationCannotBeEmpty));
|
||||
}
|
||||
}
|
||||
Loaded 100 of 209 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user