Clean up domain entities: shared picture value object, lifecycle and ownership interfaces, explicit tables
This commit is contained in:
@@ -24,7 +24,7 @@ public class AddTrackToPlayListCommandHandler(
|
||||
if (playList == null)
|
||||
return AppErrors.NotFound("PlayList", request.PlayListId);
|
||||
|
||||
if (playList.UserId != request.UserId)
|
||||
if (playList.OwnerUserId != request.UserId)
|
||||
return AppErrors.Forbidden("PlayList", request.PlayListId);
|
||||
|
||||
var trackExists = await database.Tracks
|
||||
|
||||
@@ -17,7 +17,7 @@ public record CreatePlayListCommand(
|
||||
string Name,
|
||||
string? Description,
|
||||
Guid? PictureIntentId,
|
||||
PlaylistVisibility Visibility = PlaylistVisibility.Private)
|
||||
PlayListVisibility Visibility = PlayListVisibility.Private)
|
||||
: ICommand<ErrorOr<PlayListApplicationResponse>>;
|
||||
|
||||
public class CreatePlayListCommandHandler(
|
||||
@@ -30,7 +30,7 @@ public class CreatePlayListCommandHandler(
|
||||
UploadIntentConfiguration uploadIntentConfiguration)
|
||||
: ICommandHandler<CreatePlayListCommand, ErrorOr<PlayListApplicationResponse>>
|
||||
{
|
||||
private sealed record ResolvedPlayListPictures(PlayListPictures? Pictures, UploadIntent? Intent);
|
||||
private sealed record ResolvedPlayListPictures(EntityPictures? Pictures, UploadIntent? Intent);
|
||||
|
||||
public async ValueTask<ErrorOr<PlayListApplicationResponse>> Handle(CreatePlayListCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ public class CreatePlayListCommandHandler(
|
||||
|
||||
var playList = new PlayList
|
||||
{
|
||||
UserId = request.UserId,
|
||||
OwnerUserId = request.UserId,
|
||||
Name = request.Name.Trim(),
|
||||
NormalizedName = request.Name.Trim().ToUpperInvariant(),
|
||||
Description = string.IsNullOrWhiteSpace(request.Description) ? null : request.Description.Trim(),
|
||||
@@ -96,7 +96,7 @@ public class CreatePlayListCommandHandler(
|
||||
if (validation.IsError)
|
||||
return validation.Errors;
|
||||
|
||||
return new ResolvedPlayListPictures(PlayListPictures.Pending(validation.Value.ObjectName), validation.Value);
|
||||
return new ResolvedPlayListPictures(EntityPictures.Pending(validation.Value.ObjectName), validation.Value);
|
||||
}
|
||||
|
||||
private async Task<ErrorOr<Success>> PublishCreatePlayListEventAsync(
|
||||
|
||||
@@ -27,7 +27,7 @@ public class DeletePlayListCommandHandler(
|
||||
return Error.NotFound();
|
||||
}
|
||||
|
||||
if (playList.UserId != request.UserId)
|
||||
if (playList.OwnerUserId != request.UserId)
|
||||
{
|
||||
logger.LogWarning("Playlist {PlayListId} does not belong to user {UserId}", request.PlayListId, request.UserId);
|
||||
return AppErrors.Forbidden("PlayList", request.PlayListId);
|
||||
|
||||
@@ -32,8 +32,8 @@ public class GetPlayListByIdQueryHandler(IDatabase database)
|
||||
if (entry == null)
|
||||
return Error.NotFound();
|
||||
|
||||
if (entry.PlayList.Visibility == PlaylistVisibility.Private
|
||||
&& entry.PlayList.UserId != request.RequestingUserId)
|
||||
if (entry.PlayList.Visibility == PlayListVisibility.Private
|
||||
&& entry.PlayList.OwnerUserId != request.RequestingUserId)
|
||||
{
|
||||
return Error.NotFound();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class GetPlayListCoverQueryHandler(
|
||||
{
|
||||
var owned = await database.PlayLists.AsNoTracking()
|
||||
.Where(e => e.Id == request.PlayListId && e.LifeCycleStatus == LifeCycleStatus.Active)
|
||||
.Select(e => new { OwnerUserId = e.UserId, e.Pictures })
|
||||
.Select(e => new { OwnerUserId = e.OwnerUserId, e.Pictures })
|
||||
.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (owned?.Pictures == null)
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GetPlayListTracksQueryHandler(IDatabase database)
|
||||
.AnyAsync(
|
||||
p => p.Id == request.PlayListId
|
||||
&& p.LifeCycleStatus == LifeCycleStatus.Active
|
||||
&& (p.Visibility == PlaylistVisibility.Public || p.UserId == request.ViewerId),
|
||||
&& (p.Visibility == PlayListVisibility.Public || p.OwnerUserId == request.ViewerId),
|
||||
cancellationToken);
|
||||
if (!playListExists)
|
||||
return Error.NotFound();
|
||||
|
||||
@@ -25,9 +25,9 @@ public class GetPlayListsByUserIdQueryHandler(IDatabase database)
|
||||
{
|
||||
var playListsQuery = database.PlayLists
|
||||
.AsNoTracking()
|
||||
.Where(p => p.UserId == request.UserId
|
||||
.Where(p => p.OwnerUserId == request.UserId
|
||||
&& p.LifeCycleStatus == LifeCycleStatus.Active
|
||||
&& (p.Visibility == PlaylistVisibility.Public || p.UserId == request.ViewerId));
|
||||
&& (p.Visibility == PlayListVisibility.Public || p.OwnerUserId == request.ViewerId));
|
||||
|
||||
if (!string.IsNullOrEmpty(request.Name))
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ public class RemoveTrackFromPlayListCommandHandler(
|
||||
if (playList == null)
|
||||
return AppErrors.NotFound("PlayList", request.PlayListId);
|
||||
|
||||
if (playList.UserId != request.UserId)
|
||||
if (playList.OwnerUserId != request.UserId)
|
||||
return AppErrors.Forbidden("PlayList", request.PlayListId);
|
||||
|
||||
var playListTracks = await database.PlayListHasTracks
|
||||
|
||||
@@ -10,7 +10,7 @@ public record PlayListApplicationResponse(
|
||||
string? SmallImageKeyName,
|
||||
string? MediumImageKeyName,
|
||||
string? LargeImageKeyName,
|
||||
PlaylistVisibility Visibility,
|
||||
PlayListVisibility Visibility,
|
||||
DateTime CreatedAt,
|
||||
DateTime UpdatedAt,
|
||||
IReadOnlyList<Guid> CoverTrackIds)
|
||||
|
||||
@@ -19,7 +19,7 @@ public record UpdatePlayListCommand(
|
||||
string? NewName,
|
||||
string? NewDescription,
|
||||
Guid? NewPictureIntentId,
|
||||
PlaylistVisibility? NewVisibility = null)
|
||||
PlayListVisibility? NewVisibility = null)
|
||||
: ICommand<ErrorOr<PlayListApplicationResponse>>;
|
||||
|
||||
public class UpdatePlayListCommandHandler(
|
||||
@@ -41,7 +41,7 @@ public class UpdatePlayListCommandHandler(
|
||||
return Error.NotFound();
|
||||
}
|
||||
|
||||
if (playListEntity.UserId != request.UserId)
|
||||
if (playListEntity.OwnerUserId != request.UserId)
|
||||
{
|
||||
logger.LogWarning("User {UserId} is not the owner of playlist {PlayListId}", request.UserId, request.PlayListId);
|
||||
return AppErrors.Forbidden("PlayList", request.PlayListId);
|
||||
@@ -72,7 +72,7 @@ public class UpdatePlayListCommandHandler(
|
||||
return validation.Errors;
|
||||
|
||||
var pictureIntent = validation.Value;
|
||||
playListEntity.Pictures = PlayListPictures.Pending(pictureIntent.ObjectName);
|
||||
playListEntity.Pictures = EntityPictures.Pending(pictureIntent.ObjectName);
|
||||
var finalPictureKey = playListConfiguration.Routes.BuildOriginalPicturePath(request.UserId, pictureIntent.ObjectName);
|
||||
|
||||
var publishResult = await PublishUpdatePlayListPictureSourceEventAsync(
|
||||
|
||||
Reference in New Issue
Block a user