1
0
mirror of https://github.com/actix/examples synced 2025-06-27 09:29:02 +02:00

refactor mysql models

This commit is contained in:
Rob Ede
2023-07-17 22:13:50 +01:00
parent a86471501d
commit da976e0415
3 changed files with 185 additions and 266 deletions

View File

@ -19,9 +19,9 @@ pub(crate) async fn add_bank(
data: web::Data<mysql::Pool>,
) -> actix_web::Result<impl Responder> {
let bank_name = bank_data.bank_name;
let _country = bank_data.country;
let country = bank_data.country;
create_bank(&data, bank_name, _country)?;
web::block(move || create_bank(&data, bank_name, country)).await??;
Ok(HttpResponse::NoContent())
}
@ -32,11 +32,11 @@ pub(crate) async fn add_branch(
data: web::Data<mysql::Pool>,
) -> actix_web::Result<impl Responder> {
let branch_name = branch_data.branch_name;
let _location = branch_data.location;
let location = branch_data.location;
let response_data = create_branch(&data, branch_name, _location);
web::block(move || create_branch(&data, branch_name, location)).await??;
Ok(web::Json(response_data))
Ok(HttpResponse::NoContent())
}
#[post("/teller")]
@ -47,9 +47,9 @@ pub(crate) async fn add_teller(
let teller_name = teller_data.teller_name;
let branch_name = teller_data.branch_name;
let response_data = create_teller(&data, teller_name, branch_name);
web::block(move || create_teller(&data, teller_name, branch_name)).await??;
Ok(web::Json(response_data))
Ok(HttpResponse::NoContent())
}
#[post("/customer")]
@ -60,26 +60,26 @@ pub(crate) async fn add_customer(
let customer_name = customer_data.customer_name;
let branch_name = customer_data.branch_name;
let response_data = create_customer(&data, customer_name, branch_name);
web::block(move || create_customer(&data, customer_name, branch_name)).await??;
Ok(web::Json(response_data))
Ok(HttpResponse::NoContent())
}
#[get("/bank")]
pub(crate) async fn get_bank(data: web::Data<mysql::Pool>) -> actix_web::Result<impl Responder> {
let bank_response_data = get_bank_data(&data);
let bank_response_data = web::block(move || get_bank_data(&data)).await??;
Ok(web::Json(bank_response_data))
}
#[get("/branch")]
pub(crate) async fn get_branch(data: web::Data<mysql::Pool>) -> actix_web::Result<impl Responder> {
let branch_response_data = get_branch_data(&data);
let branch_response_data = web::block(move || get_branch_data(&data)).await??;
Ok(web::Json(branch_response_data))
}
#[get("/teller")]
pub(crate) async fn get_teller(data: web::Data<mysql::Pool>) -> actix_web::Result<impl Responder> {
let teller_response_data = get_teller_data(&data);
let teller_response_data = web::block(move || get_teller_data(&data)).await??;
Ok(web::Json(teller_response_data))
}
@ -87,6 +87,6 @@ pub(crate) async fn get_teller(data: web::Data<mysql::Pool>) -> actix_web::Resul
pub(crate) async fn get_customer(
data: web::Data<mysql::Pool>,
) -> actix_web::Result<impl Responder> {
let customer_response_data = get_customer_data(&data);
let customer_response_data = web::block(move || get_customer_data(&data)).await??;
Ok(web::Json(customer_response_data))
}