38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
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();
|
|
}
|
|
}
|