Clean up Application layer commands/queries readability and correctness
Add missing AsNoTracking() on read-only queries, drop redundant Update() calls on already-tracked entities, and fix inconsistent formatting (stray spaces in generics, ternaries, and lambdas) across the Albums/Tracks/PlayLists/Users command and query handlers.
This commit is contained in:
@@ -55,7 +55,7 @@ namespace Musify.Application.PlayLists
|
||||
UserId = request.UserId,
|
||||
Name = request.Name,
|
||||
NormalizedName = request.Name.Trim().ToUpperInvariant(),
|
||||
Description = string.IsNullOrWhiteSpace(request.Description)? null: request.Description.Trim(),
|
||||
Description = string.IsNullOrWhiteSpace(request.Description) ? null : request.Description.Trim(),
|
||||
Pictures = resolvedPictures.Pictures,
|
||||
Visibility = request.Visibility
|
||||
};
|
||||
@@ -106,7 +106,7 @@ namespace Musify.Application.PlayLists
|
||||
}, validation.Value);
|
||||
}
|
||||
|
||||
async Task<ErrorOr<Success>> PublishCreatePlayListEventAsync(
|
||||
private async Task<ErrorOr<Success>> PublishCreatePlayListEventAsync(
|
||||
Guid playListId,
|
||||
UploadIntent pictureIntent,
|
||||
string finalPictureKey,
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace Musify.Application.PlayLists
|
||||
: IQuery<ErrorOr<PaginatedResponse<TrackApplicationResponse>>>;
|
||||
|
||||
public class GetPlayListTracksQueryHandler(IDatabase database)
|
||||
: IQueryHandler<GetPlayListTracksQuery, ErrorOr<PaginatedResponse<TrackApplicationResponse>> >
|
||||
: IQueryHandler<GetPlayListTracksQuery, ErrorOr<PaginatedResponse<TrackApplicationResponse>>>
|
||||
{
|
||||
public async ValueTask<ErrorOr<PaginatedResponse<TrackApplicationResponse> >> Handle(GetPlayListTracksQuery request, CancellationToken cancellationToken)
|
||||
public async ValueTask<ErrorOr<PaginatedResponse<TrackApplicationResponse>>> Handle(GetPlayListTracksQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var playListExists = await database.PlayLists
|
||||
.AsNoTracking()
|
||||
|
||||
@@ -10,12 +10,12 @@ using Musify.Application.Contracts;
|
||||
namespace Musify.Application.PlayLists
|
||||
{
|
||||
public record GetPlayListsQuery(int PageNumber, int PageSize)
|
||||
: IQuery<ErrorOr<PaginatedResponse<PlayListApplicationResponse>> >;
|
||||
: IQuery<ErrorOr<PaginatedResponse<PlayListApplicationResponse>>>;
|
||||
|
||||
public class GetPlayListsQueryHandler(IDatabase database)
|
||||
: IQueryHandler<GetPlayListsQuery, ErrorOr<PaginatedResponse<PlayListApplicationResponse> >>
|
||||
: IQueryHandler<GetPlayListsQuery, ErrorOr<PaginatedResponse<PlayListApplicationResponse>>>
|
||||
{
|
||||
public async ValueTask<ErrorOr<PaginatedResponse<PlayListApplicationResponse> >> Handle(GetPlayListsQuery request, CancellationToken cancellationToken)
|
||||
public async ValueTask<ErrorOr<PaginatedResponse<PlayListApplicationResponse>>> Handle(GetPlayListsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var totalCount = await database.PlayLists.CountAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ namespace Musify.Application.PlayLists
|
||||
int PageNumber,
|
||||
int PageSize,
|
||||
bool OnlyPublic = false)
|
||||
: IQuery<ErrorOr<PaginatedResponse<PlayListApplicationResponse>> >;
|
||||
: IQuery<ErrorOr<PaginatedResponse<PlayListApplicationResponse>>>;
|
||||
|
||||
public class GetPlayListsByUserIdQueryHandler(IDatabase database)
|
||||
: IQueryHandler<GetPlayListsByUserIdQuery, ErrorOr<PaginatedResponse<PlayListApplicationResponse> > >
|
||||
: IQueryHandler<GetPlayListsByUserIdQuery, ErrorOr<PaginatedResponse<PlayListApplicationResponse>>>
|
||||
{
|
||||
public async ValueTask<ErrorOr<PaginatedResponse<PlayListApplicationResponse> >> Handle(GetPlayListsByUserIdQuery request, CancellationToken cancellationToken)
|
||||
public async ValueTask<ErrorOr<PaginatedResponse<PlayListApplicationResponse>>> Handle(GetPlayListsByUserIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var playListsQuery = database.PlayLists
|
||||
.AsNoTracking()
|
||||
@@ -51,7 +51,7 @@ namespace Musify.Application.PlayLists
|
||||
.Take(PlayListApplicationResponse.CoverTrackCount)
|
||||
.Select(plt => plt.TrackId)
|
||||
.ToList()
|
||||
} )
|
||||
})
|
||||
.ToPagedListAsync(request.PageNumber, request.PageSize, totalCount, cancellationToken);
|
||||
|
||||
var pagedPlayLists = new StaticPagedList<PlayListApplicationResponse>(
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Musify.Application.PlayLists
|
||||
var effectiveSizeBytes = request.ExpectedSizeBytes
|
||||
?? uploadIntentConfiguration.DefaultExpectedPictureSizeBytes;
|
||||
|
||||
var objectName = $"{Guid.NewGuid() }.{request.FileType.TrimStart('.').ToLowerInvariant() }";
|
||||
var objectName = $"{Guid.NewGuid()}.{request.FileType.TrimStart('.').ToLowerInvariant()}";
|
||||
|
||||
var tempKey = playListConfiguration.Routes.BuildTempPicturePath(
|
||||
uploadIntentConfiguration.TemporalRootPrefix, request.UserId, objectName);
|
||||
@@ -84,7 +84,7 @@ namespace Musify.Application.PlayLists
|
||||
await database.SaveChangesAsync(cancellationToken);
|
||||
await transaction.CommitAsync(cancellationToken);
|
||||
|
||||
logger.LogInformation("Issued upload intent {IntentId} for user {UserId} (PlayListPicture, temp key: {Key} )", intent.Id, request.UserId, tempKey);
|
||||
logger.LogInformation("Issued upload intent {IntentId} for user {UserId} (PlayListPicture, temp key: {Key})", intent.Id, request.UserId, tempKey);
|
||||
|
||||
return new PlayListPictureUploadResponse(
|
||||
intent.Id,
|
||||
|
||||
@@ -85,9 +85,7 @@ namespace Musify.Application.PlayLists
|
||||
finalPictureKey = playListConfiguration.Routes.BuildOriginalPicturePath(request.UserId, pictureIntent.ObjectName);
|
||||
}
|
||||
|
||||
database.PlayLists.Update(playListEntity);
|
||||
|
||||
if (pictureIntent != null&& finalPictureKey != null)
|
||||
if (pictureIntent != null && finalPictureKey != null)
|
||||
{
|
||||
var publishResult = await PublishUpdatePlayListPictureSourceEventAsync(
|
||||
playListEntity.Id, pictureIntent, finalPictureKey, cancellationToken);
|
||||
@@ -117,7 +115,7 @@ namespace Musify.Application.PlayLists
|
||||
return PlayListApplicationResponse.FromEntity(playListEntity, coverTrackIds);
|
||||
}
|
||||
|
||||
async Task<ErrorOr<Success>> PublishUpdatePlayListPictureSourceEventAsync(
|
||||
private async Task<ErrorOr<Success>> PublishUpdatePlayListPictureSourceEventAsync(
|
||||
Guid playListId,
|
||||
UploadIntent pictureIntent,
|
||||
string finalPictureKey,
|
||||
|
||||
Reference in New Issue
Block a user