Разделение

This commit is contained in:
Халимов Рустам
2026-03-30 15:35:28 +03:00
parent 465e84e686
commit 09e5cbaa76
57 changed files with 631 additions and 233 deletions

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Knot.Contracts.Relations.Application.Abstractions;
using Knot.Contracts.Relations.Domain;
using Knot.Modules.Relations.Domain;
using Knot.Modules.Relations.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
namespace Knot.Modules.Relations.Application.Abstractions;
internal sealed class FriendshipRepository : IFriendshipRepository
{
private readonly RelationsDbContext _context;
public FriendshipRepository(RelationsDbContext context)
{
_context = context;
}
public async Task<List<Knot.Contracts.Relations.Domain.Friendship>> GetAcceptedFriendshipsAsync(Guid userId, CancellationToken ct = default)
{
var friendships = await _context.Set<Knot.Modules.Relations.Domain.Friendship>()
.Where(f => f.Status == Knot.Contracts.Relations.Domain.FriendshipStatus.Accepted && (f.UserId == userId || f.FriendId == userId))
.ToListAsync(ct);
return friendships.Select(f => new Knot.Contracts.Relations.Domain.Friendship(
f.Id,
f.UserId,
f.FriendId,
f.Status,
f.CreatedAt
)).ToList();
}
}

View File

@@ -1,7 +1,9 @@
using Knot.Contracts.Relations.Application.Abstractions;
using Knot.Modules.Relations.Application.Abstractions;
using Knot.Modules.Relations.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Knot.Modules.Relations.Infrastructure.Persistence;
namespace Knot.Modules.Relations;
@@ -13,6 +15,8 @@ public static class DependencyInjection
services.AddDbContext<RelationsDbContext>(options =>
options.UseNpgsql(connectionString));
services.AddScoped<IFriendshipRepository, FriendshipRepository>();
services.AddMediatR(config =>
config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly));

View File

@@ -1,14 +1,8 @@
using Knot.Contracts.Relations.Domain;
using Knot.Shared.Kernel;
namespace Knot.Modules.Relations.Domain;
public enum FriendshipStatus
{
Pending,
Accepted,
Declined
}
public sealed class Friendship : Entity<Guid>
{
public Guid UserId { get; private set; }

View File

@@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Contracts\Relations\Knot.Contracts.Relations.csproj" />
<ProjectReference Include="..\..\Shared\Knot.Shared.Kernel\Knot.Shared.Kernel.csproj" />
<ProjectReference Include="..\..\Shared\Knot.Shared.Infrastructure\Knot.Shared.Infrastructure.csproj" />
</ItemGroup>
@@ -21,7 +22,6 @@
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ProjectReference Include="..\Settings\Knot.Modules.Settings.csproj" />
</ItemGroup>
</Project>