diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..4d9636b
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "rust-analyzer.showUnlinkedFileNotification": false
+}
\ No newline at end of file
diff --git a/documentation/not_found.html b/documentation/not_found.html
new file mode 100644
index 0000000..446e782
--- /dev/null
+++ b/documentation/not_found.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+ The content you are looking for does not appear to be here...
+
+
+
\ No newline at end of file
diff --git a/public/Error/not_found.html b/public/Error/not_found.html
new file mode 100644
index 0000000..ff4db94
--- /dev/null
+++ b/public/Error/not_found.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+ Not Found
+
+
+ The content you are looking for does not appear to be here...
+
+
+
\ No newline at end of file
diff --git a/src/typing/leaderboard.rs b/src/api/leaderboard.rs
similarity index 55%
rename from src/typing/leaderboard.rs
rename to src/api/leaderboard.rs
index 6e808d2..c0d18e3 100644
--- a/src/typing/leaderboard.rs
+++ b/src/api/leaderboard.rs
@@ -1,8 +1,5 @@
-use rocket::{ serde::json::Json, State };
-use crate::typing::sql::{
- Database,
- LeaderBoardTest
-};
+use crate::api::sql::{Database, LeaderBoardTest};
+use rocket::{serde::json::Json, State};
type LeaderBoardTests = Vec;
@@ -10,15 +7,14 @@ type LeaderBoardTests = Vec;
/// a json array
/// Acessible from http://url/api/leaderboard
#[get("/leaderboard")]
-pub async fn leaderboard( database: &State ) -> Option> {
+pub async fn leaderboard(database: &State) -> Option> {
let leaderboard = match database.get_leaderboard(0).await {
- Err(why) => {
+ Err(why) => {
println!("Error getting leaderboard, {why}");
- return None
+ return None;
}
- Ok(leaderboard) => { leaderboard }
+ Ok(leaderboard) => leaderboard,
};
Some(Json(leaderboard))
}
-
diff --git a/src/typing/mod.rs b/src/api/mod.rs
similarity index 77%
rename from src/typing/mod.rs
rename to src/api/mod.rs
index 7c3efda..0bda601 100644
--- a/src/typing/mod.rs
+++ b/src/api/mod.rs
@@ -1,4 +1,4 @@
-pub mod sql;
-pub mod user;
pub mod leaderboard;
-pub mod test;
\ No newline at end of file
+pub mod sql;
+pub mod test;
+pub mod user;
diff --git a/src/typing/sql.rs b/src/api/sql.rs
similarity index 52%
rename from src/typing/sql.rs
rename to src/api/sql.rs
index 022107c..c264175 100644
--- a/src/typing/sql.rs
+++ b/src/api/sql.rs
@@ -4,16 +4,16 @@
//! it abstracts away the rusqlite necessary to perform
//! these functions
//! Author: Arlo Filley
-//!
-//! TODO:
+//!
+//! TODO:
//! - put necessary structs into a different file
-//! - create structure for the input of post test
+//! - create structure for the input of post test
// Imports for json handling and rusqlite
-use sqlx::sqlite::{ SqlitePool, SqlitePoolOptions };
-use rocket::serde::{ Serialize, json::Json };
+use rocket::serde::{json::Json, Serialize};
+use sqlx::sqlite::{SqlitePool, SqlitePoolOptions};
-use crate::typing::test::PostTest;
+use crate::api::test::PostTest;
/// Contains the database connection pool
pub struct Database(SqlitePool);
@@ -24,7 +24,7 @@ impl Database {
pub async fn new() -> Result {
let pool = SqlitePoolOptions::new()
.max_connections(2)
- .connect("sqlite:/Users/arlo/code/cs_coursework/database/dev/database.sqlite")
+ .connect("sqlite:/Users/arlo/Code/Projects/cs_coursework/database/database.sqlite")
.await?;
Ok(Self(pool))
@@ -33,16 +33,20 @@ impl Database {
/// Creates the necessary tables inside the database with
/// correct normalised links between data for later querying
pub async fn _new_database(&self) -> Result<(), sqlx::Error> {
- sqlx::query!("
+ sqlx::query!(
+ "
CREATE TABLE IF NOT EXISTS Users (
user_id INTEGER PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
secret TEXT NOT NULL
)"
- ).execute(&self.0).await?;
+ )
+ .execute(&self.0)
+ .await?;
- sqlx::query!("
+ sqlx::query!(
+ "
CREATE TABLE IF NOT EXISTS Tests (
test_id INTEGER PRIMARY KEY,
test_type TEXT NOT NULL,
@@ -55,7 +59,9 @@ impl Database {
user_id INTEGER,
FOREIGN KEY(user_id) REFERENCES users(user_id)
)"
- ).execute(&self.0).await?;
+ )
+ .execute(&self.0)
+ .await?;
Ok(())
}
@@ -64,15 +70,18 @@ impl Database {
/// a database record with the data
pub async fn create_test(&self, test: Json>) -> Result<(), sqlx::Error> {
// Test to see whether the secret is correct
- let user = sqlx::query!("
+ let user = sqlx::query!(
+ "
Select secret
From Users
- Where user_id=?",
+ Where user_id=?",
test.user_id
- ).fetch_one(&self.0).await?;
+ )
+ .fetch_one(&self.0)
+ .await?;
if user.secret != test.secret {
- return Err(sqlx::Error::RowNotFound)
+ return Err(sqlx::Error::RowNotFound);
}
sqlx::query!("
@@ -86,25 +95,43 @@ impl Database {
/// takes a username and password and creates a database
/// entry for a new user
- pub async fn create_user(&self, username: &str, password: &str, secret: &str) -> Result<(), sqlx::Error> {
- sqlx::query!("
+ pub async fn create_user(
+ &self,
+ username: &str,
+ password: &str,
+ secret: &str,
+ ) -> Result<(), sqlx::Error> {
+ sqlx::query!(
+ "
INSERT INTO Users (username, password, secret)
- VALUES (?1, ?2, ?3)",
- username, password, secret
- ).execute(&self.0).await?;
+ VALUES (?1, ?2, ?3)",
+ username,
+ password,
+ secret
+ )
+ .execute(&self.0)
+ .await?;
Ok(())
}
/// takes a username and password as inputs and returns the
/// user_id and secret of the user if one exists
- pub async fn find_user(&self, username: &str, password: &str) -> Result