diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-10-22 22:09:46 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-10-22 22:09:46 -0400 |
commit | 5cb0869b94fc8b9aff564055af9a60046de7b028 (patch) | |
tree | 022cd909467d10747e9aa36d9455d47ea90b6c97 /dichroism/src/handlers.rs | |
parent | 99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac (diff) | |
download | theglassyladies-5cb0869b94fc8b9aff564055af9a60046de7b028.tar.xz theglassyladies-5cb0869b94fc8b9aff564055af9a60046de7b028.zip |
Skipped separate photo table; working handler for get all products
(lacking cats)
Diffstat (limited to 'dichroism/src/handlers.rs')
-rw-r--r-- | dichroism/src/handlers.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/dichroism/src/handlers.rs b/dichroism/src/handlers.rs index beecb72..23d2039 100644 --- a/dichroism/src/handlers.rs +++ b/dichroism/src/handlers.rs @@ -11,15 +11,16 @@ async fn hello() -> impl Responder { #[get("/products")] async fn get_products(pool: web::Data<DbPool>) -> Result<HttpResponse, Error> { let conn = pool.get().expect("Couldn't get DB connection from pool."); - let products = web::block(move || product_repo::read_products(&conn)) + let products: Vec<Product> = web::block(move || product_repo::read_products(&conn)) .await .map_err(|e| { eprintln!("{}", e); - HttpResponse::InternalServerError().finish() - })?; - //dbg!(&products); - //Ok(HttpResponse::Ok().json(products)) - todo!() + HttpResponse::InternalServerError().body(e.to_string()) + })? + .into_iter() + .map(|p| p.into()) + .collect(); + Ok(HttpResponse::Ok().json(products)) } #[patch("/products/{id}")] |