QOL Changes
This commit is contained in:
@@ -7,6 +7,8 @@ namespace Musify.Application.Configuration
|
||||
public const string SectionName = "Storage";
|
||||
|
||||
[Required]
|
||||
[MinLength(3)]
|
||||
[MaxLength(63)]
|
||||
public required string BucketName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
return Result.NotFound($"User with Id {request.UserId} does not exist.");
|
||||
}
|
||||
|
||||
var imageId = Guid.NewGuid();
|
||||
|
||||
var playList = new PlayList
|
||||
{
|
||||
UserId = request.UserId,
|
||||
@@ -40,14 +38,15 @@ namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
|
||||
if (request.Picture is not null)
|
||||
{
|
||||
playList.OriginalPictureKeyName = $"{imageId}{request.Picture.FileType}";
|
||||
var imageKeyName = $"{playListConfiguration.Routes.OriginalPictures}/{imageId}{request.Picture.FileType}";
|
||||
var imageId = Guid.NewGuid();
|
||||
var pictureName = $"{imageId}{request.Picture.FileType}";
|
||||
var originalImageStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, pictureName);
|
||||
|
||||
var uploadResult = await storageHandler.UploadFileAsync(
|
||||
request.Picture.FileStream,
|
||||
request.Picture.ContentType,
|
||||
storageConfiguration.BucketName,
|
||||
imageKeyName,
|
||||
originalImageStorageKey,
|
||||
cancellationToken);
|
||||
|
||||
if (!uploadResult.IsSuccess)
|
||||
@@ -57,25 +56,34 @@ namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||
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);
|
||||
|
||||
await publishEndpoint.Publish(new ResizePictureEvent(
|
||||
storageConfiguration.BucketName,
|
||||
imageKeyName,
|
||||
[
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(new ResizePictureEvent(
|
||||
storageConfiguration.BucketName,
|
||||
originalImageStorageKey,
|
||||
[
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.SmallPictureWidth,
|
||||
playListConfiguration.PicturesSizes.SmallPictureHeight,
|
||||
playListConfiguration.Routes.SmallPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.MediumPictureWidth,
|
||||
playListConfiguration.PicturesSizes.MediumPictureHeight,
|
||||
playListConfiguration.Routes.MediumPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.LargePictureWidth,
|
||||
playListConfiguration.PicturesSizes.LargePictureHeight,
|
||||
playListConfiguration.Routes.LargePictures)
|
||||
] ), cancellationToken);
|
||||
playListConfiguration.PicturesSizes.SmallPictureWidth,
|
||||
playListConfiguration.PicturesSizes.SmallPictureHeight,
|
||||
playListConfiguration.Routes.SmallPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.MediumPictureWidth,
|
||||
playListConfiguration.PicturesSizes.MediumPictureHeight,
|
||||
playListConfiguration.Routes.MediumPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.LargePictureWidth,
|
||||
playListConfiguration.PicturesSizes.LargePictureHeight,
|
||||
playListConfiguration.Routes.LargePictures)
|
||||
] ), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish resize picture event for PlayList with id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish resize picture event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Musify.Application.Configuration;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Application.Events;
|
||||
using Musify.Application.PlayLists;
|
||||
|
||||
namespace Musify.Application.PlayLists.Commands.DeletePlayList
|
||||
{
|
||||
@@ -28,26 +29,66 @@ namespace Musify.Application.PlayLists.Commands.DeletePlayList
|
||||
return Result.Unauthorized();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
||||
{
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.OriginalPictureKeyName), cancellationToken);
|
||||
var originalImageStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, playList.OriginalPictureKeyName);
|
||||
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
originalImageStorageKey), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for original picture of PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||
}
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.SmallPictureKeyName), cancellationToken);
|
||||
{
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(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}.");
|
||||
}
|
||||
}
|
||||
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.MediumPictureKeyName), cancellationToken);
|
||||
{
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(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}.");
|
||||
}
|
||||
}
|
||||
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.LargePictureKeyName), cancellationToken);
|
||||
{
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
database.PlayLists.Remove(playList);
|
||||
|
||||
@@ -31,7 +31,10 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.NewName))
|
||||
{
|
||||
playList.Name = request.NewName;
|
||||
playList.NormalizedName = request.NewName.Trim().ToUpperInvariant();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.NewDescription))
|
||||
playList.Description = request.NewDescription;
|
||||
@@ -46,36 +49,78 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
||||
{
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.OriginalPictureKeyName), cancellationToken);
|
||||
var originalImageStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, playList.OriginalPictureKeyName);
|
||||
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
originalImageStorageKey), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish remove file event for original 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}",
|
||||
playList.OriginalPictureKeyName, storageConfiguration.BucketName);
|
||||
originalImageStorageKey, storageConfiguration.BucketName);
|
||||
|
||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.SmallPictureKeyName), cancellationToken);
|
||||
{
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(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}.");
|
||||
}
|
||||
}
|
||||
|
||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.MediumPictureKeyName), cancellationToken);
|
||||
{
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(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}.");
|
||||
}
|
||||
}
|
||||
|
||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||
await publishEndpoint.Publish(new RemoveFileEvent(
|
||||
storageConfiguration.BucketName,
|
||||
playList.LargePictureKeyName), cancellationToken);
|
||||
{
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var newImageId = Guid.NewGuid();
|
||||
var imageKeyName = $"{playListConfiguration.Routes.OriginalPictures}/{newImageId}{request.NewPicture.FileType}";
|
||||
var pictureName = $"{newImageId}{request.NewPicture.FileType}";
|
||||
var newImageStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, pictureName);
|
||||
|
||||
var uploadResult = await storageHandler.UploadFileAsync(
|
||||
request.NewPicture.FileStream,
|
||||
request.NewPicture.ContentType,
|
||||
storageConfiguration.BucketName,
|
||||
imageKeyName,
|
||||
newImageStorageKey,
|
||||
cancellationToken);
|
||||
|
||||
if (!uploadResult.IsSuccess)
|
||||
@@ -85,30 +130,39 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
||||
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
||||
}
|
||||
|
||||
playList.OriginalPictureKeyName = imageKeyName;
|
||||
await publishEndpoint.Publish(new ResizePictureEvent(
|
||||
storageConfiguration.BucketName,
|
||||
imageKeyName,
|
||||
[
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.SmallPictureWidth,
|
||||
playListConfiguration.PicturesSizes.SmallPictureHeight,
|
||||
playListConfiguration.Routes.SmallPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.MediumPictureWidth,
|
||||
playListConfiguration.PicturesSizes.MediumPictureHeight,
|
||||
playListConfiguration.Routes.MediumPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.LargePictureWidth,
|
||||
playListConfiguration.PicturesSizes.LargePictureHeight,
|
||||
playListConfiguration.Routes.LargePictures)
|
||||
]
|
||||
), cancellationToken);
|
||||
playList.OriginalPictureKeyName = pictureName;
|
||||
|
||||
try
|
||||
{
|
||||
await publishEndpoint.Publish(new ResizePictureEvent(
|
||||
storageConfiguration.BucketName,
|
||||
newImageStorageKey,
|
||||
[
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.SmallPictureWidth,
|
||||
playListConfiguration.PicturesSizes.SmallPictureHeight,
|
||||
playListConfiguration.Routes.SmallPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.MediumPictureWidth,
|
||||
playListConfiguration.PicturesSizes.MediumPictureHeight,
|
||||
playListConfiguration.Routes.MediumPictures),
|
||||
new ResizePictureItems(
|
||||
playListConfiguration.PicturesSizes.LargePictureWidth,
|
||||
playListConfiguration.PicturesSizes.LargePictureHeight,
|
||||
playListConfiguration.Routes.LargePictures)
|
||||
]
|
||||
), cancellationToken);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.LogError(exception, "Failed to publish resize picture event for PlayList id={PlayListId}.", playList.Id);
|
||||
return Result.Error($"Failed to publish resize 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 {PictureKeyName}.", playList.Id, imageKeyName);
|
||||
logger.LogInformation("Updated PlayList with id={PlayListId} and picture key {PictureKeyName}.", playList.Id, newImageStorageKey);
|
||||
return Result.Success(PlayListResponse.FromEntity(playList));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ using Musify.Application.PlayLists.Contracts;
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayListById
|
||||
{
|
||||
public record GetPlayListByIdQuery(Guid Id)
|
||||
: IRequest<GetPlayListByIdQuery, Result<PlayListResponse>>;
|
||||
: IRequest<GetPlayListByIdQuery, Task<Result<PlayListResponse>>>;
|
||||
}
|
||||
@@ -5,5 +5,5 @@ using Musify.Application.PlayLists.Contracts;
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayLists
|
||||
{
|
||||
public record GetPlayListsQuery(int PageNumber = 1, int PageSize = 10)
|
||||
: IRequest<GetPlayListsQuery, Result<PaginatedPlayListResponse>>;
|
||||
: IRequest<GetPlayListsQuery, Task<Result<PaginatedPlayListResponse>>>;
|
||||
}
|
||||
@@ -9,5 +9,5 @@ namespace Musify.Application.PlayLists.Queries.GetPlayListsByUserId
|
||||
string Name = "",
|
||||
int PageNumber = 1,
|
||||
int PageSize = 10)
|
||||
: IRequest<GetPlayListsByUserIdQuery, Result<PaginatedPlayListResponse>>;
|
||||
: IRequest<GetPlayListsByUserIdQuery, Task<Result<PaginatedPlayListResponse>>>;
|
||||
}
|
||||
+1
-2
@@ -3,7 +3,6 @@ using DispatchR.Abstractions.Send;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts.Infrastructure;
|
||||
using Musify.Application.PlayLists.Contracts;
|
||||
using Musify.Domain.Entities;
|
||||
using X.PagedList.EF;
|
||||
|
||||
namespace Musify.Application.PlayLists.Queries.GetPlayListsByUserId
|
||||
@@ -15,7 +14,7 @@ namespace Musify.Application.PlayLists.Queries.GetPlayListsByUserId
|
||||
{
|
||||
var pageNumber = request.PageNumber < 1 ? 1 : request.PageNumber;
|
||||
var pageSize = request.PageSize < 1 ? 10 : request.PageSize;
|
||||
var normalizedName = request.Name.Trim().ToUpperInvariant();
|
||||
var normalizedName = request.Name?.Trim().ToUpperInvariant() ?? string.Empty;
|
||||
|
||||
var playListsQuery = database.PlayLists
|
||||
.AsNoTracking()
|
||||
|
||||
@@ -5,5 +5,5 @@ using Musify.Application.Users.Contracts;
|
||||
namespace Musify.Application.Users.Commands.CreateUser
|
||||
{
|
||||
public record CreateUserCommand(Guid Id)
|
||||
: IRequest<CreateUserCommand, Result<UserResponse>>;
|
||||
: IRequest<CreateUserCommand, Task<Result<UserResponse>>>;
|
||||
}
|
||||
@@ -4,5 +4,5 @@ using DispatchR.Abstractions.Send;
|
||||
namespace Musify.Application.Users.Commands.DeleteUser
|
||||
{
|
||||
public record DeleteUserCommand(Guid Id)
|
||||
: IRequest<DeleteUserCommand, Result>;
|
||||
: IRequest<DeleteUserCommand, Task<Result>>;
|
||||
}
|
||||
Reference in New Issue
Block a user