aboutsummaryrefslogtreecommitdiff
path: root/src/handlers/product.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/handlers/product.rs')
-rw-r--r--src/handlers/product.rs25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/handlers/product.rs b/src/handlers/product.rs
index 60a4684..788efb3 100644
--- a/src/handlers/product.rs
+++ b/src/handlers/product.rs
@@ -1,4 +1,4 @@
1use crate::models::{NewProduct, Product}; 1use crate::models::{NewProduct, Product, UpdateProduct};
2use crate::schema::product::dsl::*; 2use crate::schema::product::dsl::*;
3use crate::TPool; 3use crate::TPool;
4 4
@@ -43,14 +43,6 @@ pub async fn product_details(
43 } 43 }
44} 44}
45 45
46#[derive(Deserialize)]
47pub struct UpdateProduct {
48 name: String,
49 kind: Option<String>,
50 price: f32,
51 description: Option<String>,
52}
53
54pub async fn update_product( 46pub async fn update_product(
55 pool: web::Data<TPool>, 47 pool: web::Data<TPool>,
56 product_id: web::Path<i32>, 48 product_id: web::Path<i32>,
@@ -78,3 +70,18 @@ pub async fn update_product(
78 } 70 }
79 } 71 }
80} 72}
73
74pub async fn get_all_products(pool: web::Data<TPool>) -> impl Responder {
75 let conn = pool.get().unwrap();
76 info!("Generating and returning catalog ...");
77 match product.load::<Product>(&conn) {
78 Ok(products) => {
79 return HttpResponse::Ok()
80 .body(serde_json::to_string(&products).unwrap())
81 }
82 Err(_) => {
83 return HttpResponse::InternalServerError()
84 .body("Unable to fetch product catalog")
85 }
86 }
87}