blob: beecb7235593a87d16abd734701252aed912d386 (
plain) (
tree)
|
|
use crate::dtos::*;
use crate::product_repo;
use crate::types::DbPool;
use actix_web::{get, patch, post, web, Error, HttpResponse, Responder};
#[get("/")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hey, this is an API!")
}
#[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))
.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<ProductPatch>,
) -> Result<HttpResponse, Error> {
dbg!(id, updated_product);
Ok(HttpResponse::Ok().finish())
}
#[post("/products")]
async fn create_product(
_pool: web::Data<DbPool>,
new_product: web::Json<NewProduct>,
) -> Result<HttpResponse, Error> {
dbg!(new_product);
Ok(HttpResponse::Ok().finish())
}
|