ini
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using AuthHex.Models;
|
||||
using AuthHex.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AuthHex.Repos
|
||||
{
|
||||
public class RecoveryManagerRepository : IRecoveryManagerRepository
|
||||
{
|
||||
private readonly AppDBContext _dbContext;
|
||||
|
||||
public RecoveryManagerRepository(AppDBContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<Recovery> AddRecoveryAsync(Recovery recovery, CancellationToken ct = default)
|
||||
{
|
||||
_dbContext.Recovery.Add(recovery);
|
||||
await _dbContext.SaveChangesAsync(ct);
|
||||
return recovery;
|
||||
}
|
||||
|
||||
public async Task<Recovery?> GetRecoveryByTokenHashAsync(string tokenHash, CancellationToken ct = default)
|
||||
{
|
||||
return await _dbContext.Recovery
|
||||
.Include(r => r.User)
|
||||
.FirstOrDefaultAsync(r => r.ResetTokenHash == tokenHash && !r.IsUsed, ct);
|
||||
}
|
||||
|
||||
public async Task<Recovery?> GetRecoveryByReferenceNumAsync(string referenceNum, CancellationToken ct = default)
|
||||
{
|
||||
return await _dbContext.Recovery
|
||||
.Include(r => r.User)
|
||||
.FirstOrDefaultAsync(r => r.RecoveryReferenceNum == referenceNum, ct);
|
||||
}
|
||||
|
||||
public async Task UpdateRecoveryAsync(Recovery recovery, CancellationToken ct = default)
|
||||
{
|
||||
_dbContext.Recovery.Update(recovery);
|
||||
await _dbContext.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
public async Task<List<Recovery>> GetPendingRecoveriesByUserIdAsync(Guid userId, CancellationToken ct = default)
|
||||
{
|
||||
return await _dbContext.Recovery
|
||||
.Where(r => r.UserId == userId && !r.IsUsed && r.Status == "Pending")
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user