Refactor: migrate Core -> Domain and reorganize projects

Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
This commit is contained in:
Artemy
2026-07-16 19:27:45 +07:00
parent 1d35356c8c
commit 6d1c53beeb
371 changed files with 2729 additions and 6694 deletions
+15 -11
View File
@@ -1,11 +1,11 @@
using Govor.API.Common.SignalR.Helpers;
using Govor.API.Hubs.Infrastructure;
using Govor.Application.Exceptions.VerifyFriendship;
using Govor.Application.Interfaces.Messages;
using Govor.Application.Interfaces.Messages.Parameters;
using Govor.Application.Messages;
using Govor.Application.Messages.Parameters;
using Govor.Contracts.Requests.SignalR;
using Govor.Contracts.Responses.SignalR;
using Govor.Core.Models.Messages;
using Govor.Domain.Models.Messages;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
@@ -15,20 +15,24 @@ namespace Govor.API.Hubs;
public class ChatsHub : Hub
{
private readonly ILogger<ChatsHub> _logger;
private readonly IMessageCommandService _commandService;
private readonly IMessageSendingService _messageSendingService;
private readonly IMessageEditingService _messageEditingService;
private readonly IMessageRemovingService _messageRemovingService;
private readonly IHubUserAccessor _userAccessor;
private readonly IChatNotificationService _notifier;
private readonly IConnectionManager _connectionManager;
public ChatsHub(
ILogger<ChatsHub> logger,
IMessageCommandService commandService,
public ChatsHub(ILogger<ChatsHub> logger,
IMessageSendingService messageSendingService,
IMessageEditingService messageEditingService,
IHubUserAccessor userAccessor,
IChatNotificationService notifier,
IConnectionManager connectionManager)
{
_logger = logger;
_commandService = commandService;
_messageSendingService = messageSendingService;
_messageEditingService = messageEditingService;
_userAccessor = userAccessor;
_notifier = notifier;
_connectionManager = connectionManager;
@@ -69,7 +73,7 @@ public class ChatsHub : Hub
ValidateMessageRequest(request);
var sendParams = MapToSendMessage(request, userId);
var result = await _commandService.SendMessageAsync(sendParams);
var result = await _messageSendingService.SendMessageAsync(sendParams);
if (!result.IsSuccess)
throw new InvalidOperationException(result.Exception.Message ?? "Failed to send message");
@@ -87,7 +91,7 @@ public class ChatsHub : Hub
{
return await SafeExecute(async (userId) =>
{
var result = await _commandService.DeleteMessageAsync(new DeleteMessage(userId, request.MessageId));
var result = await _messageRemovingService.DeleteMessageAsync(new DeleteMessage(userId, request.MessageId));
if (!result.IsSuccess || result.OriginalMessage == null)
throw new InvalidOperationException("Message deletion failed");
@@ -112,7 +116,7 @@ public class ChatsHub : Hub
return await SafeExecute(async (userId) =>
{
var editParams = new EditMessage(userId, request.MessageId, request.NewEncryptedContent, DateTime.UtcNow);
var result = await _commandService.EditMessageAsync(editParams);
var result = await _messageEditingService.EditMessageAsync(editParams);
if (!result.IsSuccess || result.OriginalMessage == null)
throw new InvalidOperationException("Edit message error");
+21 -4
View File
@@ -1,7 +1,7 @@
using AutoMapper;
using Govor.API.Common.SignalR.Helpers;
using Govor.Application.Exceptions.FriendsService;
using Govor.Application.Interfaces.Friends;
using Govor.Application.Friends;
using Govor.Contracts.DTOs;
using Govor.Contracts.Responses.SignalR;
using Microsoft.AspNetCore.SignalR;
@@ -76,7 +76,12 @@ public class FriendsHub : Hub
try
{
var userId = _userAccessor.GetUserId(Context);
var friendship = await _friendRequestService.SendAsync(userId, targetUserId);
var result = await _friendRequestService.SendAsync(userId, targetUserId);
if(result.IsFailure)
return HubResult<object>.Error(result.Error.ToString());
var friendship = result.Value;
var dto = _mapper.Map<FriendshipDto>(friendship);
await Clients.Group(targetUserId.ToString())
@@ -115,7 +120,13 @@ public class FriendsHub : Hub
try
{
var userId = _userAccessor.GetUserId(Context);
var friendship = await _friendRequestService.AcceptAsync(friendshipId, userId);
var result = await _friendRequestService.AcceptAsync(friendshipId, userId);
if(result.IsFailure)
return HubResult<object>.BadRequest(result.Error.ToString());
var friendship = result.Value;
var dto = _mapper.Map<FriendshipDto>(friendship);
await Clients.Group(userId.ToString())
@@ -149,7 +160,13 @@ public class FriendsHub : Hub
try
{
var userId = _userAccessor.GetUserId(Context);
var friendship = await _friendRequestService.RejectAsync(friendshipId, userId);
var result = await _friendRequestService.RejectAsync(friendshipId, userId);
if(result.IsFailure)
return HubResult<object>.BadRequest(result.Error.ToString());
var friendship = result.Value;
var dto = _mapper.Map<FriendshipDto>(friendship);
await Clients.Group(userId.ToString())
@@ -1,9 +1,8 @@
using Govor.Application.Interfaces;
using Govor.Application.Interfaces.PushNotifications;
using Govor.Application.PrivateUserChats;
using Govor.Application.Profiles;
using Govor.Application.PushNotifications;
using Govor.Contracts.Responses.SignalR;
using Govor.Core.Models.Messages;
using Govor.Core.Repositories.PrivateChats;
using Govor.Core.Repositories.PushTokens;
using Govor.Domain.Models.Messages;
using Microsoft.AspNetCore.SignalR;
namespace Govor.API.Hubs.Infrastructure;
@@ -11,19 +10,20 @@ namespace Govor.API.Hubs.Infrastructure;
public class ChatNotificationService : IChatNotificationService
{
private readonly IHubContext<ChatsHub> _hubContext;
private readonly IPrivateChatsRepository _privateChatsRepository;
private readonly IPushNotificationService _notificationService;
private readonly IUserPrivateChatsGetterService _userPrivateChatsGetterService;
private readonly IProfileService _profileService;
public ChatNotificationService(
IProfileService profileService,
IHubContext<ChatsHub> hubContext,
IHubContext<ChatsHub> hubContext,
IPushNotificationService notificationService,
IPrivateChatsRepository privateChatsRepository)
IUserPrivateChatsGetterService userPrivateChatsGetterService,
IProfileService profileService)
{
_hubContext = hubContext;
_profileService = profileService;
_notificationService = notificationService;
_privateChatsRepository = privateChatsRepository;
_userPrivateChatsGetterService = userPrivateChatsGetterService;
_profileService = profileService;
}
public async Task NotifyMessageSentAsync(UserMessageResponse message)
@@ -47,12 +47,22 @@ public class ChatNotificationService : IChatNotificationService
private async Task NotifyMessageReceivedInPrivateChatAsync(UserMessageResponse message)
{
var privateChat = await _privateChatsRepository.GetByIdAsync(message.RecipientId);
var result = await _userPrivateChatsGetterService.GetPrivateChatAsync(message.RecipientId);
if(result.IsFailure)
return;
var privateChat = result.Value;
var text = message.EncryptedContent.Substring(0, Math.Min(40, message.EncryptedContent.Length));
var userId = message.SenderId == privateChat.UserAId ? privateChat.UserBId : privateChat.UserAId;
var profile = await _profileService.GetUserProfileAsync(message.SenderId);
var resultProf = await _profileService.GetUserProfileAsync(message.SenderId);
if(resultProf.IsFailure)
return;
var profile = resultProf.Value;
var title = profile.Username;
Dictionary<string, string> data = new Dictionary<string, string>();
@@ -1,5 +1,8 @@
using System.Collections.Concurrent;
using Govor.Application.Groups;
using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Interfaces;
using Govor.Application.PrivateUserChats;
using Microsoft.AspNetCore.SignalR;
namespace Govor.API.Hubs.Infrastructure;
@@ -1,5 +1,5 @@
using System.Collections.Concurrent;
using Govor.Application.Interfaces;
using Govor.Application.Infrastructure.Extensions;
namespace Govor.API.Hubs.Infrastructure;
@@ -1,7 +1,9 @@
using Govor.API.Hubs;
using Govor.API.Hubs.Infrastructure;
using Govor.Application.Infrastructure.Extensions;
using Govor.Application.Interfaces;
using Govor.Core.Models;
using Govor.Application.PrivateUserChats;
using Govor.Domain.Models;
using Microsoft.AspNetCore.SignalR;
namespace Govor.API.Hubs.Infrastructure;
+5 -32
View File
@@ -1,6 +1,5 @@
using Govor.API.Common.SignalR.Helpers;
using Govor.Application.Interfaces.UserOnlineStatus;
using Govor.Core.Repositories.Users;
using Govor.Application.Users.UserOnlineStatus;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.SignalR;
@@ -15,17 +14,14 @@ public class PresenceHub : Hub
private readonly IUserNotificationScopeService _scopeService;
private readonly IOnlineUserStore _onlineUserStore;
private readonly IHubUserAccessor _userAccessor;
private readonly IUsersRepository _users;
public PresenceHub(
ILogger<PresenceHub> logger,
IUserNotificationScopeService scopeService,
IOnlineUserStore onlineUserStore,
IHubUserAccessor userAccessor,
IUsersRepository users)
IHubUserAccessor userAccessor)
{
_logger = logger;
_users = users;
_scopeService = scopeService;
_onlineUserStore = onlineUserStore;
_userAccessor = userAccessor;
@@ -79,32 +75,9 @@ public class PresenceHub : Hub
if (isLastConnection)
{
_ = Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(5));
var currentConnections = _onlineUserStore.GetConnections(userId);
if (currentConnections == null || !currentConnections.Any())
{
var friends = await _scopeService.GetNotifiedUsers(userId);
await Clients.Groups(friends.Select(f => f.ToString()).ToList())
.SendAsync("UserOffline", userId);
try
{
var user = await _users.FindByIdAsync(userId);
if (user != null)
{
user.WasOnline = DateTime.UtcNow;
await _users.UpdateAsync(user);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error updating WasOnline for {UserId}", userId);
}
}
});
var friends = await _scopeService.GetNotifiedUsers(userId);
await Clients.Groups(friends.Select(f => f.ToString()).ToList())
.SendAsync("UserOffline", userId);
}
await base.OnDisconnectedAsync(exception);
+4 -7
View File
@@ -1,10 +1,10 @@
using Govor.API.Common.SignalR.Helpers;
using Govor.Application.Interfaces;
using Govor.Application.Interfaces.Friends;
using Govor.Application.Interfaces.Medias;
using Govor.Application.Friends;
using Govor.Application.Medias;
using Govor.Application.Profiles;
using Govor.Application.Synching;
using Govor.Contracts.DTOs;
using Govor.Contracts.Responses.SignalR;
using Govor.Core.Repositories.Groups;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
@@ -13,7 +13,6 @@ namespace Govor.API.Hubs;
[Authorize]
public class ProfileHub : Hub
{
private readonly IGroupsRepository _groupsRepository;
private readonly IFriendshipService _friendsService;
private readonly IProfileService _profileService;
private readonly IHubUserAccessor _userAccessor;
@@ -22,7 +21,6 @@ public class ProfileHub : Hub
private readonly IMediaService _mediaService;
public ProfileHub(
IGroupsRepository groupsRepository,
IFriendshipService friendsService,
IProfileService profileService,
IHubUserAccessor userAccessor,
@@ -30,7 +28,6 @@ public class ProfileHub : Hub
IMediaService mediaService,
ILogger<ProfileHub> logger)
{
_groupsRepository = groupsRepository;
_friendsService = friendsService;
_profileService = profileService;
_userAccessor = userAccessor;