32 lines
793 B
Rust
32 lines
793 B
Rust
use actix_web::{post, web, HttpResponse, Responder, Result};
|
|
use serde::Serialize;
|
|
|
|
use bank::bank::Bank;
|
|
|
|
use crate::handlers::error::HttpAccountError;
|
|
use crate::handlers::AmountData;
|
|
use crate::AppState;
|
|
|
|
#[derive(Serialize)]
|
|
struct AccountCreated {
|
|
nr: String,
|
|
}
|
|
|
|
#[post("/{nr}/deposit")]
|
|
pub async fn route(
|
|
info: web::Path<String>,
|
|
form: web::Form<AmountData>,
|
|
data: web::Data<AppState>,
|
|
) -> Result<impl Responder> {
|
|
let nr = info.into_inner();
|
|
let amount = form.amount;
|
|
|
|
info!("depositing {} into account {}...", amount, nr);
|
|
|
|
let bank = data.bank.read().unwrap();
|
|
match Bank::account_action(bank, &nr, |account| account.deposit(amount)) {
|
|
Err(e) => Err(HttpAccountError(e).into()),
|
|
Ok(_) => Ok(HttpResponse::Ok().finish()),
|
|
}
|
|
}
|