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/create_account.rs
Normal file
29
http-server/src/handlers/create_account.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use actix_web::{post, web, Responder, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::AppState;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct OwnerData {
|
||||
pub(crate) owner: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct AccountCreated {
|
||||
nr: String,
|
||||
}
|
||||
|
||||
#[post("")]
|
||||
pub async fn route(
|
||||
form: web::Form<OwnerData>,
|
||||
data: web::Data<AppState>,
|
||||
) -> Result<impl Responder> {
|
||||
let owner = &form.owner;
|
||||
info!("creating new account with owner {}...", owner);
|
||||
|
||||
let mut bank = data.bank.write().unwrap();
|
||||
let nr = bank.create_account(owner.clone());
|
||||
info!("created account {}", nr);
|
||||
|
||||
Ok(web::Json(AccountCreated { nr }))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue