Implemented user transactions
This commit is contained in:
@ -54,21 +54,19 @@ namespace IO.Swagger.Controllers
|
||||
[ValidateModelState]
|
||||
[SwaggerOperation("GetUserBalances")]
|
||||
[ProducesResponseType(typeof(WalletBalanceDto), 200)]
|
||||
[ProducesResponseType(401)]
|
||||
public virtual async Task<IActionResult> GetUserBalances()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
var transactions = await transactionRepository.GetTransactionsForUser(userId);
|
||||
var balances = transactions.GroupBy(t => t.Currency)
|
||||
.Select(g => new WalletBalanceDto
|
||||
var balances = await transactionRepository.GetBalancesForUser(userId);
|
||||
var res = balances.Select(t => new WalletBalanceDto
|
||||
{
|
||||
Currency = mapper.Map<CurrencyDto>(g.Key),
|
||||
Balance = g.Sum(t =>t.Amount)
|
||||
Currency = mapper.Map<CurrencyDto>(t.Item1),
|
||||
Balance = t.Item2
|
||||
});
|
||||
return Ok(balances);
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -82,7 +80,6 @@ namespace IO.Swagger.Controllers
|
||||
[ValidateModelState]
|
||||
[SwaggerOperation("GetUserTransactions")]
|
||||
[ProducesResponseType(typeof(IEnumerable<TransactionDto>), 200)]
|
||||
[ProducesResponseType(401)]
|
||||
public virtual async Task<IActionResult> GetUserTransactions()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
@ -90,7 +87,6 @@ namespace IO.Swagger.Controllers
|
||||
return Unauthorized();
|
||||
|
||||
var transactions = await transactionRepository.GetTransactionsForUser(userId);
|
||||
|
||||
return Ok(transactions.Select(mapper.Map<TransactionDto>));
|
||||
}
|
||||
|
||||
@ -132,18 +128,18 @@ namespace IO.Swagger.Controllers
|
||||
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
|
||||
[ValidateModelState]
|
||||
[SwaggerOperation("TransferPhysicalCurrency")]
|
||||
public virtual IActionResult TransferPhysicalCurrency([FromBody]WalletTransferPhysicalBody body)
|
||||
{
|
||||
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(200);
|
||||
[ProducesResponseType(typeof(IEnumerable<string>), 400)]
|
||||
[ProducesResponseType(typeof(TransactionReturnCode), 409)]
|
||||
public virtual async Task<IActionResult> TransferPhysicalCurrency([FromBody]WalletTransferPhysicalBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(400);
|
||||
|
||||
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(401);
|
||||
|
||||
throw new NotImplementedException();
|
||||
var transactionResult = await transactionRepository.TransferPhysical(body, userId);
|
||||
return transactionResult == TransactionReturnCode.Success ? Ok() : StatusCode(409, (int)transactionResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user