Renames and changes

This commit is contained in:
2026-03-28 15:32:36 +01:00
parent d2a1807883
commit 06ef70cb3b
28 changed files with 236 additions and 241 deletions
@@ -4,19 +4,19 @@ namespace Musify.Application.Contracts.Infrastructure
{
public interface IStorageHandler
{
Task<Result<Stream>> GetFileAsync(string bucketName, string keyName, CancellationToken cancellationToken);
Task<Result<Stream>> GetFileAsync(string bucket, string key, CancellationToken cancellationToken);
Task<string> GetUrlAsync(string bucketName, string keyName, TimeSpan ExpirationTime, CancellationToken cancellationToken);
Task<string> GetUrlAsync(string bucket, string key, TimeSpan ExpirationTime, CancellationToken cancellationToken);
Task<Result<string>> UploadFileAsync(string filePath, string bucketName, string keyName, CancellationToken cancellationToken);
Task<Result<string>> UploadFileAsync(string filePath, string bucket, string key, CancellationToken cancellationToken);
Task<Result<string>> UploadFileAsync(Stream sourceStream, string contentType, string bucketName, string keyName, CancellationToken cancellationToken);
Task<Result<string>> UploadFileAsync(Stream sourceStream, string contentType, string bucket, string key, CancellationToken cancellationToken);
Task<Result> TransferFilesAsync(string sourceDirectory, string bucketName, string route, CancellationToken cancellationToken);
Task<Result> TransferFilesAsync(string sourceDirectory, string bucket, string route, CancellationToken cancellationToken);
Task<Result> RemoveFileAsync(string bucketName, string keyName, CancellationToken cancellationToken);
Task<Result> RemoveFileAsync(string bucket, string key, CancellationToken cancellationToken);
Task<Result> CopyFileAsync(string sourceBucketName, string sourceKeyName, string destinationBucketName, string destinationKeyName,
Task<Result> CopyFileAsync(string sourceBucket, string sourceKey, string destinationBucket, string destinationKey,
CancellationToken cancellationToken);
}
}
@@ -32,10 +32,10 @@ namespace Musify.Application.PlayLists.Handlers
Name = request.Name,
NormalizedName = request.Name.Trim().ToUpperInvariant(),
Description = request.Description,
OriginalPictureKeyName = playListConfiguration.Routes.PresetOriginalPicture,
SmallPictureKeyName = playListConfiguration.Routes.PresetSmallPicture,
MediumPictureKeyName = playListConfiguration.Routes.PresetMediumPicture,
LargePictureKeyName = playListConfiguration.Routes.PresetLargePicture,
OriginalPictureName = playListConfiguration.Routes.PresetOriginalPicture,
SmallPictureName = playListConfiguration.Routes.PresetSmallPicture,
MediumPictureName = playListConfiguration.Routes.PresetMediumPicture,
LargePictureName = playListConfiguration.Routes.PresetLargePicture,
};
var setPictureResult = request.Picture is null
@@ -63,12 +63,12 @@ namespace Musify.Application.PlayLists.Handlers
if (!uploadResult.IsSuccess)
{
logger.LogError("Failed to upload picture for PlayList with Id={PlayListId} to storage. Storage handler returned error: {ErrorMessage}",
logger.LogError("Failed to upload picture for PlayList with Id={PlayListId} to storage. Storage handler returned error={ErrorMessage}",
playList.Id, string.Join("; ", uploadResult.Errors));
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
}
playList.OriginalPictureKeyName = pictureName;
playList.OriginalPictureName = pictureName;
logger.LogInformation("Playlist image uploaded successfully for PlayList with Id={PlayListId}.", playList.Id);
try
@@ -30,15 +30,15 @@ namespace Musify.Application.PlayLists.Handlers
var keysToRemove = new List<string>();
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
if (playList.SmallPictureName != playListConfiguration.Routes.PresetSmallPicture)
keysToRemove.Add(Path.Combine(playListConfiguration.Routes.SmallPicturesPath,
playList.SmallPictureKeyName));
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
playList.SmallPictureName));
if (playList.MediumPictureName != playListConfiguration.Routes.PresetMediumPicture)
keysToRemove.Add(Path.Combine(playListConfiguration.Routes.MediumPicturesPath,
playList.MediumPictureKeyName));
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
playList.MediumPictureName));
if (playList.LargePictureName != playListConfiguration.Routes.PresetLargePicture)
keysToRemove.Add(Path.Combine(playListConfiguration.Routes.LargePicturesPath,
playList.LargePictureKeyName));
playList.LargePictureName));
foreach (var key in keysToRemove)
{
@@ -48,7 +48,7 @@ namespace Musify.Application.PlayLists.Handlers
{
if (publishResult.IsNotFound())
{
logger.LogWarning("File with key={KeyName} not found in storage while trying to publish remove file event for PlayList with id={PlayListId}.", key, playList.Id);
logger.LogWarning("File with key={Key} not found in storage while trying to publish remove file event for PlayList with id={PlayListId}.", key, playList.Id);
continue;
}
@@ -62,19 +62,19 @@ namespace Musify.Application.PlayLists.Handlers
return Result.NoContent();
}
async Task<Result> TryPublishRemoveFileEventAsync(Guid playListId, string keyName, CancellationToken cancellationToken)
async Task<Result> TryPublishRemoveFileEventAsync(Guid playListId, string key, CancellationToken cancellationToken)
{
try
{
await eventBus.PublishAsync(new RemoveFileEvent(
storageConfiguration.BucketName,
keyName), cancellationToken);
key), cancellationToken);
return Result.Success();
}
catch (Exception exception)
{
logger.LogError(exception, "Failed to publish remove file event for PlayList id={PlayListId} and key={KeyName}.", playListId, keyName);
logger.LogError(exception, "Failed to publish remove file event for PlayList id={PlayListId} and key={Key}.", playListId, key);
return Result.Error($"Failed to publish remove file event for PlayList with id {playListId}.");
}
}
@@ -23,13 +23,13 @@ namespace Musify.Application.PlayLists.Handlers
if (playList is null)
{
logger.LogInformation("PlayList with id {PlayListId} not found", request.PlayListId);
logger.LogInformation("PlayList with id={PlayListId} not found", request.PlayListId);
return Result.NotFound();
}
if (playList.UserId != request.UserId)
{
logger.LogWarning("User with id {UserId} is not the owner of the PlayList with id {PlayListId}", request.UserId, request.PlayListId);
logger.LogWarning("User with id={UserId} is not the owner of the PlayList with id={PlayListId}", request.UserId, request.PlayListId);
return Result.Unauthorized();
}
@@ -51,20 +51,20 @@ namespace Musify.Application.PlayLists.Handlers
return Result.Success(PlayListResponse.FromEntity(playList));
}
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
if (playList.SmallPictureName != playListConfiguration.Routes.PresetSmallPicture)
await PublishRemoveFileEvent(Path.Combine(
playListConfiguration.Routes.SmallPicturesPath,
playList.SmallPictureKeyName),
playList.SmallPictureName),
cancellationToken);
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
if (playList.MediumPictureName != playListConfiguration.Routes.PresetMediumPicture)
await PublishRemoveFileEvent(Path.Combine(
playListConfiguration.Routes.MediumPicturesPath,
playList.MediumPictureKeyName),
playList.MediumPictureName),
cancellationToken);
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
if (playList.LargePictureName != playListConfiguration.Routes.PresetLargePicture)
await PublishRemoveFileEvent(Path.Combine(
playListConfiguration.Routes.LargePicturesPath,
playList.LargePictureKeyName),
playList.LargePictureName),
cancellationToken);
var newImageId = Guid.NewGuid();
@@ -74,7 +74,7 @@ namespace Musify.Application.PlayLists.Handlers
var uploadResult = await UploadFile(request.NewPicture, newImageStorageKey, cancellationToken);
if (!uploadResult.IsSuccess)
{
logger.LogError("Failed to upload picture for PlayList with Id={PlayListId} to storage. Storage handler returned error: {ErrorMessage}",
logger.LogError("Failed to upload picture for PlayList with Id={PlayListId} to storage. Storage handler returned error?={ErrorMessage}",
playList.Id, string.Join("; ", uploadResult.Errors));
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
}
@@ -85,14 +85,14 @@ namespace Musify.Application.PlayLists.Handlers
}
catch (Exception exception)
{
logger.LogError(exception, "Failed to publish update picture event for PlayList with id {PlayListId}.", playList.Id);
logger.LogError(exception, "Failed to publish update picture event for PlayList with id={PlayListId}.", playList.Id);
return Result.Error($"Failed to publish update picture event for PlayList with id {playList.Id}.");
}
database.PlayLists.Update(playList);
await database.SaveChangesAsync(cancellationToken);
logger.LogInformation("Updated PlayList with id={PlayListId} and picture key {PictureKey}.", playList.Id, newImageStorageKey);
logger.LogInformation("Updated PlayList with id={PlayListId} and picture key={PictureKey}.", playList.Id, newImageStorageKey);
return Result.Success(PlayListResponse.FromEntity(playList));
}
@@ -110,7 +110,7 @@ namespace Musify.Application.PlayLists.Handlers
}
catch (Exception exception)
{
logger.LogError(exception, "Failed to publish remove file event for key {Key}.", key);
logger.LogError(exception, "Failed to publish remove file event for key={Key}.", key);
return Result.Error($"Failed to publish remove file event for key {key}.");
}
}
@@ -18,9 +18,9 @@ namespace Musify.Application.PlayLists.Responses
playList.Id,
playList.Name,
playList.Description,
playList.SmallPictureKeyName,
playList.MediumPictureKeyName,
playList.LargePictureKeyName,
playList.SmallPictureName,
playList.MediumPictureName,
playList.LargePictureName,
playList.CreatedDate,
playList.UpdatedDate);
}
@@ -21,7 +21,7 @@ namespace Musify.Application.Tracks.Handler
if (userExists is null)
{
logger.LogWarning("User with id {UserId} not found", request.UserId);
logger.LogWarning("User with id={UserId} not found", request.UserId);
return Result.NotFound($"User with id {request.UserId} not found");
}
@@ -31,11 +31,11 @@ namespace Musify.Application.Tracks.Handler
{
Title = request.Title,
NormalizedTitle = request.Title.Trim().ToUpperInvariant(),
OriginalPictureKeyName = originalPictureFileName,
OriginalAudioKeyName = originalAudioFileName,
SmallPictureKeyName = trackConfiguration.Routes.PresetMediumPicture,
MediumPictureKeyName = trackConfiguration.Routes.PresetMediumPicture,
LargePictureKeyName = trackConfiguration.Routes.PresetLargePicture,
OriginalPictureName = originalPictureFileName,
OriginalAudioName = originalAudioFileName,
SmallPictureName = trackConfiguration.Routes.PresetMediumPicture,
MediumPictureName = trackConfiguration.Routes.PresetMediumPicture,
LargePictureName = trackConfiguration.Routes.PresetLargePicture,
};
var originalPictureKey = Path.Combine(trackConfiguration.Routes.OriginalPicturesPath,
@@ -43,7 +43,7 @@ namespace Musify.Application.Tracks.Handler
var pictureUploadResult = await UploadFile(request.Picture, originalPictureKey, cancellationToken);
if (!pictureUploadResult.IsSuccess)
{
logger.LogError("Failed to upload picture for track {TrackTitle}", request.Title);
logger.LogError("Failed to upload picture for track={TrackTitle}", request.Title);
return Result.Error($"Failed to upload picture for track {request.Title}");
}
@@ -53,7 +53,7 @@ namespace Musify.Application.Tracks.Handler
var audioUploadResult = await UploadFile(request.Audio, audioKey, cancellationToken);
if (!audioUploadResult.IsSuccess)
{
logger.LogError("Failed to upload audio for track {TrackTitle}", request.Title);
logger.LogError("Failed to upload audio for track={TrackTitle}", request.Title);
return Result.Error($"Failed to upload audio for track {request.Title}");
}
@@ -14,8 +14,6 @@ namespace Musify.Application.Users.Handlers
{
public async Task<Result<UserResponse>> Handle(CreateUserCommand request, CancellationToken cancellationToken)
{
logger.LogDebug("Handling {CommandName} with Id: {UserId}", nameof(CreateUserCommand), request.Id);
var existingUser = await database.Users.SingleOrDefaultAsync(u => u.Id == request.Id, cancellationToken);
if (existingUser is not null)