Сборка

This commit is contained in:
Халимов Рустам
2026-03-31 00:16:18 +03:00
parent f1f8f6e012
commit b09e197626
16 changed files with 68 additions and 102 deletions
+14
View File
@@ -1,16 +1,30 @@
using Knot.Modules.Messaging;
using Knot.Shared.Infrastructure;
using Knot.Modules.Auth;
using Knot.Modules.Auth.Presentation.Endpoints;
using Knot.Modules.Profiles;
using Knot.Modules.Profiles.Presentation.Endpoints;
using Knot.Modules.Settings;
using Knot.Modules.Settings.Presentation.Endpoints;
using Knot.Modules.Admin;
using Knot.Modules.Conversations;
using Knot.Modules.Conversations.Infrastructure.SignalR;
using Knot.Modules.Conversations.Presentation.Endpoints;
using Knot.Modules.Auth.Infrastructure.Persistence;
using Knot.Modules.Conversations.Infrastructure.Persistence;
using Knot.Modules.Storage;
using Knot.Modules.Stories;
using Knot.Modules.Stories.Presentation.Endpoints;
using Knot.Modules.Klipy;
using Knot.Modules.Federation;
using Knot.Modules.WebRtc;
using Knot.Modules.WebRtc.Presentation.Endpoints;
using Knot.Modules.TelegramImport;
using Knot.Modules.TelegramImport.Presentation.Endpoints;
using Knot.Modules.Relations;
using Knot.Modules.Relations.Presentation.Endpoints;
using Host.Endpoints;
using Knot.Host.Presentation.Endpoints;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
@@ -1,6 +1,6 @@
using Knot.Shared.Kernel;
using Knot.Contracts.Auth.Domain;
using Knot.Contracts.Auth.Application.Auth.DTOs;
using Knot.Contracts.Auth.Application.Auth.DTOs;
using Knot.Shared.Kernel;
namespace Knot.Modules.Auth.Application.Users.GetMe;
@@ -1,7 +1,6 @@
using BCrypt.Net;
using Knot.Contracts.Auth.Application.Abstractions;
using Knot.Contracts.Auth.Application.Auth.DTOs;
using Knot.Contracts.Auth.Domain;
using Knot.Shared.Kernel;
namespace Knot.Modules.Auth.Application.Users.Login;
@@ -1,16 +1,16 @@
using Knot.Contracts.Auth.Domain;
using BCrypt.Net;
using BCrypt.Net;
using Knot.Contracts.Auth.Application.Abstractions;
using Knot.Contracts.Auth.Application.Auth.DTOs;
using Knot.Modules.Auth.Domain;
using Knot.Shared.Kernel;
using Knot.Contracts.Settings.Application.Abstractions;
using Knot.Contracts.Settings.Application.DTOs;
using BCrypt.Net;
using Knot.Modules.Auth.Domain;
using Knot.Shared.Kernel;
namespace Knot.Modules.Auth.Application.Users.Register;
/// <summary>
/// Êîìàíäà äëÿ ðåãèñòðàöèè íîâîãî ïîëüçîâàòåëÿ.
/// .
/// </summary>
public sealed record RegisterUserCommand(
string Username,
@@ -20,7 +20,7 @@ public sealed record RegisterUserCommand(
string? Bio) : ICommand<AuthResponseDto>;
/// <summary>
/// Îáðàáîò÷èê êîìàíäû ðåãèñòðàöèè.
/// .
/// </summary>
internal sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserCommand, AuthResponseDto>
{
@@ -48,16 +48,16 @@ internal sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserC
return Result.Failure<AuthResponseDto>(AuthErrors.IdentityRegistrationDisabled);
}
// 1. Ïðîâåðêà óíèêàëüíîñòè username
// 1. username
if (!await _userRepository.IsUsernameUniqueAsync(request.Username, cancellationToken))
{
return Result.Failure<AuthResponseDto>(AuthErrors.IdentityUsernameNotUnique);
}
// 2. Õåøèðîâàíèå ïàðîëÿ
// 2.
string passwordHash = BCrypt.Net.BCrypt.HashPassword(request.Password);
// 3. Ñîçäàíèå ñóùíîñòè
// 3.
var user = User.Create(
request.Username,
passwordHash,
@@ -65,10 +65,10 @@ internal sealed class RegisterUserCommandHandler : ICommandHandler<RegisterUserC
request.Email,
request.Bio);
// 4. Ñîõðàíåíèå - èñïîëüçóåì ìåòîä ñ Domain User
// 4. - Domain User
var repoWithDomainUserAdd = _userRepository as Infrastructure.Persistence.UserRepository;
repoWithDomainUserAdd?.Add(user);
await _unitOfWork.SaveChangesAsync(cancellationToken);
string token = _tokenProvider.Generate(user.Id, user.Username, user.DisplayName, user.Avatar);
@@ -24,7 +24,7 @@ public static class DependencyInjection
services.AddScoped<IAuthUnitOfWork>(sp => sp.GetRequiredService<AuthDbContext>());
services.AddScoped<Knot.Contracts.Auth.Application.Abstractions.IAuthDbContext>(sp => sp.GetRequiredService<AuthDbContext>());
services.AddScoped<Knot.Contracts.Auth.Infrastructure.Persistence.IAuthDbContext>(sp => sp.GetRequiredService<AuthDbContext>());
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<Knot.Contracts.Auth.Domain.IUserRepository, UserRepository>();
services.AddScoped<IJwtTokenProvider, JwtTokenProvider>();
services.AddScoped<IUserDisplayNameProvider, Knot.Modules.Auth.Infrastructure.Services.UserDisplayNameProvider>();
@@ -1,19 +0,0 @@
using Knot.Modules.Auth.Domain;
namespace Knot.Modules.Auth.Domain;
/// <summary>
/// Интерфейс репозитория для работы с пользователями.
/// </summary>
public interface IUserRepository
{
Task<User?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<List<User>> GetByIdsAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default);
Task<User?> GetByUsernameAsync(string username, CancellationToken cancellationToken = default);
Task<bool> IsUsernameUniqueAsync(string username, CancellationToken cancellationToken = default);
Task<List<User>> SearchUsersAsync(string query, CancellationToken cancellationToken = default);
void Add(User user);
void Update(User user);
void Remove(User user);
}
+4
View File
@@ -0,0 +1,4 @@
// Глобальные алиасы для модуля Auth
// Используем контракты вместо дублирующихся интерфейсов из модуля
global using AuthErrors = Knot.Contracts.Auth.Application.Auth.DTOs.AuthErrors;
global using IUserRepository = Knot.Contracts.Auth.Domain.IUserRepository;
@@ -1,4 +1,3 @@
using Knot.Contracts.Auth.Domain;
using Knot.Shared.Kernel;
namespace Knot.Modules.Auth.Infrastructure.Services;
@@ -10,15 +10,15 @@ public static class DependencyInjection
{
public static IServiceCollection AddProfilesModule(this IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IProfileRepository, ProfileRepository>();
services.AddScoped<IProfilesUnitOfWork, ProfilesUnitOfWork>();
services.AddScoped<IAvatarStorageService, AvatarStorageService>();
services.AddScoped<Knot.Contracts.Profiles.Domain.IProfileRepository, ProfileRepository>();
services.AddScoped<Knot.Contracts.Profiles.Domain.IProfilesUnitOfWork, ProfilesUnitOfWork>();
services.AddScoped<Knot.Contracts.Profiles.Domain.IAvatarStorageService, AvatarStorageService>();
// MongoDB Registration
var mongoConnection = configuration.GetConnectionString("MongoConnection")
?? configuration["MONGO_URL"]
var mongoConnection = configuration.GetConnectionString("MongoConnection")
?? configuration["MONGO_URL"]
?? "mongodb://mongo:27017";
var mongoClient = new MongoClient(mongoConnection);
var databaseName = new MongoUrl(mongoConnection).DatabaseName ?? "knot_messager";
var database = mongoClient.GetDatabase(databaseName);
@@ -1,11 +0,0 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Knot.Modules.Profiles.Domain;
public interface IAvatarStorageService
{
Task<string> UploadAsync(Stream content, string fileName, string contentType, CancellationToken ct = default);
Task DeleteAsync(string fileId, CancellationToken ct = default);
}
@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Knot.Modules.Profiles.Domain;
public interface IProfileRepository
{
Task<ProfileDocument?> GetByIdAsync(Guid id, CancellationToken ct = default);
Task<ProfileDocument?> GetByUsernameAsync(string username, CancellationToken ct = default);
Task AddAsync(ProfileDocument profile, CancellationToken ct = default);
Task UpdateAsync(ProfileDocument profile, CancellationToken ct = default);
Task<List<ProfileDocument>> SearchAsync(string query, CancellationToken ct = default);
}
@@ -1,9 +0,0 @@
using System.Threading;
using System.Threading.Tasks;
namespace Knot.Modules.Profiles.Domain;
public interface IProfilesUnitOfWork
{
Task SaveChangesAsync(CancellationToken ct = default);
}
@@ -1,10 +0,0 @@
namespace Knot.Modules.Profiles.Domain;
using Knot.Shared.Kernel;
public static class ProfilesErrors
{
public static readonly Error ProfileNotFound = new("Profile.NotFound", "Profile not found");
}
public static class IdentityErrors
{
public static readonly Error UserNotFound = new("Profile.NotFound", "Profile not found");
}
+26 -12
View File
@@ -1,18 +1,32 @@
global using System;
global using System;
global using System.Collections.Generic;
global using System.Collections.Generic;
global using System.IO;
global using System.IO;
global using System.Linq;
global using System.Linq;
global using System.Threading;
global using System.Threading;
global using System.Threading.Tasks;
global using System.Threading.Tasks;
global using Knot.Modules.Profiles.Domain;
global using Knot.Modules.Profiles.Domain;
global using Knot.Modules.Profiles.Domain.Events;
global using Knot.Modules.Profiles.Domain.Events;
global using Knot.Modules.Profiles.Infrastructure.Database;
global using Knot.Modules.Profiles.Infrastructure.Database;
global using Knot.Shared.Kernel;
global using Knot.Shared.Kernel.Events;
global using Knot.Shared.Kernel.Storage;
global using Knot.Modules.Profiles.Domain;
global using Knot.Modules.Profiles.Domain.Events;
global using Knot.Modules.Profiles.Infrastructure.Database;
global using MediatR;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using MongoDB.Bson;
global using MongoDB.Bson.Serialization.Attributes;
global using MongoDB.Driver;
global using MediatR;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Configuration;
global using System;
global using System.Collections.Generic;
global using System.Threading;
global using System.Threading.Tasks;
global using System.IO;
global using System.Linq;
global using IAvatarStorageService = Knot.Contracts.Profiles.Domain.IAvatarStorageService;
// Алиасы для использования контрактов вместо дублирующихся интерфейсов модуля
global using IProfileRepository = Knot.Contracts.Profiles.Domain.IProfileRepository;
global using IProfilesUnitOfWork = Knot.Contracts.Profiles.Domain.IProfilesUnitOfWork;
global using ProfilesErrors = Knot.Contracts.Profiles.Application.DTOs.ProfilesErrors;
@@ -3,12 +3,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Profiles.Domain;
using Knot.Contracts.Profiles.Application.DTOs;
using Knot.Contracts.Profiles.Domain;
using Knot.Modules.Profiles.Domain;
using Knot.Modules.Profiles.Infrastructure.Mappings;
using Knot.Shared.Kernel;
using ProfilesErrors = Knot.Contracts.Profiles.Application.DTOs.ProfilesErrors;
using MongoDB.Bson;
using MongoDB.Driver;
@@ -1,8 +1,9 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Knot.Contracts.Relations.Domain;
using Knot.Modules.Stories.Domain;
using Knot.Modules.Relations.Domain;
using Microsoft.EntityFrameworkCore;
namespace Knot.Modules.Stories.Application.Abstractions;