This commit is contained in:
Nathan Sobo 2022-05-18 11:51:47 -06:00
parent b3038c2de9
commit 37fcfeab8d

View file

@ -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, &params.github_login)
.await?
} else {
let user_id = app
.db
.create_user(&params.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))
}