(&self, pool: &PgPool)
| 98 | } |
| 99 | |
| 100 | pub async fn call(&self, pool: &PgPool) -> Result<UpsertUserResult> { |
| 101 | let username = &self.input.github_username; |
| 102 | |
| 103 | let query = format!( |
| 104 | r#"select |
| 105 | {USER_FIELDS} |
| 106 | from users u |
| 107 | left join users_repositories ur on u.id = ur.user_id |
| 108 | join github_accounts ga on u.id = ga.user_id |
| 109 | where ga.username = $1 |
| 110 | group by u.id"# |
| 111 | ); |
| 112 | let result = sqlx::query_as::<_, Row>(&query) |
| 113 | .bind(username) |
| 114 | .fetch_optional(pool) |
| 115 | .await?; |
| 116 | |
| 117 | let user = match result { |
| 118 | Some(row) => row, |
| 119 | None => { |
| 120 | log::info!("user {} not found, creating", username); |
| 121 | let mut tx = pool.begin().await?; |
| 122 | let user = self.create_github_user(&mut tx).await?; |
| 123 | CompleteRegistration::new(&user, &self.input.github_username) |
| 124 | .call(&mut tx) |
| 125 | .await?; |
| 126 | tx.commit().await?; |
| 127 | user |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | Ok(UpsertUserResult { user }) |
| 132 | } |
| 133 | |
| 134 | async fn create_github_user(&self, tx: &mut PgTransaction<'_>) -> Result<Row> { |
| 135 | let row = sqlx::query_as::<_, Row>( |
nothing calls this directly
no test coverage detected