diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 91bfdb4..0eab822 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -40,6 +40,7 @@ pub mod ops; #[cfg(feature = "test")] pub mod tests; +use dev::*; pub use ops::GetConnection; pub mod prelude { @@ -65,7 +66,20 @@ pub struct CreateForge<'a> { pub forge_type: ForgeImplementation, } -use dev::*; +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +/// add new user to database +pub struct AddUser<'a> { + /// hostname of the forge instance: with scheme but remove trailing slash + /// hostname can be derived from html_link also, but used to link to user's forge instance + pub hostname: &'a str, + /// username of the user + pub username: &'a str, + /// html link to the user profile + pub html_link: &'a str, + /// OPTIONAL: html link to the user's profile photo + pub profile_photo: Option<&'a str>, +} + #[async_trait] /// Starchart's database requirements. To implement support for $Database, kindly implement this /// trait. @@ -84,6 +98,13 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { /// check if forge type exists async fn forge_type_exists(&self, forge_type: &ForgeImplementation) -> DBResult; + + /// add new user to database + async fn add_user(&self, u: &AddUser) -> DBResult<()>; + + /// check if an user exists. When hostname of a forge instace is provided, username search is + /// done only on that forge + async fn user_exists(&self, username: &str, hostname: Option<&str>) -> DBResult; } /// Trait to clone SCDatabase diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index caef4d1..f97c56c 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -19,13 +19,21 @@ use crate::prelude::*; /// adding forge works -pub async fn adding_forge_works(db: &T, create_forge_msg: CreateForge<'static>) { +pub async fn adding_forge_works( + db: &T, + create_forge_msg: CreateForge<'static>, + add_user_msg: AddUser<'static>, + add_user_msg2: AddUser<'static>, +) { let _ = db.delete_forge_instance(&create_forge_msg.hostname).await; db.create_forge_isntance(&create_forge_msg).await.unwrap(); assert!( db.forge_exists(create_forge_msg.hostname).await.unwrap(), "forge creation failed, forge existance check failure" ); + + db.add_user(&add_user_msg).await.unwrap(); + db.add_user(&add_user_msg2).await.unwrap(); } /// test if all forge type implementations are loaded into DB