2022-09-26 13:21:13 -04:00
|
|
|
|
using System.Data;
|
|
|
|
|
|
using Bit.Core.Entities;
|
|
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
|
using Bit.Core.Settings;
|
|
|
|
|
|
using Dapper;
|
2023-01-10 15:58:41 -05:00
|
|
|
|
using Microsoft.Data.SqlClient;
|
2022-09-26 13:21:13 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
|
|
|
|
|
|
|
|
|
|
|
public class AuthRequestRepository : Repository<AuthRequest, Guid>, IAuthRequestRepository
|
|
|
|
|
|
{
|
|
|
|
|
|
public AuthRequestRepository(GlobalSettings globalSettings)
|
|
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public AuthRequestRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> DeleteExpiredAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
return await connection.ExecuteAsync(
|
|
|
|
|
|
$"[{Schema}].[AuthRequest_DeleteIfExpired]",
|
|
|
|
|
|
null,
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<ICollection<AuthRequest>> GetManyByUserIdAsync(Guid userId)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<AuthRequest>(
|
2022-11-16 17:15:20 +00:00
|
|
|
|
$"[{Schema}].[AuthRequest_ReadByUserId]",
|
2022-09-26 13:21:13 -04:00
|
|
|
|
new { UserId = userId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|