mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2025-12-20 02:59:20 +01:00
fix todos in payment endpoint
This commit is contained in:
parent
2d3cc8edc1
commit
02b56c745d
@ -1,8 +1,8 @@
|
||||
use std::{borrow::Cow, cell::RefCell, sync::Arc};
|
||||
|
||||
use axum::{Router, routing::post};
|
||||
use axum::{Router, http::StatusCode, routing::post};
|
||||
use bank_core::{
|
||||
Name, NameOrUuid, USER_ACCOUNT_PATTERN, make_schemas,
|
||||
ApiError, Name, NameOrUuid, USER_ACCOUNT_PATTERN, make_schemas,
|
||||
pagination::Pagination,
|
||||
transaction::{FullTransaction, Transaction, TransactionQuery},
|
||||
};
|
||||
@ -349,13 +349,28 @@ pub async fn make_payment(
|
||||
NameOrUuid::Id(uuid) => Accounts::by_id(&client, uuid).await?,
|
||||
NameOrUuid::Name(name) => Accounts::get_for_user(&client, user_id, &*name).await?,
|
||||
}) else {
|
||||
todo!("from account doesn't exist")
|
||||
return Err(ApiError::const_new(
|
||||
StatusCode::NOT_FOUND,
|
||||
"transaction.from.not_found",
|
||||
"Not Found",
|
||||
)
|
||||
.into());
|
||||
};
|
||||
let Some((to_user, to)) = to.account_id(&client).await? else {
|
||||
todo!("to account doesn't exist")
|
||||
return Err(ApiError::const_new(
|
||||
StatusCode::NOT_FOUND,
|
||||
"transaction.target.not_found",
|
||||
"Not Found",
|
||||
)
|
||||
.into());
|
||||
};
|
||||
if from.balance < amount {
|
||||
todo!("not enough money")
|
||||
return Err(ApiError::const_new(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"transaction.insufficient_funds",
|
||||
"Insufficient funds",
|
||||
)
|
||||
.into());
|
||||
}
|
||||
let update_balance_stmt = client
|
||||
.prepare_cached("update accounts set balance = balance + $2 where id = $1")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user