Files
Artemy 6d1c53beeb 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.
2026-07-16 19:27:45 +07:00

62 lines
1.9 KiB
C#

using Microsoft.EntityFrameworkCore;
using Govor.Domain;
using Govor.Domain.Models;
using Govor.Domain.Models.Users;
namespace Govor.Application.Friends;
public class FriendshipService : IFriendshipService
{
private readonly GovorDbContext _context;
public FriendshipService(GovorDbContext context)
{
_context = context;
}
public async Task<List<User>> SearchUsersAsync(string query, Guid currentId)
{
if (string.IsNullOrWhiteSpace(query))
{
return [];
}
return await _context.Users
.AsNoTracking()
.Where(u => u.Id != currentId && u.Username.Contains(query))
.Take(5)
.ToListAsync();
}
public async Task<List<User>> GetPotentialFriendsAsync(Guid userId)
{
var pendingFriendships = await _context.Friendships
.AsNoTracking()
.Include(f => f.Requester)
.Include(f => f.Addressee)
.Where(f => (f.RequesterId == userId || f.AddresseeId == userId)
&& f.Status == FriendshipStatus.Pending)
.ToListAsync();
return pendingFriendships
.Select(f => f.RequesterId == userId ? f.Addressee : f.Requester)
.ToList();
}
public async Task<List<User>> GetFriendsAsync(Guid userId)
{
var acceptedFriendships = await _context.Friendships
.AsNoTracking()
.Include(f => f.Requester)
.Include(f => f.Addressee)
.Where(f => (f.RequesterId == userId || f.AddresseeId == userId)
&& f.Status == FriendshipStatus.Accepted)
.ToListAsync();
var friends = acceptedFriendships
.Select(f => f.RequesterId == userId ? f.Addressee : f.Requester)
.ToList();
return friends;
}
}