Setup wallet and transaction retrieval, better swagger docs, and proper dtos
This commit is contained in:
35
src/IO.Swagger/Repositories/TransactionRepository.cs
Normal file
35
src/IO.Swagger/Repositories/TransactionRepository.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user