small changes to server code

This commit is contained in:
Arlo Filley 2022-11-04 12:24:55 +00:00
commit c6cf81a583
4 changed files with 9 additions and 19 deletions

BIN
.DS_Store vendored

Binary file not shown.

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
Cargo.lock
/database/database.sqlite
/NEA_Screenshots
.DS_Store

View File

@ -1,6 +1,6 @@
// relevant macros and imports for rocket.rs
#[macro_use] extern crate rocket;
use rocket::{Rocket, Build, fs::{FileServer, relative}, serde::{Deserialize, json::Json}};
use rocket::{Rocket, Build, fs::{FileServer, relative}, serde::{Deserialize, json::Json}, Error, Response};
pub mod sql;
#[get("/")]
@ -14,28 +14,17 @@ fn test() -> String {
#[serde(crate = "rocket::serde")]
struct PostTest<'r> {
test_type: &'r str,
test_length: i64,
test_time: i32,
test_length: u32,
test_time: u32,
test_seed: i64,
quote_id: i32,
wpm: i16,
accuracy: i8,
user_id: i32
wpm: u8,
accuracy: u8,
user_id: u32
}
#[post("/post_test", data = "<test>")]
fn post_test(test: Json<PostTest<'_>>) {
println!(
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
test.test_type,
test.test_length,
test.test_time,
test.test_seed,
test.quote_id,
test.wpm,
test.accuracy,
test.user_id
);
sql::post_test(test.test_type, test.test_length, test.test_time, test.test_seed, test.quote_id, test.wpm, test.accuracy, test.user_id)
.expect("error in posting test to tests table");
}

View File

@ -26,7 +26,7 @@ pub fn create_database() -> Result<()> {
Ok(())
}
pub fn post_test(test_type: &str, test_length: i64, test_time: i32, test_seed: i64, quote_id: i32, wpm: i16, accuracy: i8, user_id: i32)
pub fn post_test(test_type: &str, test_length: u32, test_time: u32, test_seed: i64, quote_id: i32, wpm: u8, accuracy: u8, user_id: u32)
-> Result<()> {
let connection = get_connection();