TekH 3de7e64f85 Deprecate services and update mapping profiles
- Added obsolete attributes to `AuthController`, `ModuleController`, and various mapping profiles, recommending the use of MediatR and DigitalData.Core.Exceptions.
- Updated `User` class to use `required` keyword for `DateFormat` in .NET 7.0 or greater.
- Marked methods in `Extensions` and `AddUserManagerInfrastructure` as obsolete, suggesting the use of IRepository.
- Adjusted import statements in `DependencyInjection.cs` and marked `GroupOfUserRepository` and `ModuleRepository` as obsolete, recommending a Repository pattern.
2025-06-26 13:53:54 +02:00

76 lines
3.3 KiB
C#

using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.Core.Infrastructure;
using Microsoft.EntityFrameworkCore;
using DigitalData.UserManager.Application.Contracts.Repositories;
namespace DigitalData.UserManager.Infrastructure.Repositories
{
[Obsolete("Use Repository")]
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> ReadByUserId(int userId)
{
return _dbSet.Where(gou => gou.User!.Id == userId).Include(gou => gou.Group);
}
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();
}
//TODO: Add -Async suffix at the end of async method names
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();
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();
}
}
}