97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using UserService.DatabaseLayer.DataModels;
|
|
|
|
namespace UserService.DatabaseLayer.Repository
|
|
{
|
|
public class OrganizationUnitsRepository : BaseRepository<OrganizationUnit>, IOrganizationUnitsRepository
|
|
{
|
|
public OrganizationUnitsRepository() : base(x => x.OrganizationUnits)
|
|
{
|
|
}
|
|
}
|
|
|
|
public class SecurityGroupsRepository : BaseRepository<SecurityGroup>, ISecurityGroupsRepository
|
|
{
|
|
public SecurityGroupsRepository() : base(x=> x.SecurityGroups)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
public class UsersRepository : BaseRepository<User>, IUsersRepository
|
|
{
|
|
public UsersRepository() : base(x => x.Users)
|
|
{
|
|
}
|
|
}
|
|
|
|
public class NodesRepository : INodesRepository
|
|
{
|
|
private readonly IUsersRepository _users;
|
|
private readonly ISecurityGroupsRepository _securityGroups;
|
|
private readonly IOrganizationUnitsRepository _organizationUnits;
|
|
|
|
public NodesRepository(IUsersRepository users, ISecurityGroupsRepository securityGroups, IOrganizationUnitsRepository organizationUnits)
|
|
{
|
|
_users = users;
|
|
_securityGroups = securityGroups;
|
|
_organizationUnits = organizationUnits;
|
|
}
|
|
|
|
public static async IAsyncEnumerable<Node> GetNodesAsync([EnumeratorCancellation] CancellationToken token = default)
|
|
{
|
|
await using var db = new UserServiceDbContext();
|
|
await foreach (var note in db.OrganizationUnits.AsAsyncEnumerable().WithCancellation(token))
|
|
{
|
|
yield return note;
|
|
}
|
|
await foreach (var node in db.SecurityGroups.AsAsyncEnumerable().WithCancellation(token))
|
|
{
|
|
yield return node;
|
|
}
|
|
|
|
await foreach (var node in db.Users.AsAsyncEnumerable().WithCancellation(token))
|
|
{
|
|
yield return node;
|
|
}
|
|
}
|
|
|
|
public async Task<IReadOnlyList<Node>> GetAllAsync(CancellationToken token = default)
|
|
{
|
|
|
|
var list = new List<Node>();
|
|
await foreach (var node in GetNodesAsync(token))
|
|
{
|
|
list.Add(node);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
public Task<Node?> GetAsync(Expression<Func<Node, bool>> predicate, CancellationToken token = default)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task AddAsync(Node entity, CancellationToken token = default)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task UpdateAsync(Node entity, CancellationToken token = default)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task DeleteAsync(Node entity, CancellationToken token = default)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |