Adds library saved domnain event and its handler

This commit is contained in:
BinaryAlley committed 2025-01-09 18:47:47 +02:00
1 parent 846edac83f
commit 104106d2ec
26 files changed
+475 -28

No files matched your search

@@ -15,6 +15,7 @@ public static partial class Errors
public static Error LibraryAlreadyExists => Error.Conflict(description: nameof(LibraryAlreadyExists));
public static Error LibraryNotFound => Error.NotFound(description: nameof(LibraryNotFound));
public static Error LibraryTypeCannotBeNull => Error.Validation(description: nameof(LibraryTypeCannotBeNull));
public static Error CoverFileMustBeAnImage => Error.Validation(description: nameof(CoverFileMustBeAnImage));
public static Error UnknownLibraryType => Error.Unexpected(description: nameof(UnknownLibraryType));
public static Error PathsListCannotBeNull => Error.Validation(description: nameof(PathsListCannotBeNull));
public static Error PathsListCannotBeEmpty => Error.Validation(description: nameof(PathsListCannotBeEmpty));
@@ -26,7 +26,7 @@ public class ThumbnailService : IThumbnailService
/// <summary>
/// Initializes a new instance of the <see cref="ThumbnailService"/> class.
/// </summary>
/// <param name="environmentContext">Injected environment context.</param>
/// <param name="environmentContext">Injected facade service for environment contextual services.</param>
public ThumbnailService(IEnvironmentContext environmentContext)
{
_environmentContext = environmentContext;
@@ -0,0 +1,20 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Events;
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
/// <summary>
/// Domain event raised when a libary is created or updated.
/// </summary>
/// <param name="Id">The Id of the domain event.</param>
/// <param name="Library">The library that was created or updated.</param>
/// <param name="OccurredOnUtc">The date and time when the domain event occurred.</param>
[DebuggerDisplay("Id: {Library.Id} Title: {Library.Title}")]
public record LibrarySavedDomainEvent(
Guid Id,
Library Library,
DateTime OccurredOnUtc
) : IDomainEvent;
@@ -3,6 +3,7 @@ using ErrorOr;
using Lumina.Domain.Common.Enums.MediaLibrary;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System;
@@ -40,6 +41,11 @@ public class Library : AggregateRoot<LibraryId>
/// </summary>
public string? CoverImage { get; private set; }
/// <summary>
/// Gets the path of the image file chosen by the user to be used as the cover for the library.
/// </summary>
public string? CoverImageSourcePath { get; private set; }
/// <summary>
/// Gets the list of file system paths that make up the media library.
/// </summary>
@@ -67,6 +73,8 @@ public class Library : AggregateRoot<LibraryId>
LibraryType = libraryType;
_contentLocations = contentLocations;
CoverImage = coverImage;
_domainEvents.Add(new LibrarySavedDomainEvent(Guid.NewGuid(), this, DateTime.UtcNow));
}
/// <summary>
@@ -76,7 +84,7 @@ public class Library : AggregateRoot<LibraryId>
/// <param name="title">The title of the media library.</param>
/// <param name="libraryType">The type of the media library (e.g., Book, TvShow).</param>
/// <param name="contentLocations">The list of file system paths that make up the media library.</param>
/// <param name="coverImage">The path of the image file used as the cover for the library.</param>
/// <param name="coverImageSourcePath">The path of the image file chosen by the user to be used as the cover for the library.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Library"/>, or an error message.
/// </returns>
@@ -85,7 +93,7 @@ public class Library : AggregateRoot<LibraryId>
string title,
LibraryType libraryType,
IEnumerable<string> contentLocations,
string? coverImage)
string? coverImageSourcePath)
{
List<FileSystemPathId> tempContentLocations = [];
// go through all the file system paths that make up the media library and create domain objects from them
@@ -102,7 +110,7 @@ public class Library : AggregateRoot<LibraryId>
title,
libraryType,
tempContentLocations,
coverImage
coverImageSourcePath
);
}
@@ -114,7 +122,7 @@ public class Library : AggregateRoot<LibraryId>
/// <param name="title">The title of the media library.</param>
/// <param name="libraryType">The type of the media library (e.g., Book, TvShow).</param>
/// <param name="contentLocations">The list of file system paths that make up the media library.</param>
/// <param name="coverImage">The path of the image file used as the cover for the library.</param>
/// <param name="coverImageSourcePath">The path of the image file chosen by the user to be used as the cover for the library.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Library"/>, or an error message.
/// </returns>
@@ -124,7 +132,7 @@ public class Library : AggregateRoot<LibraryId>
string title,
LibraryType libraryType,
IEnumerable<string> contentLocations,
string? coverImage)
string? coverImageSourcePath)
{
List<FileSystemPathId> tempContentLocations = [];
// go through all the file system paths that make up the media library and create domain objects from them
@@ -141,7 +149,16 @@ public class Library : AggregateRoot<LibraryId>
title,
libraryType,
tempContentLocations,
coverImage
coverImageSourcePath
);
}
/// <summary>
/// Sets the file system path where the cover image was copied to from where it was located when the user selected it, to the internal library.
/// </summary>
/// <param name="path">The internal libray path location of the cover image file.</param>
public void SetInternalLibraryCoverImagePath(string path)
{
CoverImage = path;
}
}