Doxy, -Wall -Werror, other cleanup and organization first round

This commit is contained in:
2023-08-19 20:46:31 -04:00
parent 1fedd4d016
commit 49de8aa8d7
43 changed files with 728 additions and 354 deletions

View File

@ -1,5 +1,5 @@
using IO.Swagger.Models.db;
using IO.Swagger.Models.dto;
using IO.Swagger.Models.RequestDto;
using IO.Swagger.Services;
using Microsoft.EntityFrameworkCore;
using System;
@ -9,16 +9,25 @@ using System.Threading.Tasks;
namespace IO.Swagger.Repositories
{
/// <summary>
/// The EF implementation of this interface
/// </summary>
/// <seealso cref="IO.Swagger.Repositories.ITransactionRepository" />
public class TransactionRepository : ITransactionRepository
{
BankDbContext context;
private readonly BankDbContext context;
/// <summary>
/// Initializes a new instance of the <see cref="TransactionRepository"/> class.
/// </summary>
/// <param name="context">The context.</param>
/// <exception cref="System.ArgumentNullException">context</exception>
public TransactionRepository(BankDbContext context)
{
this.context = context ?? throw new ArgumentNullException(nameof(context));
}
/// <inheritdoc/>
public async Task<List<Transaction>> GetTransactionsForUser(int userId)
{
var transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
@ -34,6 +43,8 @@ namespace IO.Swagger.Repositories
return transactions;
}
/// <inheritdoc/>
public async Task<List<Tuple<Currency, float>>> GetBalancesForUser(int userId)
{
var transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
@ -41,7 +52,7 @@ namespace IO.Swagger.Repositories
.GroupBy(t => t.Currency)
.Select(g => Tuple.Create(
g.Key,
g.Sum(t =>t.ToUserId != t.FromUserId && t.FromUserId == userId
g.Sum(t => t.ToUserId != t.FromUserId && t.FromUserId == userId
? -t.Amount
: t.Amount
)
@ -52,13 +63,15 @@ namespace IO.Swagger.Repositories
return transactions;
}
/// <inheritdoc/>
public async Task<TransactionReturnCode> TransferPhysical(WalletTransferPhysicalBody request, int fromUserId)
{
var trimmedDest = request.DestUserEmail.Trim().ToLower();
var destUser = await context.Users.FirstOrDefaultAsync(u => u.Email == trimmedDest);
if (destUser == null)
return TransactionReturnCode.UnknownDestinationUser;
var balances = await GetBalancesForUser(fromUserId);
var balance = balances.FirstOrDefault(b => b.Item1.CurrencyId == request.CurrencyId);
if (balance == null || balance.Item2 < request.Amount)