Add balance handling to card transactions and user accounts
Java CI / build (push) Successful in 1m11s
.NET+Docker CI/CD / Unit and Integration tests (push) Successful in 36s
.NET+Docker CI/CD / Push Docker image to ghcr.io (push) Failing after 33s

Signed-off-by: Dmitrii <computer@yawaflua.tech>

Took 6 minutes
This commit is contained in:
Dmitrii
2026-07-06 03:53:31 +03:00
parent 9238069d0e
commit d065c6897e
4 changed files with 24 additions and 10 deletions
@@ -70,6 +70,11 @@ public class TransactionsController(AppDbContext context, ILogger<TransactionsCo
return BadRequest(new { error = "Card not found" });
}
if (cardToUse.Balance != -1 && cardToUse.Balance < body.amount)
{
return BadRequest(new { error = "Insufficient balance" });
}
var shortId = Program.GenerateRandomString(5);
while (true)
@@ -101,17 +106,18 @@ public class TransactionsController(AppDbContext context, ILogger<TransactionsCo
{
{ "receiver", body.receiverCard },
{ "amount", body.amount },
{ "comment", body.comment + ";Чек:"+ uri }
{ "comment", (body.comment)[8..] + "..;Чек:"+ uri }
};
Console.WriteLine((body.comment + ";Чек: "+ uri).Length);
Console.WriteLine((body.comment + ";Чек: "+ uri));
var resp = await SendRequest(endpoint: "transactions", body: transitionInfo,
AuthHeader: new("Bearer", cardToUse.Token));
Console.WriteLine(((body.comment)[8..] + "..;Чек:"+ uri).Length);
Console.WriteLine(((body.comment)[8..] + "..;Чек:"+ uri));
var resp = await SendRequest(endpoint: "transactions", body: transitionInfo, AuthHeader: new("Bearer", cardToUse.Token));
var balance = (int?)JsonNode.Parse(resp)?["balance"];
if (balance == null)
{
throw new Exception("Failed to create transaction: " + resp);
}
cardToUse.Balance = balance.Value;
} catch (Exception exception)
{