diff --git a/src/api/transactions.rs b/src/api/transactions.rs index 407c74a..85ce032 100644 --- a/src/api/transactions.rs +++ b/src/api/transactions.rs @@ -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")