diff --git a/.gitignore b/.gitignore index e1eb793..16d7ed7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ node_modules fontawesome Cargo.lock +**/*.sqlite3 diff --git a/Cargo.toml b/Cargo.toml index baa7348..d9ed1af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" authors = ["Artus "] edition = "2018" +[dependencies] +actix-web = "0.7" +lootalot-db = { version = "0.1", path = "./lootalot_db" } +dotenv = "*" + [workspace] members = [ "lootalot_db" diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 95ea61d..9e908f0 100644 Binary files a/lootalot_db/db.sqlite3 and b/lootalot_db/db.sqlite3 differ diff --git a/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql b/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql index 1be5066..f39d73b 100644 --- a/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql +++ b/lootalot_db/migrations/2019-06-10-123922_create_items/up.sql @@ -1,5 +1,5 @@ CREATE TABLE items ( - id INTEGER PRIMARY KEY, + id INTEGER PRIMARY KEY NOT NULL, name VARCHAR NOT NULL, base_price INTEGER NOT NULL ); diff --git a/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql b/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql index b14a350..669ddf9 100644 --- a/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql +++ b/lootalot_db/migrations/2019-06-10-123940_create_players/up.sql @@ -1,9 +1,9 @@ CREATE TABLE players ( - id INTEGER PRIMARY KEY, + id INTEGER PRIMARY KEY NOT NULL, name VARCHAR NOT NULL, - debt INTEGER DEFAULT 0, -- debt to the group in copper pieces - cp INTEGER DEFAULT 0, - sp INTEGER DEFAULT 0, - gp INTEGER DEFAULT 0, - pp INTEGER DEFAULT 0 + debt INTEGER DEFAULT 0 NOT NULL, -- debt to the group in copper pieces + cp INTEGER DEFAULT 0 NOT NULL, + sp INTEGER DEFAULT 0 NOT NULL, + gp INTEGER DEFAULT 0 NOT NULL, + pp INTEGER DEFAULT 0 NOT NULL ); diff --git a/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql b/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql index 5169a5b..46f2053 100644 --- a/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql +++ b/lootalot_db/migrations/2019-06-10-124013_create_looted/up.sql @@ -1,8 +1,8 @@ CREATE TABLE looted ( - id INTEGER PRIMARY KEY, + id INTEGER PRIMARY KEY NOT NULL, player_id INTEGER NOT NULL, item_id INTEGER NOT NULL, - acquired_date DATE DEFAULT NOW, + acquired_date DATE NOT NULL, FOREIGN KEY (player_id) REFERENCES players(id), FOREIGN KEY (item_id) REFERENCES items(id) ); diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index f90b0d1..2ea9807 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -23,7 +23,6 @@ pub fn list_players() -> Vec { players .load::(&conn) .expect("Error loading players") - .collect() } diff --git a/lootalot_db/src/schema.rs b/lootalot_db/src/schema.rs index d7f7c90..f5a1efa 100644 --- a/lootalot_db/src/schema.rs +++ b/lootalot_db/src/schema.rs @@ -1,6 +1,6 @@ table! { items (id) { - id -> Nullable, + id -> Integer, name -> Text, base_price -> Integer, } @@ -8,22 +8,22 @@ table! { table! { looted (id) { - id -> Nullable, + id -> Integer, player_id -> Integer, item_id -> Integer, - acquired_date -> Nullable, + acquired_date -> Date, } } table! { players (id) { - id -> Nullable, + id -> Integer, name -> Text, - debt -> Nullable, - cp -> Nullable, - sp -> Nullable, - gp -> Nullable, - pp -> Nullable, + debt -> Integer, + cp -> Integer, + sp -> Integer, + gp -> Integer, + pp -> Integer, } } diff --git a/src/main.rs b/src/main.rs index 7dfc9f0..dfeba02 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,25 @@ extern crate lootalot_db; +extern crate actix_web; +extern crate dotenv; + +use std::env; +use std::cell::RefCell; +use std::rc::Rc; +use actix_web::{server, App, Result, HttpRequest, fs }; + fn main() { println!("Hello, world!"); + + dotenv::dotenv().ok(); + + let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set"); + println!("serving files from: {}", &www_root); + server::new(move || { + App::new() + .handler("/", fs::StaticFiles::new(www_root.clone()).unwrap().index_file("index.html")) + }) + .bind("127.0.0.1:8088") + .unwrap() + .run(); }