#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBookCover;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
///
/// Extension methods for converting .
///
public static class UpdateBookCoverCommandMapping
{
///
/// Converts to the cover artwork of the book identified by , replacing the
/// file of when the book already has a cover, or creating a new cover artwork when it does not.
///
/// The command whose cover image was stored.
/// The existing cover artwork of the book, or when the book has none.
/// The Id of the book the cover belongs to.
/// The relative path of the stored cover image.
/// The Id of the user that stored the cover image.
/// The cover artwork of the book, carrying the stored cover image.
public static BookArtworkEntity ToRepositoryEntity(this UpdateBookCoverCommand command, BookArtworkEntity? existingCover, Guid bookId, string storedCoverPath, Guid userId)
{
if (existingCover is null)
{
return new BookArtworkEntity
{
Id = Guid.NewGuid(),
BookId = bookId,
ArtworkType = ArtworkType.Cover,
Ordinal = 0,
FileName = storedCoverPath,
Status = ArtworkStatus.Enriched,
CreatedOnUtc = DateTime.UtcNow,
CreatedBy = userId,
UpdatedBy = null
};
}
existingCover.FileName = storedCoverPath;
existingCover.Status = ArtworkStatus.Enriched;
existingCover.LastUpdateUtc = DateTime.UtcNow;
existingCover.UpdatedOnUtc = DateTime.UtcNow;
existingCover.UpdatedBy = userId;
return existingCover;
}
}