Правки админки, вход
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user