Setup wallet and transaction retrieval, better swagger docs, and proper dtos

This commit is contained in:
2023-08-19 16:43:58 -04:00
parent 658bd7ca2a
commit dc9ab74598
16 changed files with 224 additions and 21 deletions

View File

@ -0,0 +1,35 @@
using IO.Swagger.Models.db;
using IO.Swagger.Services;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IO.Swagger.Repositories
{
public class TransactionRepository : ITransactionRepository
{
BankDbContext context;
public TransactionRepository(BankDbContext context)
{
this.context = context ?? throw new ArgumentNullException(nameof(context));
}
public async Task<List<Transaction>> GetTransactionsForUser(int userId)
{
var transactions = await context.Transactions.Where(t => t.ToUserId == userId || t.FromUserId == userId)
.Include(t => t.Currency)
.Include(t => t.FromUser)
.Include(t => t.ToUser)
.OrderByDescending(t => t.TransactionTime)
.ToListAsync();
foreach (var t in transactions)
if (t.ToUserId != t.FromUserId && t.FromUserId == userId)
t.Amount *= -1;
return transactions;
}
}
}