A lot of changes
This commit is contained in:
@@ -10,9 +10,8 @@ using Musify.Domain.Entities;
|
||||
|
||||
namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
{
|
||||
public class CreatePlayListCommandHandler(IEventBus eventBus, IDatabase database, IStorageHandler storageHandler,
|
||||
ILogger<CreatePlayListCommandHandler> logger, ApplicationStorageConfiguration storageConfiguration,
|
||||
PlayListConfiguration playListConfiguration, IPictureHandler pictureHandler)
|
||||
public class CreatePlayListCommandHandler(IEventBus eventBus, IDatabase database, IStorageHandler storageHandler, IPictureHandler pictureHandler,
|
||||
ILogger<CreatePlayListCommandHandler> logger, ApplicationStorageConfiguration storageConfiguration, PlayListConfiguration playListConfiguration)
|
||||
: IRequestHandler<CreatePlayListCommand, Task<Result<PlayListResponse>> >
|
||||
{
|
||||
public async Task<Result<PlayListResponse>> Handle(CreatePlayListCommand request, CancellationToken cancellationToken)
|
||||
@@ -55,8 +54,6 @@ namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
playList.Id, string.Join("; ", uploadResult.Errors));
|
||||
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
||||
}
|
||||
|
||||
playList.OriginalPictureKeyName = pictureName;
|
||||
logger.LogInformation("Playlist image uploaded successfully for PlayList with Id={PlayListId}.", playList.Id);
|
||||
|
||||
var smallPictureKeyName = Path.Combine(
|
||||
|
||||
@@ -27,36 +27,28 @@ namespace Musify.Application.PlayLists.Commands.DeletePlayList
|
||||
return Result.Unauthorized();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
||||
var keysToRemove = new List<string>();
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
{
|
||||
var keysToRemove = new List<string>
|
||||
{
|
||||
Path.Join(playListConfiguration.Routes.OriginalPictures, playList.OriginalPictureKeyName)
|
||||
};
|
||||
keysToRemove.Add(playList.SmallPictureKeyName);
|
||||
}
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
{
|
||||
keysToRemove.Add(playList.MediumPictureKeyName);
|
||||
}
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
{
|
||||
keysToRemove.Add(playList.LargePictureKeyName);
|
||||
}
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
{
|
||||
keysToRemove.Add(playList.SmallPictureKeyName);
|
||||
}
|
||||
foreach (var key in keysToRemove)
|
||||
{
|
||||
var publishResult = await TryPublishRemoveFileEventAsync(playList.Id, key, cancellationToken);
|
||||
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
if (!publishResult.IsSuccess)
|
||||
{
|
||||
keysToRemove.Add(playList.MediumPictureKeyName);
|
||||
}
|
||||
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
{
|
||||
keysToRemove.Add(playList.LargePictureKeyName);
|
||||
}
|
||||
|
||||
foreach (var key in keysToRemove)
|
||||
{
|
||||
var publishResult = await TryPublishRemoveFileEventAsync(playList.Id, key, cancellationToken);
|
||||
|
||||
if (!publishResult.IsSuccess)
|
||||
{
|
||||
return publishResult;
|
||||
}
|
||||
return publishResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,68 +47,46 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
return Result.Success(PlayListResponse.FromEntity(playList));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
{
|
||||
var originalImageStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, playList.OriginalPictureKeyName);
|
||||
|
||||
try
|
||||
{
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
originalImageStorageKey), cancellationToken);
|
||||
storageConfiguration.BucketName,
|
||||
playList.SmallPictureKeyName), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for original picture of PlayList id={PlayListId}.", playList.Id);
|
||||
logger.LogError(exception, "Failed to publish remove file event for small picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
|
||||
logger.LogInformation("Published event to remove old picture with key name {KeyName} from bucket {BucketName}",
|
||||
originalImageStorageKey, storageConfiguration.BucketName);
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
}
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.SmallPictureKeyName), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for small picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.MediumPictureKeyName), cancellationToken);
|
||||
}
|
||||
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
catch (Exception exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.MediumPictureKeyName), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for medium picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
logger.LogError(exception, "Failed to publish remove file event for medium picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
}
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.LargePictureKeyName), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for large picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
await eventBus.PublishAsync(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.LargePictureKeyName), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for large picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +108,6 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
||||
}
|
||||
|
||||
playList.OriginalPictureKeyName = pictureName;
|
||||
|
||||
var smallPictureKeyName = Path.Combine(
|
||||
playListConfiguration.Routes.SmallPictures,
|
||||
$"{playList.Id}.{pictureHandler.FileExtension}");
|
||||
|
||||
Reference in New Issue
Block a user