From 9b3df58a08f140968133114dea8cdb7ef2770ee5 Mon Sep 17 00:00:00 2001 From: Artus Date: Tue, 18 Jun 2019 15:44:49 +0200 Subject: [PATCH] adds server to serve the static files, fixes db tables --- .gitignore | 1 + Cargo.toml | 5 +++++ lootalot_db/db.sqlite3 | Bin 28672 -> 28672 bytes .../2019-06-10-123922_create_items/up.sql | 2 +- .../2019-06-10-123940_create_players/up.sql | 12 +++++------ .../2019-06-10-124013_create_looted/up.sql | 4 ++-- lootalot_db/src/lib.rs | 1 - lootalot_db/src/schema.rs | 18 ++++++++-------- src/main.rs | 20 ++++++++++++++++++ 9 files changed, 44 insertions(+), 19 deletions(-) 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 95ea61df7aacc8e8221aaceaac44ff347d40ff24..9e908f09787c4e90106dc2cacdffd96f46c58459 100644 GIT binary patch delta 362 zcmZp8z}WDBae}m<1Oo#DI}|elX`zWa#u5??dO88T{6832d6*gaZt^eY^XC=hVdmS| z*u%}$#LdbsE-A^_TsS$H$AMG9&p$-LFVx3p@?@Ss4mjsMPco-93%j_qG-HeJQ~zGk3yQegLfV BRWkqp delta 435 zcmZp8z}WDBae}lU9|HpeI}|elX^x3H#u9uCdO88T{6832c{~~TZt^eYi{uUD@#Nbq zC~%3JtBIABU0hOv@tnSy|Y{rKK606DLda zI!~U@Cp)=?S8VcPUOQGDE(L|+$%cHwU{*SaHCcyGf}2aTj+tFtT%55ndU7P6?dJJ> z+=2!M3Wmm32F6x~W-3g~n#M*3hL#3qh6aX4#+D`qAfB#)nXVyFm64UHv6ZR8+8^HZ%Wa2L5;aclj>^9dndlmxGy=fs<1h7-alR dAeJJ`Lk4C7jI0cdoQf=95hEjA1CvDw0swzhUElx! 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(); }