Developer 02 8d88148b98 feat(core): Core-Bibliotheken auf 2.0.0.0 aktualisiert und IUnique implementiert
- `IUnique`-Schnittstelle in allen Entitäten implementiert.
- Interface für DbContext erstellt und DbSet-Eigenschaften in den Konstruktoren über Repositories injiziert.
2024-09-20 00:25:57 +02:00

39 lines
1.8 KiB
C#

using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.UserManager.Infrastructure.Repositories
{
public class GroupOfUserRepository<TDbContext> : CRUDRepository<GroupOfUser, int, TDbContext>, IGroupOfUserRepository
where TDbContext : DbContext, IUserManagerDbContext
{
public GroupOfUserRepository(TDbContext dbContext) : base(dbContext, dbContext.GroupOfUsers)
{
}
//TODO: making it public and having it in the interface is against Clean Architecture. Make it private
public IQueryable<GroupOfUser> ReadByGroupId(int groupId)
{
return _dbSet.Where(mou => mou.GroupId == groupId);
}
private IQueryable<GroupOfUser> ReadByUsername(string userName)
{
return _dbSet.Where(gou => gou.User!.Username == userName).Include(gou => gou.Group);
}
public async Task<IEnumerable<GroupOfUser>> ReadByGroupUserIdAsync(int groupId, int userId)
{
return await _dbSet.Where(gou => gou.GroupId == groupId && gou.UserId == userId).ToListAsync();
}
public async Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroup() => await _dbSet.Include(gou => gou.Group).ToListAsync();
public async Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithUser() => await _dbSet.Include(gou => gou.User).ToListAsync();
public async Task<IEnumerable<GroupOfUser>> ReadAllAsyncWithGroupAndUser() => await _dbSet.Include(gou => gou.Group).Include(gou => gou.User).ToListAsync();
public async Task<IEnumerable<GroupOfUser>> ReadByUsernameAsync(string username) => await ReadByUsername(username).ToListAsync();
}
}