Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release alpha #21

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ name: Rust
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v3
- name: Build
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 }}
secrets: |
DATABASE_URL = '${{ secrets.DATABASE_URL }}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
test.db
.DS_Store
Secrets.toml
.env
49 changes: 37 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
actix-web = "4.4.0"
anyhow = "1.0.66"
chrono = "0.4.31"
diesel = { version = "2.1.4", features = ["postgres", "r2d2", "chrono", "uuid"] }
diesel_migrations = "2.1.0"
Expand All @@ -18,5 +19,7 @@ env_logger = "0.10"
log = "0.4"
strum_macros = "0.25.3"
strum = { version = "0.25.0", features = ["derive"]}
shuttle-actix-web = "0.35.1"
shuttle-runtime = "0.35.1"
shuttle-actix-web = "0.36.0"
shuttle-runtime = "0.36.0"
shuttle-secrets = "0.36.0"
tokio = "1.35.1"
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Built with actix

## Development

#### Compile the current package
#### Compile the current package
- ``cargo build``

#### Setup the database and migration
Expand All @@ -16,7 +16,6 @@ Built with actix
- ``cargo run``



## How to's

**Create new table**
Expand Down
63 changes: 26 additions & 37 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
use actix_web::{middleware::Logger, web::{self}, App, HttpServer};
use actix_web::{
web::ServiceConfig,
web::{self},
};
use shuttle_actix_web::ShuttleActixWeb;

pub mod app;
pub mod schema;

use app::api::home::{
all_homes,
add_home,
find_home,
delete_home
};

use app::api::room::{add_room, get_room};
use app::api::home::{add_home, all_homes, delete_home, find_home};
use app::api::item::{add_item, get_items};
use app::api::room::{add_room, get_room};

use app::db::{
initialize_db_pool,
initial_migration
};
use app::db::{initial_migration, initialize_db_pool};

// #[cfg(debug_assertions)]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
#[shuttle_runtime::main]
async fn main() -> ShuttleActixWeb<impl FnOnce(&mut ServiceConfig) + Send + Clone + 'static> {
dotenvy::dotenv().ok();
std::env::set_var("RUST_LOG", "debug");
std::env::set_var("RUST_BACKTRACE", "1");
env_logger::init();

let pool = initialize_db_pool();

log::info!("starting HTTP server at http://localhost:8080");
initial_migration();

HttpServer::new(move || {
let logger = Logger::default();
App::new()
.app_data(web::Data::new(pool.clone()))
.wrap(logger)
.service(all_homes)
.service(add_home)
.service(find_home)
.service(delete_home)
.service(add_room)
.service(get_room)
.service(get_items)
.service(add_item)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
let config = move |cfg: &mut ServiceConfig| {
cfg.app_data(web::Data::new(pool.clone()));
// Homes
cfg.service(all_homes);
cfg.service(add_home);
cfg.service(find_home);
cfg.service(delete_home);
// Rooms
cfg.service(add_room);
cfg.service(get_room);
// Items
cfg.service(add_item);
cfg.service(get_items);
};

Ok(config.into())
}
Loading