From 69d4b7f5894e4b54b8b9fe2e869e22590261fe18 Mon Sep 17 00:00:00 2001 From: Jijo Bose Date: Sun, 14 Jan 2024 00:27:35 +0530 Subject: [PATCH] env (#24) --- .github/workflows/rust.yml | 8 -------- src/app/api/item.rs | 21 ++++++++++++++++++++- src/main.rs | 6 +++++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 924d5fa..554a83e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,11 +18,3 @@ jobs: run: cargo build --verbose - name: Run tests run: cargo test --verbose - - deploy: - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - steps: - - uses: shuttle-hq/deploy-action@main - with: - deploy-key: ${{ secrets.SHUTTLE_API_KEY }} diff --git a/src/app/api/item.rs b/src/app/api/item.rs index 90426ff..20ddf69 100644 --- a/src/app/api/item.rs +++ b/src/app/api/item.rs @@ -1,5 +1,6 @@ -use actix_web::{error, get, post, web, HttpResponse, Responder, Result}; +use actix_web::{error, get, post, delete, web, HttpResponse, Responder, Result}; use diesel::{r2d2, PgConnection}; +use uuid::Uuid; use crate::app::actions; use crate::app::models; @@ -37,3 +38,21 @@ async fn get_items( Ok(HttpResponse::Ok().json(response)) } + +#[delete("/item/{item_id}")] +async fn delete_item( + pool: web::Data, + item_id: web::Path, +) -> Result { + + let item_id = item_id.into_inner(); + + let item = web::block(move || { + let mut conn = pool.get()?; + actions::item::delete_item(&mut conn, item_id) + }) + .await? + .map_err(error::ErrorBadRequest)?; + + Ok(HttpResponse::Created().json(item)) +} diff --git a/src/main.rs b/src/main.rs index b4b3d4b..698d238 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use app::api::home::{ }; use app::api::room::{add_room, get_room}; -use app::api::item::{add_item, get_items}; +use app::api::item::{add_item, get_items, delete_item}; use app::db::{ initialize_db_pool, @@ -36,14 +36,18 @@ async fn main() -> std::io::Result<()> { App::new() .app_data(web::Data::new(pool.clone())) .wrap(logger) + // Home API .service(all_homes) .service(add_home) .service(find_home) .service(delete_home) + // Room .service(add_room) .service(get_room) + // Iventory Item .service(get_items) .service(add_item) + .service(delete_item) }) .bind(("127.0.0.1", 8080))? .run()