38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using ContactService.Domain;
|
|
using ContactService.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ContactService.Infrastructure
|
|
{
|
|
public class FriendRequestReposity : IFriendRequestReposity
|
|
{
|
|
private readonly ContactDbContext db;
|
|
|
|
public FriendRequestReposity(ContactDbContext db)
|
|
{
|
|
this.db = db;
|
|
}
|
|
|
|
public async Task<bool> CreateAsync(FriendRequest friendRequest)
|
|
{
|
|
db.Add(friendRequest);
|
|
return true;
|
|
}
|
|
|
|
public Task<FriendRequest?> FindByIdAsync(Guid id)
|
|
{
|
|
return db.FriendRequests.FirstOrDefaultAsync(x => x.Id == id);
|
|
}
|
|
|
|
public async Task<IEnumerable<FriendRequest>> FindByOwnerIdAsync(Guid ownerId)
|
|
{
|
|
return await db.FriendRequests.Where(x => x.OwnerId == ownerId).ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<FriendRequest>> FindByTargetIdAsync(Guid targetId)
|
|
{
|
|
return await db.FriendRequests.Where(x => x.TargetId == targetId).ToListAsync();
|
|
}
|
|
}
|
|
}
|