summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/guards/mod.rs1
-rw-r--r--src/api/guards/session.rs25
-rw-r--r--src/api/mod.rs2
-rw-r--r--src/api/routes/mod.rs1
-rw-r--r--src/api/routes/test.rs9
5 files changed, 38 insertions, 0 deletions
diff --git a/src/api/guards/mod.rs b/src/api/guards/mod.rs
new file mode 100644
index 0000000..f52f1c4
--- /dev/null
+++ b/src/api/guards/mod.rs
@@ -0,0 +1 @@
+pub mod session;
diff --git a/src/api/guards/session.rs b/src/api/guards/session.rs
new file mode 100644
index 0000000..ccd40a2
--- /dev/null
+++ b/src/api/guards/session.rs
@@ -0,0 +1,25 @@
+use std::str::FromStr;
+
+use rocket::{http::Status, outcome::Outcome, request::{self, Request, FromRequest}};
+use sqlx::PgPool;
+use uuid::Uuid;
+use crate::db::models::auth::LoginSession;
+
+
+#[rocket::async_trait]
+impl<'r> FromRequest<'r> for LoginSession {
+    type Error = ();
+
+    async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
+        // At the moment just always look up this one for initial testing
+        let hardcoded_uuid = "557621dd-b98e-409a-9ce7-25b5004caa42";
+
+        if let Some(db) = req.rocket().state::<PgPool>() {
+            if let Some(session) = LoginSession::lookup(&db, Uuid::from_str(hardcoded_uuid).unwrap()).await {
+                return Outcome::Success(session);
+            }
+        }
+
+        Outcome::Error((Status::InternalServerError, ()))
+    }
+}
diff --git a/src/api/mod.rs b/src/api/mod.rs
new file mode 100644
index 0000000..47e142d
--- /dev/null
+++ b/src/api/mod.rs
@@ -0,0 +1,2 @@
+pub mod routes;
+pub mod guards;
diff --git a/src/api/routes/mod.rs b/src/api/routes/mod.rs
new file mode 100644
index 0000000..7b788c2
--- /dev/null
+++ b/src/api/routes/mod.rs
@@ -0,0 +1 @@
+pub mod test;
diff --git a/src/api/routes/test.rs b/src/api/routes/test.rs
new file mode 100644
index 0000000..718c634
--- /dev/null
+++ b/src/api/routes/test.rs
@@ -0,0 +1,9 @@
+use rocket::get;
+use rocket::serde::json::Json;
+
+use crate::db::models::auth::LoginSession;
+
+#[get("/test")]
+pub fn testroute(session: LoginSession) -> Json<LoginSession> {
+    Json(session)
+}