vesys-bank-server/http-server/src/handlers/is_active.rs

32 lines
870 B
Rust

use actix_web::{head, web, HttpResponse, Responder, Result};
use bank::account::AccountError;
use serde::Serialize;
use crate::handlers::error::HttpAccountError;
use crate::AppState;
#[derive(Serialize)]
struct AccountCreated {
nr: String,
}
#[head("/{nr}")]
pub async fn route(info: web::Path<String>, data: web::Data<AppState>) -> Result<impl Responder> {
let nr = info.into_inner();
info!("checking account {}...", nr);
let bank = data.bank.read().unwrap();
match bank.accounts.get(&nr) {
None => Err(HttpAccountError(AccountError::NotFound).into()),
Some(account) => {
let account = account.read().unwrap();
if account.is_active {
Ok(HttpResponse::Ok().finish())
} else {
Err(HttpAccountError(AccountError::Inactive).into())
}
}
}
}