Files
pos-system/services/iam-service-net/src/IamService.Infrastructure/Repositories/AccessReviewRepository.cs
Ho Ngoc Hai 8b7db56b79 feat: Add Access Review and Privileged Access functionality to IAM Service
- Introduced new AccessReview and PrivilegedAccess entities in the DbContext to enhance access management capabilities.
- Updated Dependency Injection to include AccessReviewRepository and PrivilegedAccessRepository, improving service functionality for access reviews and privileged access management.
2026-01-14 16:02:34 +07:00

39 lines
1.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using IamService.Domain.AggregatesModel.AccessReviewAggregate;
using IamService.Domain.SeedWork;
namespace IamService.Infrastructure.Repositories;
/// <summary>
/// EN: Repository implementation for AccessReview aggregate.
/// VI: Repository implementation cho AccessReview aggregate.
/// </summary>
public class AccessReviewRepository : IAccessReviewRepository
{
private readonly IamServiceContext _context;
public IUnitOfWork UnitOfWork => _context;
public AccessReviewRepository(IamServiceContext context) => _context = context;
public AccessReview Add(AccessReview review) => _context.AccessReviews.Add(review).Entity;
public void Update(AccessReview review) => _context.Entry(review).State = EntityState.Modified;
public async Task<AccessReview?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
=> await _context.AccessReviews.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
public async Task<AccessReview?> GetByIdWithItemsAsync(Guid id, CancellationToken cancellationToken = default)
=> await _context.AccessReviews.Include(x => x.Items).FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
public async Task<IEnumerable<AccessReview>> GetByOwnerIdAsync(Guid ownerId, CancellationToken cancellationToken = default)
=> await _context.AccessReviews
.Where(x => EF.Property<Guid>(x, "_ownerId") == ownerId)
.OrderByDescending(x => EF.Property<DateTime>(x, "_createdAt"))
.ToListAsync(cancellationToken);
public async Task<IEnumerable<AccessReview>> GetActiveReviewsAsync(CancellationToken cancellationToken = default)
=> await _context.AccessReviews
.Where(x => EF.Property<AccessReviewStatus>(x, "_status") == AccessReviewStatus.Active)
.ToListAsync(cancellationToken);
}