Files
server/src/Infrastructure.Dapper/Repositories/TransactionRepository.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
2.6 KiB
C#
Raw Normal View History

using System.Data;
using Bit.Core.Entities;
2019-02-01 22:22:08 -05:00
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Core.Settings;
2019-01-31 16:45:01 -05:00
using Dapper;
using Microsoft.Data.SqlClient;
2019-01-31 16:45:01 -05:00
#nullable enable
namespace Bit.Infrastructure.Dapper.Repositories;
2022-08-29 16:06:55 -04: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)
{ }
public async Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId, int? limit = null)
2022-08-29 16:06:55 -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]",
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
public async Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId, int? limit = null)
2022-08-29 16:06:55 -04:00
{
await using var connection = new SqlConnection(ConnectionString);
2022-08-29 16:06:55 -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
public async Task<ICollection<Transaction>> GetManyByProviderIdAsync(Guid providerId, int? limit = null)
{
await using var sqlConnection = new SqlConnection(ConnectionString);
var results = await sqlConnection.QueryAsync<Transaction>(
$"[{Schema}].[Transaction_ReadByProviderId]",
new { ProviderId = providerId, Limit = limit ?? int.MaxValue },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
public async Task<Transaction?> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId)
2022-08-29 16:06:55 -04:00
{
// maybe come back to this
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
}
}