mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
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:
@@ -0,0 +1,52 @@
|
||||
using Govor.Domain;
|
||||
using Govor.Domain.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Govor.Application.PrivateUserChats;
|
||||
|
||||
public class UserPrivateChatsCreator : IUserPrivateChatsCreator
|
||||
{
|
||||
private readonly GovorDbContext _context;
|
||||
private readonly IPrivateChatGroupManager _privateChatGroupManager;
|
||||
private readonly ILogger<UserPrivateChatsCreator> _logger;
|
||||
|
||||
public UserPrivateChatsCreator(
|
||||
GovorDbContext context,
|
||||
IPrivateChatGroupManager privateChatGroupManager,
|
||||
ILogger<UserPrivateChatsCreator> logger)
|
||||
{
|
||||
_context = context;
|
||||
_privateChatGroupManager = privateChatGroupManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<PrivateChat> CreateAsync(Guid userIdA, Guid userIdB)
|
||||
{
|
||||
var existingChat = await _context.PrivateChats
|
||||
.FirstOrDefaultAsync(c => (c.UserAId == userIdA && c.UserBId == userIdB) ||
|
||||
(c.UserAId == userIdB && c.UserBId == userIdA));
|
||||
|
||||
if (existingChat is null)
|
||||
{
|
||||
var recipientId = Guid.NewGuid();
|
||||
var privateChat = new PrivateChat
|
||||
{
|
||||
Id = recipientId,
|
||||
UserAId = userIdA,
|
||||
UserBId = userIdB
|
||||
};
|
||||
|
||||
await _context.PrivateChats.AddAsync(privateChat);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
await _privateChatGroupManager.AddUsersToPrivateChatGroupAsync(privateChat);
|
||||
|
||||
_logger.LogInformation($"Private chat created with Id: {recipientId} for users {userIdA} and {userIdB}");
|
||||
return privateChat;
|
||||
}
|
||||
|
||||
_logger.LogInformation($"Private chat already exists for {userIdA} and {userIdB}; Returning existing chat...");
|
||||
return existingChat;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user