Правки админки, вход

This commit is contained in:
Халимов Рустам
2026-03-31 23:55:38 +03:00
parent bce8f92101
commit 2c6d6f831f
13 changed files with 264 additions and 51 deletions

View File

@@ -0,0 +1,17 @@
using Knot.Modules.Conversations.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace Knot.Modules.Conversations.Infrastructure;
[DbContext(typeof(ChatsDbContext))]
public class ChatsDbContextFactory : IDesignTimeDbContextFactory<ChatsDbContext>
{
public ChatsDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<ChatsDbContext>();
optionsBuilder.UseNpgsql("Host=localhost;Database=knot_db;Username=knot;Password=knot_pass");
return new ChatsDbContext(optionsBuilder.Options);
}
}

View File

@@ -18,11 +18,16 @@ namespace Knot.Modules.Conversations.Infrastructure.Persistence;
public sealed class ChatsDbContext : DbContext, Knot.Modules.Conversations.Application.Abstractions.IChatsUnitOfWork, Knot.Contracts.Conversations.Infrastructure.Persistence.IChatsDbContext
{
private readonly IMediator _mediator;
private readonly IEncryptionService _encryptionService;
private readonly IMediator? _mediator;
private readonly IEncryptionService? _encryptionService;
public ChatsDbContext(DbContextOptions<ChatsDbContext> options)
: base(options)
{
}
public ChatsDbContext(DbContextOptions<ChatsDbContext> options, IMediator mediator, IEncryptionService encryptionService)
: base(options)
: this(options)
{
_mediator = mediator;
_encryptionService = encryptionService;
@@ -99,9 +104,12 @@ public sealed class ChatsDbContext : DbContext, Knot.Modules.Conversations.Appli
int result = await base.SaveChangesAsync(cancellationToken);
foreach (var domainEvent in domainEvents)
if (_mediator != null)
{
await _mediator.Publish(domainEvent, cancellationToken);
foreach (var domainEvent in domainEvents)
{
await _mediator.Publish(domainEvent, cancellationToken);
}
}
return result;

View File

@@ -0,0 +1,21 @@
using Knot.Contracts.Conversations.Abstractions;
using Knot.Modules.Conversations.Application.Users.Commands.DeleteUser;
using Knot.Shared.Kernel;
using MediatR;
namespace Knot.Modules.Conversations.Infrastructure.Services;
public sealed class UserDeleterService : IUserDeleterService
{
private readonly ISender _sender;
public UserDeleterService(ISender sender)
{
_sender = sender;
}
public async Task<Result> DeleteUserAsync(Guid userId, CancellationToken cancellationToken)
{
return await _sender.Send(new DeleteUserCommand(userId), cancellationToken);
}
}