Очистка
This commit is contained in:
@@ -7,5 +7,4 @@ public interface IAuthUnitOfWork : IUnitOfWork
|
||||
{
|
||||
IUserRepository UserRepository { get; }
|
||||
void Add(UserContract user);
|
||||
Task<int> SaveChangesAsync(CancellationToken ct = default);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,4 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Carter" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
|
||||
<_Parameter1>Knot.Modules.Admin.UnitTests</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,12 +1,11 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Contracts.Auth.Application.Abstractions;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Modules.Auth.Infrastructure.Authentication;
|
||||
using Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
using Knot.Shared.Kernel;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Knot.Modules.Auth;
|
||||
|
||||
|
||||
@@ -1,36 +1,77 @@
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Shared.Kernel.Events;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
|
||||
namespace Knot.Modules.Auth.Domain;
|
||||
|
||||
/// <summary>
|
||||
/// Ñóùíîñòü ïîëüçîâàòåëÿ â êîíòåêñòå èäåíòèôèêàöèè (Identity).
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (Identity).
|
||||
/// </summary>
|
||||
public sealed class User : AggregateRoot<Guid>
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Username { get; private set; }
|
||||
public string PasswordHash { get; private set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string DisplayName { get; private set; }
|
||||
public string? Email { get; private set; }
|
||||
public string? Bio { get; private set; }
|
||||
public string? Avatar { get; set; }
|
||||
public string? Avatar { get; private set; }
|
||||
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; set; }
|
||||
public bool IsOnline { get; private set; }
|
||||
public DateTime? LastSeen { get; private set; }
|
||||
public bool HideStatus { get; private set; }
|
||||
public bool IsBanned { get; set; }
|
||||
public string? PhoneNumber { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
public DateTime? BannedUntil { get; set; }
|
||||
public bool IsBanned { get; private set; }
|
||||
public string? PhoneNumber { get; private set; }
|
||||
public string? RefreshToken { get; private set; }
|
||||
public DateTime? BannedUntil { get; private set; }
|
||||
|
||||
public void Ban() => IsBanned = true;
|
||||
public void Unban() => IsBanned = false;
|
||||
|
||||
public void SetOnline(bool isOnline, DateTime? lastSeen = null)
|
||||
{
|
||||
IsOnline = isOnline;
|
||||
LastSeen = lastSeen ?? DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void SetPhoneNumber(string? phoneNumber)
|
||||
{
|
||||
PhoneNumber = phoneNumber;
|
||||
}
|
||||
|
||||
public void SetRefreshToken(string? refreshToken)
|
||||
{
|
||||
RefreshToken = refreshToken;
|
||||
}
|
||||
|
||||
public void SetBannedUntil(DateTime? bannedUntil)
|
||||
{
|
||||
BannedUntil = bannedUntil;
|
||||
}
|
||||
|
||||
public void SetAsExternal(string domain)
|
||||
{
|
||||
IsExternal = true;
|
||||
UserDomain = domain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates user from contract (used by repository).
|
||||
/// </summary>
|
||||
public void UpdateFromContract(UserContract contract)
|
||||
{
|
||||
Username = contract.Username;
|
||||
DisplayName = contract.DisplayName;
|
||||
PhoneNumber = contract.PhoneNumber;
|
||||
IsBanned = contract.IsBanned;
|
||||
BannedUntil = contract.BannedUntil;
|
||||
SetOnline(contract.IsOnline, contract.LastSeen);
|
||||
UserDomain = contract.Domain;
|
||||
}
|
||||
|
||||
private User(Guid id, string username, string passwordHash, string displayName, string? email, string? bio = null)
|
||||
: base(id)
|
||||
{
|
||||
@@ -44,7 +85,7 @@ public sealed class User : AggregateRoot<Guid>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ôàáðè÷íûé ìåòîä äëÿ ñîçäàíèÿ íîâîãî ïîëüçîâàòåëÿ.
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
/// </summary>
|
||||
public static User Create(string username, string passwordHash, string displayName, string? email = null, string? bio = null)
|
||||
{
|
||||
@@ -54,14 +95,14 @@ public sealed class User : AggregateRoot<Guid>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ñîçäàåò "òåíåâîãî" ïîëüçîâàòåëÿ äëÿ êîíòàêòà ñ äðóãîãî ñåðâåðà.
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
/// </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;
|
||||
user.SetAsExternal(domain);
|
||||
if (avatar != null)
|
||||
user.UpdateAvatar(avatar);
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -98,7 +139,8 @@ public sealed class User : AggregateRoot<Guid>
|
||||
{
|
||||
IsOnline = isOnline;
|
||||
LastSeen = DateTime.UtcNow;
|
||||
|
||||
|
||||
|
||||
if (!HideStatus)
|
||||
{
|
||||
RaiseDomainEvent(new UserStatusChangedDomainEvent(Id, IsOnline, LastSeen.Value));
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Knot.Contracts.Auth.Application.Abstractions;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Shared.Kernel.Security;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using DomainUser = Knot.Modules.Auth.Domain.User;
|
||||
|
||||
namespace Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
@@ -76,9 +76,5 @@ public sealed class AuthDbContext : DbContext, IAuthUnitOfWork, IAuthDbContext
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async Task<int> IAuthUnitOfWork.SaveChangesAsync(CancellationToken ct)
|
||||
{
|
||||
return await SaveChangesAsync(ct);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Modules.Auth.Domain;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Knot.Modules.Auth.Infrastructure.Persistence;
|
||||
|
||||
@@ -63,13 +63,7 @@ internal sealed class UserRepository : IUserRepository
|
||||
var domainUser = await _context.Users.FirstOrDefaultAsync(u => u.Id == user.Id, cancellationToken);
|
||||
if (domainUser != null)
|
||||
{
|
||||
domainUser.Username = user.Username;
|
||||
domainUser.DisplayName = user.DisplayName;
|
||||
domainUser.PhoneNumber = user.PhoneNumber;
|
||||
domainUser.IsBanned = user.IsBanned;
|
||||
domainUser.BannedUntil = user.BannedUntil;
|
||||
domainUser.IsOnline = user.IsOnline;
|
||||
domainUser.UserDomain = user.Domain;
|
||||
domainUser.UpdateFromContract(user);
|
||||
_context.Users.Update(domainUser);
|
||||
}
|
||||
}
|
||||
@@ -109,13 +103,7 @@ internal sealed class UserRepository : IUserRepository
|
||||
var domainUser = _context.Users.Find(user.Id);
|
||||
if (domainUser != null)
|
||||
{
|
||||
domainUser.Username = user.Username;
|
||||
domainUser.DisplayName = user.DisplayName;
|
||||
domainUser.PhoneNumber = user.PhoneNumber;
|
||||
domainUser.IsBanned = user.IsBanned;
|
||||
domainUser.BannedUntil = user.BannedUntil;
|
||||
domainUser.IsOnline = user.IsOnline;
|
||||
domainUser.UserDomain = user.Domain;
|
||||
domainUser.UpdateFromContract(user);
|
||||
_context.Users.Update(domainUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Shared.Kernel;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
using Knot.Contracts.Auth.Domain;
|
||||
|
||||
namespace Knot.Modules.Auth.Infrastructure.Services;
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="Knot.Modules.Conversations.UnitTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="Knot.Modules.Profiles.UnitTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,11 +1,34 @@
|
||||
namespace Knot.Modules.Relations.Domain;
|
||||
|
||||
using System;
|
||||
|
||||
public class UserReplica
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Avatar { get; set; }
|
||||
public bool IsExternal { get; set; }
|
||||
public string? Domain { get; set; }
|
||||
public Guid Id { get; init; }
|
||||
public string Username { get; init; } = string.Empty;
|
||||
public string DisplayName { get; init; } = string.Empty;
|
||||
public string Avatar { get; init; } = string.Empty;
|
||||
public bool IsExternal { get; init; }
|
||||
public string? Domain { get; init; }
|
||||
|
||||
private UserReplica() { }
|
||||
|
||||
public static UserReplica Create(
|
||||
Guid id,
|
||||
string username,
|
||||
string displayName,
|
||||
string avatar,
|
||||
bool isExternal,
|
||||
string? domain)
|
||||
{
|
||||
return new UserReplica
|
||||
{
|
||||
Id = id,
|
||||
Username = username,
|
||||
DisplayName = displayName,
|
||||
Avatar = avatar,
|
||||
IsExternal = isExternal,
|
||||
Domain = domain
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Knot.Modules.Stories.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Knot.IntegrationTests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
|
||||
Reference in New Issue
Block a user