feat: def interface to get user data
This commit is contained in:
parent
54a1d28395
commit
653088376a
2 changed files with 30 additions and 0 deletions
|
@ -73,6 +73,20 @@ pub fn get_hostname(url: &Url) -> String {
|
|||
url.host().as_ref().unwrap().to_string()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
/// user data
|
||||
pub struct User {
|
||||
/// 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: String,
|
||||
/// username of the user
|
||||
pub username: String,
|
||||
/// html link to the user profile
|
||||
pub html_link: String,
|
||||
/// OPTIONAL: html link to the user's profile photo
|
||||
pub profile_photo: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
/// add new user to database
|
||||
pub struct AddUser<'a> {
|
||||
|
@ -186,6 +200,9 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||
/// add new user to database
|
||||
async fn add_user(&self, u: &AddUser) -> DBResult<()>;
|
||||
|
||||
/// get user data
|
||||
async fn get_user(&self, username: &str, hostname: &str) -> DBResult<User>;
|
||||
|
||||
/// 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<bool>;
|
||||
|
|
|
@ -42,6 +42,19 @@ pub async fn adding_forge_works<'a, T: SCDatabase>(
|
|||
// add user
|
||||
db.add_user(&add_user_msg).await.unwrap();
|
||||
db.add_user(&add_user_msg2).await.unwrap();
|
||||
{
|
||||
let db_user = db
|
||||
.get_user(add_user_msg.username, add_user_msg.hostname)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(db_user.hostname, add_user_msg.hostname);
|
||||
assert_eq!(db_user.username, add_user_msg.username);
|
||||
assert_eq!(db_user.html_link, add_user_msg.html_link);
|
||||
assert_eq!(
|
||||
db_user.profile_photo,
|
||||
add_user_msg.profile_photo.map(|s| s.to_owned())
|
||||
);
|
||||
}
|
||||
// verify user exists
|
||||
assert!(db.user_exists(add_user_msg.username, None).await.unwrap());
|
||||
assert!(db
|
||||
|
|
Loading…
Reference in a new issue