Add relationships feature and EF migration
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RecNet.Domain.Profiles;
|
||||
|
||||
namespace RecNet.Infrastructure.Persistence.Repositories;
|
||||
|
||||
public class RelationshipRepository(DatabaseContext dbContext) : IRelationshipRepository
|
||||
{
|
||||
public Task<Relationship?> GetAsync(
|
||||
Guid ownerId,
|
||||
Guid profileId,
|
||||
CancellationToken ct = default)
|
||||
=> dbContext.Relationships
|
||||
.FirstOrDefaultAsync(x =>
|
||||
x.OwnerProfileId == ownerId &&
|
||||
x.ProfileId == profileId,
|
||||
ct);
|
||||
|
||||
public async Task<IReadOnlyList<Relationship>> GetAllOwnedRelationships(Guid ownerId, CancellationToken ct = default)
|
||||
=> await dbContext.Relationships
|
||||
.AsNoTracking()
|
||||
.Where(x => x.OwnerProfileId == ownerId)
|
||||
.ToListAsync(ct);
|
||||
|
||||
public async Task AddAsync(
|
||||
Relationship relationship,
|
||||
CancellationToken ct = default)
|
||||
=> await dbContext.Relationships.AddAsync(relationship, ct);
|
||||
|
||||
public Task SaveChangesAsync(CancellationToken ct = default)
|
||||
=> dbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
Reference in New Issue
Block a user