A lot of changes
This commit is contained in:
@@ -24,4 +24,8 @@
|
|||||||
<ProjectReference Include="..\Domain\Domain.csproj" />
|
<ProjectReference Include="..\Domain\Domain.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Tracks\Queries\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ namespace Musify.Application.Configuration
|
|||||||
{
|
{
|
||||||
serviceDescriptors
|
serviceDescriptors
|
||||||
.AddValidatedConfiguration<ApplicationStorageConfiguration>(configuration, ApplicationStorageConfiguration.SectionName)
|
.AddValidatedConfiguration<ApplicationStorageConfiguration>(configuration, ApplicationStorageConfiguration.SectionName)
|
||||||
.AddValidatedConfiguration<PlayListConfiguration>(configuration, PlayListConfiguration.SectionName);
|
.AddValidatedConfiguration<PlayListConfiguration>(configuration, PlayListConfiguration.SectionName)
|
||||||
|
.AddValidatedConfiguration<TrackConfiguration>(configuration, TrackConfiguration.SectionName);
|
||||||
|
|
||||||
return serviceDescriptors;
|
return serviceDescriptors;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,17 @@ namespace Musify.Application.Configuration
|
|||||||
public const string SectionName = "PlayListConfiguration";
|
public const string SectionName = "PlayListConfiguration";
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public Routes Routes { get; set; } = new Routes();
|
public PlayListRoutes Routes { get; set; } = new PlayListRoutes();
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public PicturesSizes PicturesSizes { get; set; } = new PicturesSizes();
|
public PlayListPicturesSizes PicturesSizes { get; set; } = new PlayListPicturesSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Routes
|
public class PlayListRoutes
|
||||||
{
|
{
|
||||||
|
[Required]
|
||||||
|
public string ParentFolders { get; set; } = "PlayLists";
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string OriginalPictures { get; set; } = "OriginalPictures";
|
public string OriginalPictures { get; set; } = "OriginalPictures";
|
||||||
|
|
||||||
@@ -37,7 +40,7 @@ namespace Musify.Application.Configuration
|
|||||||
public string PresetLargePicture { get; set; } = "PresetLargePicture.webp";
|
public string PresetLargePicture { get; set; } = "PresetLargePicture.webp";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PicturesSizes
|
public class PlayListPicturesSizes
|
||||||
{
|
{
|
||||||
[Range(1, 1024)]
|
[Range(1, 1024)]
|
||||||
public int SmallPictureWidth { get; set; } = 128;
|
public int SmallPictureWidth { get; set; } = 128;
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Musify.Application.Configuration
|
||||||
|
{
|
||||||
|
public class TrackConfiguration
|
||||||
|
{
|
||||||
|
public const string SectionName = "TrackConfiguration";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public TrackRoutes Routes { get; set; } = new TrackRoutes();
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public TrackPicturesSizes PicturesSizes { get; set; } = new TrackPicturesSizes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TrackRoutes
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public string ParentFolder { get; set; } = "Tracks";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string OriginalPictures { get; set; } = "OriginalTracks";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string SmallPictures { get; set; } = "SmallTracks";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string MediumPictures { get; set; } = "MediumTracks";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string LargePictures { get; set; } = "LargeTracks";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string PresetSmallPicture { get; set; } = "PresetSmallPicture.webp";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string PresetMediumPicture { get; set; } = "PresetMediumPicture.webp";
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string PresetLargePicture { get; set; } = "PresetLargePicture.webp";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TrackPicturesSizes
|
||||||
|
{
|
||||||
|
[Range(1, 1024)]
|
||||||
|
public int SmallPictureWidth { get; set; } = 128;
|
||||||
|
|
||||||
|
[Range(1, 1024)]
|
||||||
|
public int SmallPictureHeight { get; set; } = 128;
|
||||||
|
|
||||||
|
[Range(1, 1024)]
|
||||||
|
public int MediumPictureWidth { get; private set; } = 256;
|
||||||
|
|
||||||
|
[Range(1, 1024)]
|
||||||
|
public int MediumPictureHeight { get; private set; } = 256;
|
||||||
|
|
||||||
|
[Range(1, 1024)]
|
||||||
|
public int LargePictureWidth { get; private set; } = 512;
|
||||||
|
|
||||||
|
[Range(1, 1024)]
|
||||||
|
public int LargePictureHeight { get; private set; } = 512;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ namespace Musify.Application.Contracts.Infrastructure
|
|||||||
|
|
||||||
DbSet<Track> Tracks { get; }
|
DbSet<Track> Tracks { get; }
|
||||||
|
|
||||||
|
DbSet<UserHasTrack> UserHasTracks { get; }
|
||||||
|
|
||||||
DbSet<PlayListHasTrack> PlayListHasTracks { get; }
|
DbSet<PlayListHasTrack> PlayListHasTracks { get; }
|
||||||
|
|
||||||
DbSet<Upload> Uploads { get; }
|
DbSet<Upload> Uploads { get; }
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace Musify.Application.Events
|
||||||
|
{
|
||||||
|
public record ProcessTrackEvent();
|
||||||
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using Musify.Application.Contracts.Application;
|
namespace Musify.Application.Events
|
||||||
|
|
||||||
namespace Musify.Application.Events
|
|
||||||
{
|
{
|
||||||
public record RemoveFileEvent(
|
public record RemoveFileEvent(
|
||||||
string BucketName,
|
string BucketName,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace Musify.Application.Events
|
||||||
|
{
|
||||||
|
public record UpdateTrackPictureEvent(
|
||||||
|
Guid TrackId,
|
||||||
|
string BucketName,
|
||||||
|
string OriginalPictureKeyName,
|
||||||
|
string SmallPictureKeyName,
|
||||||
|
int SmallPictureWidth,
|
||||||
|
int SmallPictureHeight,
|
||||||
|
string MediumPictureKeyName,
|
||||||
|
int MediumPictureWidth,
|
||||||
|
int MediumPictureHeight,
|
||||||
|
string LargePictureKeyName,
|
||||||
|
int LargePictureWidth,
|
||||||
|
int LargePictureHeight);
|
||||||
|
}
|
||||||
@@ -10,9 +10,8 @@ using Musify.Domain.Entities;
|
|||||||
|
|
||||||
namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
namespace Musify.Application.PlayLists.Commands.CreatePlayList
|
||||||
{
|
{
|
||||||
public class CreatePlayListCommandHandler(IEventBus eventBus, IDatabase database, IStorageHandler storageHandler,
|
public class CreatePlayListCommandHandler(IEventBus eventBus, IDatabase database, IStorageHandler storageHandler, IPictureHandler pictureHandler,
|
||||||
ILogger<CreatePlayListCommandHandler> logger, ApplicationStorageConfiguration storageConfiguration,
|
ILogger<CreatePlayListCommandHandler> logger, ApplicationStorageConfiguration storageConfiguration, PlayListConfiguration playListConfiguration)
|
||||||
PlayListConfiguration playListConfiguration, IPictureHandler pictureHandler)
|
|
||||||
: IRequestHandler<CreatePlayListCommand, Task<Result<PlayListResponse>> >
|
: IRequestHandler<CreatePlayListCommand, Task<Result<PlayListResponse>> >
|
||||||
{
|
{
|
||||||
public async Task<Result<PlayListResponse>> Handle(CreatePlayListCommand request, CancellationToken cancellationToken)
|
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));
|
playList.Id, string.Join("; ", uploadResult.Errors));
|
||||||
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
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);
|
logger.LogInformation("Playlist image uploaded successfully for PlayList with Id={PlayListId}.", playList.Id);
|
||||||
|
|
||||||
var smallPictureKeyName = Path.Combine(
|
var smallPictureKeyName = Path.Combine(
|
||||||
|
|||||||
@@ -27,23 +27,16 @@ namespace Musify.Application.PlayLists.Commands.DeletePlayList
|
|||||||
return Result.Unauthorized();
|
return Result.Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
var keysToRemove = new List<string>();
|
||||||
{
|
|
||||||
var keysToRemove = new List<string>
|
|
||||||
{
|
|
||||||
Path.Join(playListConfiguration.Routes.OriginalPictures, playList.OriginalPictureKeyName)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||||
{
|
{
|
||||||
keysToRemove.Add(playList.SmallPictureKeyName);
|
keysToRemove.Add(playList.SmallPictureKeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||||
{
|
{
|
||||||
keysToRemove.Add(playList.MediumPictureKeyName);
|
keysToRemove.Add(playList.MediumPictureKeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
if (playList.LargePictureKeyName != playListConfiguration.Routes.PresetLargePicture)
|
||||||
{
|
{
|
||||||
keysToRemove.Add(playList.LargePictureKeyName);
|
keysToRemove.Add(playList.LargePictureKeyName);
|
||||||
@@ -58,7 +51,6 @@ namespace Musify.Application.PlayLists.Commands.DeletePlayList
|
|||||||
return publishResult;
|
return publishResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
database.PlayLists.Remove(playList);
|
database.PlayLists.Remove(playList);
|
||||||
await database.SaveChangesAsync(cancellationToken);
|
await database.SaveChangesAsync(cancellationToken);
|
||||||
|
|||||||
@@ -47,25 +47,6 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
|||||||
return Result.Success(PlayListResponse.FromEntity(playList));
|
return Result.Success(PlayListResponse.FromEntity(playList));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(playList.OriginalPictureKeyName))
|
|
||||||
{
|
|
||||||
var originalImageStorageKey = Path.Join(playListConfiguration.Routes.OriginalPictures, playList.OriginalPictureKeyName);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await eventBus.PublishAsync(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}",
|
|
||||||
originalImageStorageKey, storageConfiguration.BucketName);
|
|
||||||
|
|
||||||
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
if (playList.SmallPictureKeyName != playListConfiguration.Routes.PresetSmallPicture)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -80,7 +61,6 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
|||||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
if (playList.MediumPictureKeyName != playListConfiguration.Routes.PresetMediumPicture)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -95,7 +75,6 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
|||||||
return Result.Error($"Failed to publish remove file event for PlayList with id {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
|
||||||
@@ -110,7 +89,6 @@ namespace Musify.Application.PlayLists.Commands.UpdatePlayList
|
|||||||
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
return Result.Error($"Failed to publish remove file event for PlayList with id {playList.Id}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var newImageId = Guid.NewGuid();
|
var newImageId = Guid.NewGuid();
|
||||||
var pictureName = $"{newImageId}{request.NewPicture.FileType}";
|
var pictureName = $"{newImageId}{request.NewPicture.FileType}";
|
||||||
@@ -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.");
|
return Result.Error($"Failed to upload picture for PlayList with Id {playList.Id} to storage.");
|
||||||
}
|
}
|
||||||
|
|
||||||
playList.OriginalPictureKeyName = pictureName;
|
|
||||||
|
|
||||||
var smallPictureKeyName = Path.Combine(
|
var smallPictureKeyName = Path.Combine(
|
||||||
playListConfiguration.Routes.SmallPictures,
|
playListConfiguration.Routes.SmallPictures,
|
||||||
$"{playList.Id}.{pictureHandler.FileExtension}");
|
$"{playList.Id}.{pictureHandler.FileExtension}");
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Ardalis.Result;
|
||||||
|
using DispatchR.Abstractions.Send;
|
||||||
|
using Musify.Application.Contracts.Application;
|
||||||
|
using Musify.Application.Tracks.Contracts;
|
||||||
|
|
||||||
|
namespace Musify.Application.Tracks.Commands.CreateTrack
|
||||||
|
{
|
||||||
|
public record CreateTrackCommand(
|
||||||
|
Guid UserId,
|
||||||
|
string Title,
|
||||||
|
IFileData Picture,
|
||||||
|
IFileData Audio)
|
||||||
|
: IRequest<CreateTrackCommand, Task<Result<TrackResponse> >>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using Ardalis.Result;
|
||||||
|
using DispatchR.Abstractions.Send;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Musify.Application.Configuration;
|
||||||
|
using Musify.Application.Contracts.Infrastructure;
|
||||||
|
using Musify.Application.Events;
|
||||||
|
using Musify.Application.Tracks.Contracts;
|
||||||
|
using Musify.Domain.Entities;
|
||||||
|
|
||||||
|
namespace Musify.Application.Tracks.Commands.CreateTrack
|
||||||
|
{
|
||||||
|
public class CreateTrackCommandHandler(IDatabase database, IPictureHandler pictureHandler, IEventBus eventBus, IStorageHandler storageHandler,
|
||||||
|
ILogger<CreateTrackCommandHandler> logger, ApplicationStorageConfiguration storageConfiguration, TrackConfiguration trackConfiguration)
|
||||||
|
: IRequestHandler<CreateTrackCommand, Task<Result<TrackResponse> >>
|
||||||
|
{
|
||||||
|
public async Task<Result<TrackResponse>> Handle(CreateTrackCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var userExists = await database.Users.FindAsync(request.UserId, cancellationToken);
|
||||||
|
|
||||||
|
if (userExists is null)
|
||||||
|
{
|
||||||
|
logger.LogWarning("User with id {UserId} not found", request.UserId);
|
||||||
|
return Result.NotFound($"User with id {request.UserId} not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
var originalPictureKeyName = $"{Guid.NewGuid() }.{request.Picture.FileType}";
|
||||||
|
var track = new Track
|
||||||
|
{
|
||||||
|
Title = request.Title,
|
||||||
|
NormalizedTitle = request.Title.Trim().ToUpperInvariant(),
|
||||||
|
SmallPictureKeyName = trackConfiguration.Routes.PresetSmallPicture,
|
||||||
|
MediumPictureKeyName = trackConfiguration.Routes.PresetMediumPicture,
|
||||||
|
LargePictureKeyName = trackConfiguration.Routes.PresetLargePicture,
|
||||||
|
};
|
||||||
|
|
||||||
|
var pictureUploadResult = await storageHandler.UploadFileAsync(
|
||||||
|
request.Picture.FileStream,
|
||||||
|
request.Picture.ContentType,
|
||||||
|
storageConfiguration.BucketName,
|
||||||
|
originalPictureKeyName,
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
|
if (!pictureUploadResult.IsSuccess)
|
||||||
|
{
|
||||||
|
logger.LogError("Failed to upload picture for track {TrackTitle}", request.Title);
|
||||||
|
return Result.Error($"Failed to upload picture for track {request.Title}");
|
||||||
|
}
|
||||||
|
|
||||||
|
var smallPictureKeyName = Path.Combine(
|
||||||
|
trackConfiguration.Routes.SmallPictures,
|
||||||
|
$"{track.Id}.{pictureHandler.FileExtension}");
|
||||||
|
var mediumPictureKeyName = Path.Combine(
|
||||||
|
trackConfiguration.Routes.MediumPictures,
|
||||||
|
$"{track.Id}.{pictureHandler.FileExtension}");
|
||||||
|
var largePictureKeyName = Path.Combine(
|
||||||
|
trackConfiguration.Routes.LargePictures,
|
||||||
|
$"{track.Id}.{pictureHandler.FileExtension}");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await eventBus.PublishAsync(new UpdatePlayListPictureEvent(
|
||||||
|
track.Id,
|
||||||
|
storageConfiguration.BucketName,
|
||||||
|
originalPictureKeyName,
|
||||||
|
smallPictureKeyName,
|
||||||
|
trackConfiguration.PicturesSizes.SmallPictureWidth,
|
||||||
|
trackConfiguration.PicturesSizes.SmallPictureHeight,
|
||||||
|
mediumPictureKeyName,
|
||||||
|
trackConfiguration.PicturesSizes.MediumPictureWidth,
|
||||||
|
trackConfiguration.PicturesSizes.MediumPictureHeight,
|
||||||
|
largePictureKeyName,
|
||||||
|
trackConfiguration.PicturesSizes.LargePictureWidth,
|
||||||
|
trackConfiguration.PicturesSizes.LargePictureHeight), cancellationToken);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
logger.LogError(exception, "Failed to publish resize picture event for Track with id={TrackId}.", track.Id);
|
||||||
|
return Result.Error($"Failed to publish resize picture event for Track with id {track.Id}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await database.Tracks.AddAsync(track, cancellationToken);
|
||||||
|
await database.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
return Result.Success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using Musify.Domain.Entities;
|
||||||
|
|
||||||
|
namespace Musify.Application.Tracks.Contracts
|
||||||
|
{
|
||||||
|
public record TrackResponse(
|
||||||
|
Guid Id,
|
||||||
|
string Title,
|
||||||
|
DateTime CreatedDate,
|
||||||
|
DateTime UpdatedDate)
|
||||||
|
{
|
||||||
|
public static TrackResponse FromEntity(Track track)
|
||||||
|
{
|
||||||
|
return new TrackResponse(
|
||||||
|
track.Id,
|
||||||
|
track.Title,
|
||||||
|
track.CreatedDate,
|
||||||
|
track.UpdatedDate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,9 +25,6 @@ namespace Musify.Domain.Entities
|
|||||||
[MaxLength(254)]
|
[MaxLength(254)]
|
||||||
public required string Description { get; set; } = "No description was provided.";
|
public required string Description { get; set; } = "No description was provided.";
|
||||||
|
|
||||||
[MaxLength(64)]
|
|
||||||
public string? OriginalPictureKeyName { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[MaxLength(64)]
|
[MaxLength(64)]
|
||||||
public required string SmallPictureKeyName { get; set; }
|
public required string SmallPictureKeyName { get; set; }
|
||||||
|
|||||||
@@ -18,7 +18,15 @@ namespace Musify.Domain.Entities
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[MaxLength(64)]
|
[MaxLength(64)]
|
||||||
public required string ImageName { get; set; }
|
public required string SmallPictureKeyName { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(64)]
|
||||||
|
public required string MediumPictureKeyName { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[MaxLength(64)]
|
||||||
|
public required string LargePictureKeyName { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime CreatedDate { get; set; } = DateTime.UtcNow;
|
public DateTime CreatedDate { get; set; } = DateTime.UtcNow;
|
||||||
@@ -26,7 +34,7 @@ namespace Musify.Domain.Entities
|
|||||||
[Required]
|
[Required]
|
||||||
public DateTime UpdatedDate { get; set; } = DateTime.UtcNow;
|
public DateTime UpdatedDate { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
public ICollection<User> Users { get; set; } = new List<User>();
|
public ICollection<UserHasTrack> UserTracks { get; set; } = new List<UserHasTrack>();
|
||||||
|
|
||||||
public ICollection<PlayListHasTrack> PlayListTracks { get; set; } = new List<PlayListHasTrack>();
|
public ICollection<PlayListHasTrack> PlayListTracks { get; set; } = new List<PlayListHasTrack>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Musify.Domain.Entities
|
|||||||
[Required]
|
[Required]
|
||||||
public DateTime UpdatedAt { get; set; } = DateTime.Now;
|
public DateTime UpdatedAt { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
public ICollection<Track> Tracks { get; set; } = new List<Track>();
|
public ICollection<UserHasTrack> UserTracks { get; set; } = new List<UserHasTrack>();
|
||||||
|
|
||||||
public ICollection<PlayList> PlayLists { get; set; } = new List<PlayList>();
|
public ICollection<PlayList> PlayLists { get; set; } = new List<PlayList>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Musify.Domain.Entities
|
||||||
|
{
|
||||||
|
#pragma warning disable CS8618
|
||||||
|
[Table("UserHasTrack")]
|
||||||
|
public class UserHasTrack
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public required Guid UserId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public required Guid TrackId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(UserId)) ]
|
||||||
|
public User User { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(TrackId)) ]
|
||||||
|
public Track Track { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Musify.Infrastructure.Messaging.Activities.Arguments
|
||||||
|
{
|
||||||
|
public record UpdateTrackPictureArguments(
|
||||||
|
Guid TrackId,
|
||||||
|
string SmallPictureKeyName,
|
||||||
|
string MediumPictureKeyName,
|
||||||
|
string LargePictureKeyName);
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using MassTransit;
|
||||||
|
using Musify.Application.Contracts.Infrastructure;
|
||||||
|
using Musify.Domain.Entities;
|
||||||
|
using Musify.Infrastructure.Messaging.Activities.Arguments;
|
||||||
|
|
||||||
|
namespace Musify.Infrastructure.Messaging.Activities
|
||||||
|
{
|
||||||
|
public class UpdateTrackPictureActivity(IDatabase database, IProcessTrackingStore processTrackingStore)
|
||||||
|
: IExecuteActivity<UpdateTrackPictureArguments>
|
||||||
|
{
|
||||||
|
public const string ExecuteEndpointName = "Update-Track-Picture";
|
||||||
|
|
||||||
|
public async Task<ExecutionResult> Execute(ExecuteContext<UpdateTrackPictureArguments> executeContext)
|
||||||
|
{
|
||||||
|
var processId = await processTrackingStore.GetOrCreateProcessAsync(
|
||||||
|
"RoutingSlip",
|
||||||
|
executeContext.CorrelationId ?? executeContext.TrackingNumber,
|
||||||
|
executeContext.ConversationId,
|
||||||
|
executeContext.MessageId,
|
||||||
|
executeContext.CancellationToken);
|
||||||
|
|
||||||
|
var stepId = await processTrackingStore.StartStepAsync(
|
||||||
|
processId,
|
||||||
|
nameof(UpdateTrackPictureActivity),
|
||||||
|
ProcessStepComponentType.Activity,
|
||||||
|
0,
|
||||||
|
executeContext.CancellationToken);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var track = await database.Tracks.FindAsync(executeContext.Arguments.TrackId, executeContext.CancellationToken);
|
||||||
|
|
||||||
|
if (track is null)
|
||||||
|
throw new Exception($"Track with id {executeContext.Arguments.TrackId} not found.");
|
||||||
|
|
||||||
|
track.SmallPictureKeyName = executeContext.Arguments.SmallPictureKeyName;
|
||||||
|
track.MediumPictureKeyName = executeContext.Arguments.MediumPictureKeyName;
|
||||||
|
track.LargePictureKeyName = executeContext.Arguments.LargePictureKeyName;
|
||||||
|
|
||||||
|
database.Tracks.Update(track);
|
||||||
|
await database.SaveChangesAsync(executeContext.CancellationToken);
|
||||||
|
|
||||||
|
await processTrackingStore.CompleteStepAsync(processId, stepId, executeContext.CancellationToken);
|
||||||
|
return executeContext.Completed();
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
await processTrackingStore.FailStepAsync(processId, stepId, exception.Message, executeContext.CancellationToken);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,7 +44,10 @@ namespace Musify.Infrastructure.Messaging.Consumers
|
|||||||
routingSlipBuilder.AddActivity(
|
routingSlipBuilder.AddActivity(
|
||||||
"DeleteOriginal",
|
"DeleteOriginal",
|
||||||
BuildExecuteUri(RemoveFilesActivity.ExecuteEndpointName),
|
BuildExecuteUri(RemoveFilesActivity.ExecuteEndpointName),
|
||||||
new RemoveFileArguments(consumeContext.Message.BucketName, consumeContext.Message.OriginalPictureKeyName));
|
new RemoveFileArguments(
|
||||||
|
consumeContext.Message.BucketName,
|
||||||
|
consumeContext.Message.OriginalPictureKeyName)
|
||||||
|
);
|
||||||
|
|
||||||
routingSlipBuilder.AddActivity(
|
routingSlipBuilder.AddActivity(
|
||||||
"UpdatePlayListPicture",
|
"UpdatePlayListPicture",
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using MassTransit;
|
||||||
|
using Musify.Application.Events;
|
||||||
|
using Musify.Infrastructure.Messaging.Activities;
|
||||||
|
using Musify.Infrastructure.Messaging.Activities.Arguments;
|
||||||
|
|
||||||
|
namespace Musify.Infrastructure.Messaging.Consumers
|
||||||
|
{
|
||||||
|
public class UpdateTrackPictureConsumer(IBus bus)
|
||||||
|
: IConsumer<UpdateTrackPictureEvent>
|
||||||
|
{
|
||||||
|
public const string QueueName = "update-track-picture";
|
||||||
|
|
||||||
|
public async Task Consume(ConsumeContext<UpdateTrackPictureEvent> consumeContext)
|
||||||
|
{
|
||||||
|
var routingSlipBuilder = new RoutingSlipBuilder(NewId.NextGuid());
|
||||||
|
|
||||||
|
AddResizeActivity(
|
||||||
|
routingSlipBuilder,
|
||||||
|
"ResizeSmall",
|
||||||
|
consumeContext.Message.SmallPictureKeyName,
|
||||||
|
consumeContext.Message.SmallPictureWidth,
|
||||||
|
consumeContext.Message.SmallPictureHeight,
|
||||||
|
consumeContext.Message.OriginalPictureKeyName,
|
||||||
|
consumeContext.Message.BucketName);
|
||||||
|
|
||||||
|
AddResizeActivity(
|
||||||
|
routingSlipBuilder,
|
||||||
|
"ResizeMedium",
|
||||||
|
consumeContext.Message.SmallPictureKeyName,
|
||||||
|
consumeContext.Message.MediumPictureWidth,
|
||||||
|
consumeContext.Message.MediumPictureHeight,
|
||||||
|
consumeContext.Message.OriginalPictureKeyName,
|
||||||
|
consumeContext.Message.BucketName);
|
||||||
|
|
||||||
|
AddResizeActivity(
|
||||||
|
routingSlipBuilder,
|
||||||
|
"ResizeMedium",
|
||||||
|
consumeContext.Message.SmallPictureKeyName,
|
||||||
|
consumeContext.Message.LargePictureWidth,
|
||||||
|
consumeContext.Message.LargePictureHeight,
|
||||||
|
consumeContext.Message.OriginalPictureKeyName,
|
||||||
|
consumeContext.Message.BucketName);
|
||||||
|
|
||||||
|
routingSlipBuilder.AddActivity(
|
||||||
|
"DeleteOriginal",
|
||||||
|
BuildExecuteUri(RemoveFilesActivity.ExecuteEndpointName),
|
||||||
|
new RemoveFileArguments(
|
||||||
|
consumeContext.Message.BucketName,
|
||||||
|
consumeContext.Message.OriginalPictureKeyName)
|
||||||
|
);
|
||||||
|
|
||||||
|
routingSlipBuilder.AddActivity(
|
||||||
|
"UpdateTrackPictureActivity",
|
||||||
|
BuildExecuteUri(UpdateTrackPictureActivity.ExecuteEndpointName),
|
||||||
|
new UpdateTrackPictureArguments(
|
||||||
|
consumeContext.Message.TrackId,
|
||||||
|
consumeContext.Message.SmallPictureKeyName,
|
||||||
|
consumeContext.Message.MediumPictureKeyName,
|
||||||
|
consumeContext.Message.LargePictureKeyName));
|
||||||
|
|
||||||
|
var routingSlip = routingSlipBuilder.Build();
|
||||||
|
await bus.Execute(routingSlip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddResizeActivity(
|
||||||
|
RoutingSlipBuilder routingSlipBuilder,
|
||||||
|
string activityName,
|
||||||
|
string destinationKeyName,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
string originalPictureKeyName,
|
||||||
|
string bucketName)
|
||||||
|
{
|
||||||
|
routingSlipBuilder.AddActivity(
|
||||||
|
activityName,
|
||||||
|
BuildExecuteUri(ResizePictureActivity.ExecuteEndpointName),
|
||||||
|
new ResizePictureArgument(
|
||||||
|
bucketName,
|
||||||
|
originalPictureKeyName,
|
||||||
|
bucketName,
|
||||||
|
destinationKeyName,
|
||||||
|
width,
|
||||||
|
height));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Uri BuildExecuteUri(string endpointName) => new($"queue:{endpointName}_execute");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,8 @@ namespace Musify.Infrastructure.Persistence
|
|||||||
|
|
||||||
public DbSet<PlayList> PlayLists => Set<PlayList>();
|
public DbSet<PlayList> PlayLists => Set<PlayList>();
|
||||||
|
|
||||||
|
public DbSet<UserHasTrack> UserHasTracks => Set<UserHasTrack>();
|
||||||
|
|
||||||
public DbSet<PlayListHasTrack> PlayListHasTracks => Set<PlayListHasTrack>();
|
public DbSet<PlayListHasTrack> PlayListHasTracks => Set<PlayListHasTrack>();
|
||||||
|
|
||||||
public DbSet<Upload> Uploads => Set<Upload>();
|
public DbSet<Upload> Uploads => Set<Upload>();
|
||||||
|
|||||||
Reference in New Issue
Block a user