summaryrefslogtreecommitdiff
path: root/dichroism/src/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dichroism/src/handlers.rs')
-rw-r--r--dichroism/src/handlers.rs13
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}")]