feat: ReadAsync-Methode zum GroupOfUserRepository für flexible Abfragen hinzufügen
This commit is contained in:
parent
25995e8d48
commit
e80ec2cf8d
@ -1,5 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace DigitalData.UserManager.Domain.Entities
|
||||
|
||||
@ -18,5 +18,11 @@ namespace DigitalData.UserManager.Infrastructure.Contracts
|
||||
Task<IEnumerable<GroupOfUser>> ReadByUsernameAsync(string username);
|
||||
|
||||
Task<IEnumerable<GroupOfUser>> ReadByUserIdAsync(int userId);
|
||||
|
||||
// merge all GroupOfUserRepository-methods conditionally under this method
|
||||
Task<IEnumerable<GroupOfUser>> ReadAsync(
|
||||
bool readOnly = true,
|
||||
bool withGroup = true, bool withUser = true,
|
||||
int? id = null, int? groupId = null, int? userId = null, string? username = null);
|
||||
}
|
||||
}
|
||||
@ -42,5 +42,33 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
public async Task<IEnumerable<GroupOfUser>> ReadByUsernameAsync(string username) => await ReadByUsername(username).ToListAsync();
|
||||
|
||||
public async Task<IEnumerable<GroupOfUser>> ReadByUserIdAsync(int userId) => await ReadByUserId(userId).ToListAsync();
|
||||
|
||||
public async Task<IEnumerable<GroupOfUser>> ReadAsync(
|
||||
bool readOnly = true,
|
||||
bool withGroup = true, bool withUser = true,
|
||||
int? id = null, int? groupId = null, int? userId = null, string? username = null)
|
||||
{
|
||||
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet.AsQueryable();
|
||||
|
||||
if (withGroup)
|
||||
query = query.Include(gou => gou.Group);
|
||||
|
||||
if (withUser)
|
||||
query = query.Include(gou => gou.User);
|
||||
|
||||
if (id is not null)
|
||||
query = query.Where(gou => gou.Id == id);
|
||||
|
||||
if (groupId is not null)
|
||||
query = query.Where(gou => gou.GroupId == groupId);
|
||||
|
||||
if (userId is not null)
|
||||
query = query.Where(gou => gou.UserId == userId);
|
||||
|
||||
if (username is not null)
|
||||
query = query.Where(gou => gou.User!.Username == username);
|
||||
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,8 +8,8 @@ namespace DigitalData.UserManager.Infrastructure.Repositories
|
||||
public class UserRepository<TDbContext> : CRUDRepository<User, int, TDbContext>, IUserRepository
|
||||
where TDbContext : DbContext, IUserManagerDbContext
|
||||
{
|
||||
private IModuleOfUserRepository _moduleOfUserRepo;
|
||||
private IGroupOfUserRepository _groupOfUserRepo;
|
||||
private readonly IModuleOfUserRepository _moduleOfUserRepo;
|
||||
private readonly IGroupOfUserRepository _groupOfUserRepo;
|
||||
public UserRepository(TDbContext dbContext, IModuleOfUserRepository moduleOfUserRepo, IGroupOfUserRepository groupOfUserRepo) : base(dbContext, dbContext.Users)
|
||||
{
|
||||
_moduleOfUserRepo = moduleOfUserRepo;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user