diff --git a/src/model/mod.rs b/src/model/mod.rs index 03530f7..0115c70 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -13,7 +13,6 @@ pub mod trip; pub mod tripdetails; pub mod user; pub mod usertrip; -//pub mod users; #[derive(Serialize)] pub struct Day { diff --git a/src/model/users.rs b/src/model/users.rs deleted file mode 100644 index cc39f84..0000000 --- a/src/model/users.rs +++ /dev/null @@ -1,61 +0,0 @@ -pub struct Users { - users: Vec, -} - -#[derive(Debug)] -pub enum Error {} - -//#[rocket::async_trait] -//impl<'r> FromRequest<'r> for User { -// type Error = Error; -// -// async fn from_request(req: &'r Request<'_>) -> request::Outcome { -// //TODO: https://betterprogramming.pub/building-the-rust-web-app-multiple-users-and-authentication-5ca5988ddfe4 -// } -//} - -impl Deref for Users { - type Target = Vec; - - fn deref(&self) -> &Self::Target { - &self.users - } -} - -impl Users { - pub async fn new(pool: &SqlitePool) -> Result { - let users: Vec = sqlx::query_as!( - User, - r#" -SELECT id, name, pw, is_cox, is_admin, is_guest -FROM user - "#, - ) - .fetch_all(pool) - .await?; - - Ok(Self { users }) - } -} - -#[cfg(test)] -mod test { - use super::Users; - use sqlx::SqlitePool; - - #[sqlx::test] - fn user_with_test_db() { - let pool = SqlitePool::connect(":memory:").await.unwrap(); - sqlx::query_file!("./migration.sql") - .execute(&pool) - .await - .unwrap(); - sqlx::query_file!("./seeds.sql") - .execute(&pool) - .await - .unwrap(); - - let users = Users::new(&pool).await.unwrap(); - assert_eq!(users.len(), 4); - } -}