diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-10-22 17:44:38 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-10-22 17:44:38 -0400 |
commit | 99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac (patch) | |
tree | 15e19324332173405fc7544af2c17195d7b05ff1 /dichroism/src/handlers.rs | |
parent | 76a782599b4ecc4ecb9b0ce7acc6420ed9e1ec8e (diff) | |
download | theglassyladies-99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac.tar.xz theglassyladies-99dabd3f2f81ffcf0b6f2b59e13ebb4502b2ccac.zip |
Added product migration, better organization of DTOs, Entities, and
Domain Models. Also made config loading/photo generation easier.
Diffstat (limited to 'dichroism/src/handlers.rs')
-rw-r--r-- | dichroism/src/handlers.rs | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/dichroism/src/handlers.rs b/dichroism/src/handlers.rs index 1f657c2..beecb72 100644 --- a/dichroism/src/handlers.rs +++ b/dichroism/src/handlers.rs @@ -1,6 +1,6 @@ -//use super::product_repo; -use super::types::DbPool; -//use crate::config::Config; +use crate::dtos::*; +use crate::product_repo; +use crate::types::DbPool; use actix_web::{get, patch, post, web, Error, HttpResponse, Responder}; #[get("/")] @@ -9,24 +9,24 @@ async fn hello() -> impl Responder { } #[get("/products")] -async fn get_products(_pool: web::Data<DbPool>) -> Result<HttpResponse, Error> { - dbg!("got products"); - Ok(HttpResponse::Ok().finish()) - //let conn = pool.get().expect("Couldn't get DB connection from pool."); - //let products = web::block(move || product_repo::read_products(&conn)) - // .await - // .map_err(|e| { - // eprintln!("{}", e); - // HttpResponse::InternalServerError().finish() - // })?; +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)) + .await + .map_err(|e| { + eprintln!("{}", e); + HttpResponse::InternalServerError().finish() + })?; + //dbg!(&products); //Ok(HttpResponse::Ok().json(products)) + todo!() } #[patch("/products/{id}")] async fn update_product( _pool: web::Data<DbPool>, id: web::Path<u32>, - updated_product: web::Json<UpdatedProduct>, + updated_product: web::Json<ProductPatch>, ) -> Result<HttpResponse, Error> { dbg!(id, updated_product); Ok(HttpResponse::Ok().finish()) @@ -40,15 +40,3 @@ async fn create_product( dbg!(new_product); Ok(HttpResponse::Ok().finish()) } - -#[derive(Debug, Deserialize)] -pub struct NewProduct { - pub name: String, - pub description: String, -} - -#[derive(Debug, Deserialize)] -pub struct UpdatedProduct { - pub name: Option<String>, - pub description: Option<String>, -} |