add user table
This commit is contained in:
parent
f01b073654
commit
bb8fb03b61
1426
Cargo.lock
generated
Normal file
1426
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,10 +6,6 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = { version = "0.5.0-rc.2", features = ["secrets"]}
|
rocket = { version = "0.5.0-rc.3"}
|
||||||
rocket_dyn_templates = { version = "0.1.0-rc.2", features= ["tera"] }
|
|
||||||
chrono = { version = "0.4", features = ["serde"]}
|
|
||||||
sha3 = "0.10"
|
|
||||||
hex = "0.4"
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = "0.10"
|
env_logger = "0.10"
|
||||||
|
4
db.txt
4
db.txt
@ -1,4 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS "day" ( "day" text NOT NULL PRIMARY KEY, "planned_amount_cox" integer NOT NULL DEFAULT 0, "planned_starting_time" text, "open_registration" boolean NOT NULL DEFAULT TRUE );
|
|
||||||
CREATE TABLE IF NOT EXISTS "user" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" text NOT NULL UNIQUE, "pw" text, "is_cox" boolean NOT NULL DEFAULT FALSE, "add_different_user" boolean NOT NULL DEFAULT FALSE, "is_admin" boolean NOT NULL DEFAULT FALSE );
|
|
||||||
CREATE TABLE IF NOT EXISTS "trip" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "day" text NOT NULL, "user_id" integer NOT NULL, "cox_id" integer, "begin" text, "created" text NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY ("day") REFERENCES "day" ("day"), FOREIGN KEY ("user_id") REFERENCES "user" ("id"), FOREIGN KEY ("cox_id") REFERENCES "trip" ("id") );
|
|
||||||
create unique index UNIQ_trip on trip("day", "user_id", IFNULL(cox_id, ''), IFNULL(begin,''));
|
|
8
migration.sql
Normal file
8
migration.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS "user" (
|
||||||
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"name" text NOT NULL UNIQUE,
|
||||||
|
"pw" text,
|
||||||
|
"is_cox" boolean NOT NULL DEFAULT FALSE,
|
||||||
|
"is_admin" boolean NOT NULL DEFAULT FALSE,
|
||||||
|
"is_guest" boolean NOT NULL DEFAULT TRUE
|
||||||
|
);
|
4
seeds.sql
Normal file
4
seeds.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
INSERT INTO "user" (name, is_cox, is_admin, is_guest) VALUES('admin', false, true, false);
|
||||||
|
INSERT INTO "user" (name, is_cox, is_admin, is_guest) VALUES('rower', false, false, false);
|
||||||
|
INSERT INTO "user" (name, is_cox, is_admin, is_guest) VALUES('guest', false, false, true);
|
||||||
|
INSERT INTO "user" (name, is_cox, is_admin, is_guest) VALUES('cox', true, false, false);
|
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod rest;
|
@ -1,7 +1,11 @@
|
|||||||
|
use rot::rest;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
async fn rocket() -> _ {
|
async fn rocket() -> _ {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
rest::start()
|
||||||
}
|
}
|
||||||
|
27
src/rest/mod.rs
Normal file
27
src/rest/mod.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use rocket::{get, routes, Build, Rocket};
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
fn index() -> &'static str {
|
||||||
|
"Hello, world!"
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start() -> Rocket<Build> {
|
||||||
|
rocket::build().mount("/", routes![index])
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::start;
|
||||||
|
use rocket::http::Status;
|
||||||
|
use rocket::local::blocking::Client;
|
||||||
|
use rocket::uri;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hello_world() {
|
||||||
|
let client = Client::tracked(start()).expect("valid rocket instance");
|
||||||
|
let response = client.get(uri!(super::index)).dispatch();
|
||||||
|
|
||||||
|
assert_eq!(response.status(), Status::Ok);
|
||||||
|
assert_eq!(response.into_string(), Some("Hello, world!".into()));
|
||||||
|
}
|
||||||
|
}
|
6
test_db.sh
Executable file
6
test_db.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
rm -f db.sqlite
|
||||||
|
touch db.sqlite
|
||||||
|
sqlite3 db.sqlite < migration.sql
|
||||||
|
sqlite3 db.sqlite < seeds.sql
|
Loading…
Reference in New Issue
Block a user