2022-06-29 19:46:41 -04:00
|
|
|
|
using System.Data;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2019-02-01 22:22:08 -05:00
|
|
|
|
using Bit.Core.Enums;
|
2022-01-11 10:40:51 +01:00
|
|
|
|
using Bit.Core.Repositories;
|
2021-02-22 15:35:16 -06:00
|
|
|
|
using Bit.Core.Settings;
|
2019-01-31 16:45:01 -05:00
|
|
|
|
using Dapper;
|
2023-01-10 15:58:41 -05:00
|
|
|
|
using Microsoft.Data.SqlClient;
|
2019-01-31 16:45:01 -05:00
|
|
|
|
|
2024-07-24 09:48:09 -04:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2022-01-11 10:40:51 +01:00
|
|
|
|
public class TransactionRepository : Repository<Transaction, Guid>, ITransactionRepository
|
2019-01-31 16:45:01 -05:00
|
|
|
|
{
|
|
|
|
|
|
public TransactionRepository(GlobalSettings globalSettings)
|
|
|
|
|
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
public TransactionRepository(string connectionString, string readOnlyConnectionString)
|
|
|
|
|
|
: base(connectionString, readOnlyConnectionString)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
2024-06-11 13:55:23 -04:00
|
|
|
|
public async Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId, int? limit = null)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2019-01-31 16:45:01 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByUserId]",
|
2024-06-11 13:55:23 -04:00
|
|
|
|
new { UserId = userId, Limit = limit ?? int.MaxValue },
|
2019-01-31 16:45:01 -05:00
|
|
|
|
commandType: CommandType.StoredProcedure);
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2019-01-31 16:45:01 -05:00
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2019-01-31 16:45:01 -05:00
|
|
|
|
|
2024-06-11 13:55:23 -04:00
|
|
|
|
public async Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId, int? limit = null)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2024-06-11 13:55:23 -04:00
|
|
|
|
await using var connection = new SqlConnection(ConnectionString);
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2024-06-11 13:55:23 -04:00
|
|
|
|
var results = await connection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByOrganizationId]",
|
|
|
|
|
|
new { OrganizationId = organizationId, Limit = limit ?? int.MaxValue },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
|
|
|
|
|
|
|
|
return results.ToList();
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2019-02-01 22:22:08 -05:00
|
|
|
|
|
2024-06-11 13:55:23 -04:00
|
|
|
|
public async Task<ICollection<Transaction>> GetManyByProviderIdAsync(Guid providerId, int? limit = null)
|
2024-03-21 11:15:49 -04:00
|
|
|
|
{
|
|
|
|
|
|
await using var sqlConnection = new SqlConnection(ConnectionString);
|
2024-06-11 13:55:23 -04:00
|
|
|
|
|
2024-03-21 11:15:49 -04:00
|
|
|
|
var results = await sqlConnection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByProviderId]",
|
2024-06-11 13:55:23 -04:00
|
|
|
|
new { ProviderId = providerId, Limit = limit ?? int.MaxValue },
|
2024-03-21 11:15:49 -04:00
|
|
|
|
commandType: CommandType.StoredProcedure);
|
2024-06-11 13:55:23 -04:00
|
|
|
|
|
2024-03-21 11:15:49 -04:00
|
|
|
|
return results.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-24 09:48:09 -04:00
|
|
|
|
public async Task<Transaction?> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2024-06-11 13:55:23 -04:00
|
|
|
|
// maybe come back to this
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var connection = new SqlConnection(ConnectionString))
|
2019-02-01 22:22:08 -05:00
|
|
|
|
{
|
|
|
|
|
|
var results = await connection.QueryAsync<Transaction>(
|
|
|
|
|
|
$"[{Schema}].[Transaction_ReadByGatewayId]",
|
|
|
|
|
|
new { Gateway = gatewayType, GatewayId = gatewayId },
|
|
|
|
|
|
commandType: CommandType.StoredProcedure);
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2019-02-01 22:22:08 -05:00
|
|
|
|
return results.SingleOrDefault();
|
|
|
|
|
|
}
|
2019-01-31 16:45:01 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|