Структура, доп модули, федерация, документация
This commit is contained in:
@@ -25,13 +25,13 @@ public sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserCom
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IAuthUnitOfWork _unitOfWork;
|
||||
private readonly ISettingsService _settings;
|
||||
private readonly ISystemSettings _settings;
|
||||
private readonly IJwtTokenProvider _tokenProvider;
|
||||
|
||||
public RegisterUserCommandHandler(
|
||||
IUserRepository userRepository,
|
||||
IAuthUnitOfWork unitOfWork,
|
||||
ISettingsService settings,
|
||||
ISystemSettings settings,
|
||||
IJwtTokenProvider tokenProvider)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
|
||||
@@ -14,5 +14,6 @@ public interface IUserRepository
|
||||
Task<List<User>> SearchUsersAsync(string query, CancellationToken cancellationToken = default);
|
||||
void Add(User user);
|
||||
void Update(User user);
|
||||
void Remove(User user);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ using Knot.Shared.Kernel;
|
||||
|
||||
namespace Knot.Modules.Auth.Domain;
|
||||
|
||||
public sealed record UserStatusChangedDomainEvent(Guid UserId, bool IsOnline, DateTime LastSeen) : IDomainEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность пользователя в контексте идентификации (Identity).
|
||||
/// </summary>
|
||||
@@ -16,6 +18,11 @@ public sealed class User : AggregateRoot<Guid>
|
||||
public DateTime? Birthday { get; private set; }
|
||||
public DateTime CreatedAt { get; private set; }
|
||||
public bool HideStoryViews { get; private set; }
|
||||
public bool IsExternal { get; private set; }
|
||||
public string? Domain { get; private set; }
|
||||
public bool IsOnline { get; private set; }
|
||||
public DateTime? LastSeen { get; private set; }
|
||||
public bool HideStatus { get; private set; }
|
||||
|
||||
private User(Guid id, string username, string passwordHash, string displayName, string? email, string? bio = null)
|
||||
: base(id)
|
||||
@@ -36,6 +43,18 @@ public sealed class User : AggregateRoot<Guid>
|
||||
return new User(Guid.NewGuid(), username, passwordHash, displayName, email, bio);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создает "теневого" пользователя для контакта с другого сервера.
|
||||
/// </summary>
|
||||
public static User CreateExternal(Guid id, string username, string displayName, string domain, string? avatar = null)
|
||||
{
|
||||
var user = new User(id, username, "EXTERNAL_USER", displayName, null, null);
|
||||
user.IsExternal = true;
|
||||
user.Domain = domain;
|
||||
user.Avatar = avatar;
|
||||
return user;
|
||||
}
|
||||
|
||||
public void UpdateProfile(string displayName, string? bio, DateTime? birthday)
|
||||
{
|
||||
DisplayName = displayName;
|
||||
@@ -57,5 +76,21 @@ public sealed class User : AggregateRoot<Guid>
|
||||
{
|
||||
PasswordHash = newPasswordHash;
|
||||
}
|
||||
|
||||
public void UpdateStatus(bool isOnline)
|
||||
{
|
||||
IsOnline = isOnline;
|
||||
LastSeen = DateTime.UtcNow;
|
||||
|
||||
if (!HideStatus)
|
||||
{
|
||||
RaiseDomainEvent(new UserStatusChangedDomainEvent(Id, IsOnline, LastSeen.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHideStatus(bool hide)
|
||||
{
|
||||
HideStatus = hide;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,5 +53,10 @@ public sealed class UserRepository : IUserRepository
|
||||
{
|
||||
_context.Users.Update(user);
|
||||
}
|
||||
|
||||
public void Remove(User user)
|
||||
{
|
||||
_context.Users.Remove(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user