Add shared pagination, projections and ownership helpers; simplify query and command handlers
This commit is contained in:
@@ -1,26 +1,14 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using ErrorOr;
|
||||
using Mediator;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Musify.Application.Contracts;
|
||||
using Musify.Application.Serialization;
|
||||
using Musify.Application.Shared;
|
||||
using Musify.Application.Users.Responses;
|
||||
|
||||
namespace Musify.Application.Users;
|
||||
|
||||
public record GetUserProfileQuery(long UserId, long? ViewerId = null) : IQuery<ErrorOr<UserProfileResponse>>;
|
||||
|
||||
public record UserProfileResponse(
|
||||
[property: JsonConverter(typeof(LongAsStringConverter))] long Id,
|
||||
string Name,
|
||||
string? FirstName,
|
||||
string? SecondName,
|
||||
string? ProfilePictureUrl,
|
||||
DateTime CreatedAt,
|
||||
int FollowersCount,
|
||||
int FollowingCount,
|
||||
bool IsFollowing,
|
||||
bool CanViewFollowers);
|
||||
|
||||
public class GetUserProfileQueryHandler(IDatabase database)
|
||||
: IQueryHandler<GetUserProfileQuery, ErrorOr<UserProfileResponse>>
|
||||
{
|
||||
@@ -41,7 +29,7 @@ public class GetUserProfileQueryHandler(IDatabase database)
|
||||
.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (user == null)
|
||||
return Error.NotFound();
|
||||
return AppErrors.NotFound("User", request.UserId);
|
||||
|
||||
var followersCount = await database.UserFollows
|
||||
.AsNoTracking()
|
||||
|
||||
Reference in New Issue
Block a user