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)]
|
#[derive(Deserialize)]
|
||||||
struct CreateUserParams {
|
struct CreateUserParams {
|
||||||
github_login: String,
|
github_login: String,
|
||||||
|
invite_code: Option<String>,
|
||||||
admin: bool,
|
admin: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,16 +82,23 @@ async fn create_user(
|
||||||
Json(params): Json<CreateUserParams>,
|
Json(params): Json<CreateUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
) -> Result<Json<User>> {
|
) -> Result<Json<User>> {
|
||||||
let user_id = app
|
let user = if let Some(invite_code) = params.invite_code {
|
||||||
.db
|
let user_id = app
|
||||||
.create_user(¶ms.github_login, params.admin)
|
.db
|
||||||
.await?;
|
.redeem_invite_code(&invite_code, ¶ms.github_login)
|
||||||
|
.await?
|
||||||
|
} else {
|
||||||
|
let user_id = app
|
||||||
|
.db
|
||||||
|
.create_user(¶ms.github_login, params.admin)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let user = app
|
let user = app
|
||||||
.db
|
.db
|
||||||
.get_user_by_id(user_id)
|
.get_user_by_id(user_id)
|
||||||
.await?
|
.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))
|
Ok(Json(user))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue