Implement the http variant of the bank server.
During that process, many shortcomings with the socket server and the bank lib were fixed. I am aware a massive commit like this is not ideal.
This commit is contained in:
parent
c69654a924
commit
dac95b7dae
34 changed files with 1797 additions and 140 deletions
29
http-server/src/handlers/close_account.rs
Normal file
29
http-server/src/handlers/close_account.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use actix_web::{post, web, HttpResponse, Responder, Result};
|
||||
|
||||
use bank::account::AccountError;
|
||||
use bank::bank::Bank;
|
||||
|
||||
use crate::handlers::error::HttpAccountError;
|
||||
use crate::AppState;
|
||||
|
||||
#[post("/{nr}/close")]
|
||||
pub async fn route(info: web::Path<String>, data: web::Data<AppState>) -> Result<impl Responder> {
|
||||
let nr = info.into_inner();
|
||||
|
||||
info!("closing account {}...", nr);
|
||||
|
||||
let bank = data.bank.read().unwrap();
|
||||
match Bank::account_action(bank, &nr, |account| {
|
||||
// TODO: make the error handling part of the passivate method
|
||||
if account.balance > 0_f64 {
|
||||
Err(AccountError::AccountNotZero)
|
||||
} else if account.passivate() {
|
||||
Ok(0_f64)
|
||||
} else {
|
||||
Err(AccountError::Inactive)
|
||||
}
|
||||
}) {
|
||||
Err(e) => Err(HttpAccountError(e).into()),
|
||||
Ok(_) => Ok(HttpResponse::Ok().finish()),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue