Контракты

This commit is contained in:
Халимов Рустам
2026-03-29 23:39:17 +03:00
parent 22bc964f27
commit 0209802e9e
141 changed files with 1292 additions and 725 deletions
@@ -1,7 +1,6 @@
using Knot.Modules.Conversations.Domain;
using Knot.Modules.Conversations.Application.Abstractions;
using Knot.Modules.Settings.Application.Settings.Abstractions;
using Knot.Modules.Settings.Application.Settings.DTOs;
using Knot.Modules.Settings.Contracts.Application.Abstractions;
using Knot.Shared.Kernel;
using MediatR;
@@ -49,4 +48,3 @@ internal sealed class AddToFolderCommandHandler : ICommandHandler<AddToFolderCom
return Result.Success();
}
}
@@ -2,14 +2,13 @@ using Knot.Modules.Messaging.Application.Abstractions;
using Knot.Modules.Messaging.Domain;
using Knot.Modules.Conversations.Domain;
using Knot.Shared.Kernel;
using Knot.Modules.Settings.Application.Settings.Abstractions;
using Knot.Modules.Settings.Application.Settings.DTOs;
using Knot.Modules.Settings.Contracts.Application.Abstractions;
using Knot.Modules.Conversations.Application.Abstractions;
namespace Knot.Modules.Conversations.Application.Messages.Send;
/// <summary>
/// Команда для отправки сообщения в чат.
/// Êîìàíäà äëÿ îòïðàâêè ñîîáùåíèÿ â ÷àò.
/// </summary>
public record AttachmentRequest(string Type, string Url, string? FileName, long? FileSize);
@@ -54,20 +53,20 @@ public sealed class SendMessageCommandHandler : ICommandHandler<SendMessageComma
public async Task<Result<Guid>> Handle(SendMessageCommand request, CancellationToken cancellationToken)
{
// 1. Проверяем существование чата
// 1. Ïðîâåðÿåì ñóùåñòâîâàíèå ÷àòà
var chat = await _chatRepository.GetByIdAsync(request.ChatId, cancellationToken);
if (chat is null)
{
return Result.Failure<Guid>(ChatErrors.ChatsNotFound);
}
// 2. Проверяем, является ли отправитель участником
// 2. Ïðîâåðÿåì, ÿâëÿåòñÿ ëè îòïðàâèòåëü ó÷àñòíèêîì
if (!chat.Members.Any(m => m.UserId == request.SenderId))
{
return Result.Failure<Guid>(ChatErrors.ChatsForbidden);
}
// 3. Создаем сообщение
// 3. Ñîçäàåì ñîîáùåíèå
Message message;
if (request.Type == "story_reply" || request.Type == "story_reaction")
{
@@ -143,7 +142,7 @@ public sealed class SendMessageCommandHandler : ICommandHandler<SendMessageComma
false);
}
// 4. Последовательность сообщений High-Water Mark
// 4. Ïîñëåäîâàòåëüíîñòü ñîîáùåíèé High-Water Mark
chat.IncrementSequenceId();
message.SetSequenceId(chat.LastMessageSequenceId);
@@ -151,7 +150,7 @@ public sealed class SendMessageCommandHandler : ICommandHandler<SendMessageComma
senderMember.UpdateReadCursor(message.Id, message.SequenceId);
senderMember.UpdateDeliveredCursor(message.Id);
// 5. Сохраняем
// 5. Ñîõðàíÿåì
_messageRepository.Add(message);
await _unitOfWork.SaveChangesAsync(cancellationToken);
@@ -165,7 +164,3 @@ public sealed class SendMessageCommandHandler : ICommandHandler<SendMessageComma
return Result.Success(message.Id);
}
}
@@ -6,8 +6,8 @@ using System.Threading.Tasks;
using MediatR;
using Knot.Shared.Kernel;
using Knot.Shared.Kernel.Storage;
using Knot.Modules.Settings.Application.Settings.Abstractions;
using Knot.Modules.Settings.Application.Settings.DTOs;
using Knot.Modules.Settings.Contracts.Application.Abstractions;
using Knot.Modules.Settings.Contracts.Application.DTOs;
using Knot.Modules.Conversations.Application.DTOs;
namespace Knot.Modules.Conversations.Application.Messages.UploadFile;
@@ -1,4 +1,5 @@
using Knot.Modules.Auth.Domain;
using Knot.Modules.Auth.Contracts.Domain;
using Knot.Modules.Auth.Contracts.Application.Abstractions;
using Knot.Modules.Conversations.Domain;
using Knot.Modules.Messaging.Domain;
using Knot.Shared.Kernel;
@@ -6,7 +7,6 @@ using Knot.Shared.Kernel.Storage;
using MediatR;
using System.Text.RegularExpressions;
using Knot.Modules.Conversations.Application.Abstractions;
using Knot.Modules.Auth.Application.Abstractions;
namespace Knot.Modules.Conversations.Application.Users.Commands.DeleteUser;
@@ -80,7 +80,7 @@ internal sealed class DeleteUserCommandHandler : ICommandHandler<DeleteUserComma
_userChatSettingsRepository.RemoveRange(chatSettings);
// 4. Delete User (Postgres - Auth Module)
_userRepository.Remove(user);
await _userRepository.RemoveAsync(user, cancellationToken);
// Commit all
await _unitOfWork.SaveChangesAsync(cancellationToken);
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\Shared\Knot.Shared.Kernel\Knot.Shared.Kernel.csproj" />
<ProjectReference Include="..\..\Contracts\Knot.Modules.Settings.Contracts\Knot.Modules.Settings.Contracts.csproj" />
<ProjectReference Include="..\Messaging\Knot.Modules.Messaging.csproj" />
<ProjectReference Include="..\Auth\Knot.Modules.Auth.csproj" />
</ItemGroup>
@@ -36,5 +37,3 @@
</PropertyGroup>
</Project>
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using Knot.Modules.Conversations.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using Knot.Modules.Conversations.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;