WIP
This commit is contained in:
parent
b3038c2de9
commit
37fcfeab8d
1 changed files with 17 additions and 9 deletions
|
@ -74,6 +74,7 @@ async fn get_users(Extension(app): Extension<Arc<AppState>>) -> Result<Json<Vec<
|
|||
#[derive(Deserialize)]
|
||||
struct CreateUserParams {
|
||||
github_login: String,
|
||||
invite_code: Option<String>,
|
||||
admin: bool,
|
||||
}
|
||||
|
||||
|
@ -81,6 +82,12 @@ async fn create_user(
|
|||
Json(params): Json<CreateUserParams>,
|
||||
Extension(app): Extension<Arc<AppState>>,
|
||||
) -> Result<Json<User>> {
|
||||
let user = if let Some(invite_code) = params.invite_code {
|
||||
let user_id = app
|
||||
.db
|
||||
.redeem_invite_code(&invite_code, ¶ms.github_login)
|
||||
.await?
|
||||
} else {
|
||||
let user_id = app
|
||||
.db
|
||||
.create_user(¶ms.github_login, params.admin)
|
||||
|
@ -90,7 +97,8 @@ async fn create_user(
|
|||
.db
|
||||
.get_user_by_id(user_id)
|
||||
.await?
|
||||
.ok_or_else(|| anyhow!("couldn't find the user we just created"))?;
|
||||
.ok_or_else(|| anyhow!("couldn't find the user we just created"))?
|
||||
};
|
||||
|
||||
Ok(Json(user))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue