Allow users with no invites to be fetched from the API

This commit is contained in:
Nathan Sobo 2022-06-24 09:57:52 -06:00
parent b0eb692760
commit 4da3005b5c
2 changed files with 13 additions and 6 deletions

View file

@ -229,6 +229,7 @@ async fn create_users(
Ok(Json(users)) Ok(Json(users))
} }
#[derive(Debug, Deserialize)]
struct GetUsersWithNoInvites { struct GetUsersWithNoInvites {
invited_by_another_user: bool, invited_by_another_user: bool,
} }

View file

@ -262,15 +262,17 @@ impl Db for PostgresDb {
} }
async fn get_users_with_no_invites(&self, invited_by_another_user: bool) -> Result<Vec<User>> { async fn get_users_with_no_invites(&self, invited_by_another_user: bool) -> Result<Vec<User>> {
let query = " let query = format!(
"
SELECT users.* SELECT users.*
FROM users FROM users
WHERE invite_count = 0 WHERE invite_count = 0
"; AND inviter_id IS{} NULL
Ok(sqlx::query_as(query) ",
.bind(&ids) if invited_by_another_user { " NOT" } else { "" }
.fetch_all(&self.pool) );
.await?)
Ok(sqlx::query_as(&query).fetch_all(&self.pool).await?)
} }
async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> { async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
@ -2188,6 +2190,10 @@ pub mod tests {
Ok(ids.iter().filter_map(|id| users.get(id).cloned()).collect()) Ok(ids.iter().filter_map(|id| users.get(id).cloned()).collect())
} }
async fn get_users_with_no_invites(&self, _: bool) -> Result<Vec<User>> {
unimplemented!()
}
async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> { async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
Ok(self Ok(self
.users .users