Skip to content

Commit

Permalink
env (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
JijoBose authored Jan 13, 2024
1 parent f788a30 commit 69d4b7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
21 changes: 20 additions & 1 deletion src/app/api/item.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,3 +38,21 @@ async fn get_items(

Ok(HttpResponse::Ok().json(response))
}

#[delete("/item/{item_id}")]
async fn delete_item(
pool: web::Data<DbPool>,
item_id: web::Path<Uuid>,
) -> Result<impl Responder> {

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))
}
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down

0 comments on commit 69d4b7f

Please sign in to comment.