-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit 0a57a66.
- Loading branch information
Showing
5 changed files
with
32 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,20 +125,10 @@ impl DbConn { | |
|
||
pub async fn list_users_with_filter( | ||
&self, | ||
emails: Option<Vec<String>>, | ||
limit: Option<usize>, | ||
skip_id: Option<i32>, | ||
backwards: bool, | ||
) -> Result<Vec<UserDAO>> { | ||
let email_condition = emails.map(|emails| { | ||
let emails = emails | ||
.into_iter() | ||
.map(|e| format!("'{}'", e)) | ||
.collect::<Vec<_>>() | ||
.join(", "); | ||
format!("email in ({emails})") | ||
}); | ||
|
||
let users = query_paged_as!( | ||
UserDAO, | ||
"users", | ||
|
@@ -155,8 +145,7 @@ impl DbConn { | |
], | ||
limit, | ||
skip_id, | ||
backwards, | ||
email_condition | ||
backwards | ||
) | ||
.fetch_all(&self.pool) | ||
.await?; | ||
|
@@ -410,64 +399,60 @@ mod tests { | |
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, None, None, false) | ||
conn.list_users_with_filter(None, None, false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), None, false) | ||
conn.list_users_with_filter(Some(2), None, false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, None, Some(1), false) | ||
conn.list_users_with_filter(None, Some(1), false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), Some(1), false) | ||
conn.list_users_with_filter(Some(2), Some(1), false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
// backwards | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, None, None, true) | ||
.await | ||
.unwrap() | ||
) | ||
to_ids(conn.list_users_with_filter(None, None, true).await.unwrap()) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), None, true) | ||
conn.list_users_with_filter(Some(2), None, true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, None, Some(1), true) | ||
conn.list_users_with_filter(None, Some(1), true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(1), Some(1), true) | ||
conn.list_users_with_filter(Some(1), Some(1), true) | ||
.await | ||
.unwrap() | ||
) | ||
|
@@ -488,112 +473,65 @@ mod tests { | |
assert_eq!( | ||
vec![id1], | ||
to_ids( | ||
conn.list_users_with_filter(None, None, None, false) | ||
conn.list_users_with_filter(None, None, false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
vec![id1], | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), None, false) | ||
conn.list_users_with_filter(Some(2), None, false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, None, Some(1), false) | ||
conn.list_users_with_filter(None, Some(1), false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), Some(1), false) | ||
conn.list_users_with_filter(Some(2), Some(1), false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
// backwards | ||
assert_eq!( | ||
vec![id1], | ||
to_ids( | ||
conn.list_users_with_filter(None, None, None, true) | ||
.await | ||
.unwrap() | ||
) | ||
to_ids(conn.list_users_with_filter(None, None, true).await.unwrap()) | ||
); | ||
assert_eq!( | ||
vec![id1], | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), None, true) | ||
conn.list_users_with_filter(Some(2), None, true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, None, Some(1), true) | ||
conn.list_users_with_filter(None, Some(1), true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(1), Some(1), true) | ||
conn.list_users_with_filter(Some(1), Some(1), true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
|
||
// by email | ||
assert_eq!( | ||
vec![id1], | ||
to_ids( | ||
conn.list_users_with_filter( | ||
Some(vec!["[email protected]".into()]), | ||
None, | ||
None, | ||
true | ||
) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
|
||
assert_eq!( | ||
vec![id1], | ||
to_ids( | ||
conn.list_users_with_filter( | ||
Some(vec!["[email protected]".into()]), | ||
Some(1), | ||
None, | ||
true | ||
) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
|
||
assert_eq!( | ||
empty, | ||
to_ids( | ||
conn.list_users_with_filter( | ||
Some(vec!["[email protected]".into()]), | ||
None, | ||
None, | ||
true | ||
) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
|
||
let id2 = conn | ||
.create_user( | ||
"[email protected]".into(), | ||
|
@@ -636,83 +574,64 @@ mod tests { | |
assert_eq!( | ||
vec![id1, id2, id3, id4, id5], | ||
to_ids( | ||
conn.list_users_with_filter(None, None, None, false) | ||
conn.list_users_with_filter(None, None, false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
vec![id1, id2], | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), None, false) | ||
conn.list_users_with_filter(Some(2), None, false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
vec![id3, id4, id5], | ||
to_ids( | ||
conn.list_users_with_filter(None, None, Some(2), false) | ||
conn.list_users_with_filter(None, Some(2), false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
vec![id3, id4], | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), Some(2), false) | ||
conn.list_users_with_filter(Some(2), Some(2), false) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
// backwards | ||
assert_eq!( | ||
vec![id1, id2, id3, id4, id5], | ||
to_ids( | ||
conn.list_users_with_filter(None, None, None, true) | ||
.await | ||
.unwrap() | ||
) | ||
to_ids(conn.list_users_with_filter(None, None, true).await.unwrap()) | ||
); | ||
assert_eq!( | ||
vec![id4, id5], | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), None, true) | ||
conn.list_users_with_filter(Some(2), None, true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
vec![id1, id2, id3], | ||
to_ids( | ||
conn.list_users_with_filter(None, None, Some(4), true) | ||
conn.list_users_with_filter(None, Some(4), true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
assert_eq!( | ||
vec![id2, id3], | ||
to_ids( | ||
conn.list_users_with_filter(None, Some(2), Some(4), true) | ||
conn.list_users_with_filter(Some(2), Some(4), true) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
|
||
// by email | ||
assert_eq!( | ||
vec![id2, id3], | ||
to_ids( | ||
conn.list_users_with_filter( | ||
Some(vec!["[email protected]".into(), "[email protected]".into()]), | ||
None, | ||
None, | ||
false | ||
) | ||
.await | ||
.unwrap() | ||
) | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.