Add ability to update invite count to collab API
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
cfb31067a5
commit
7e2d1fefc4
2 changed files with 21 additions and 5 deletions
|
@ -97,7 +97,8 @@ async fn create_user(
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct UpdateUserParams {
|
struct UpdateUserParams {
|
||||||
admin: bool,
|
admin: Option<bool>,
|
||||||
|
invite_count: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_user(
|
async fn update_user(
|
||||||
|
@ -105,9 +106,16 @@ async fn update_user(
|
||||||
Json(params): Json<UpdateUserParams>,
|
Json(params): Json<UpdateUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
app.db
|
if let Some(admin) = params.admin {
|
||||||
.set_user_is_admin(UserId(user_id), params.admin)
|
app.db.set_user_is_admin(UserId(user_id), admin).await?;
|
||||||
.await?;
|
}
|
||||||
|
|
||||||
|
if let Some(invite_count) = params.invite_count {
|
||||||
|
app.db
|
||||||
|
.set_invite_count(UserId(user_id), invite_count)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -796,11 +796,13 @@ macro_rules! id_type {
|
||||||
}
|
}
|
||||||
|
|
||||||
id_type!(UserId);
|
id_type!(UserId);
|
||||||
#[derive(Clone, Debug, FromRow, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: UserId,
|
pub id: UserId,
|
||||||
pub github_login: String,
|
pub github_login: String,
|
||||||
pub admin: bool,
|
pub admin: bool,
|
||||||
|
pub invite_code: Option<String>,
|
||||||
|
pub invite_count: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
id_type!(OrgId);
|
id_type!(OrgId);
|
||||||
|
@ -912,21 +914,25 @@ pub mod tests {
|
||||||
id: user,
|
id: user,
|
||||||
github_login: "user".to_string(),
|
github_login: "user".to_string(),
|
||||||
admin: false,
|
admin: false,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
User {
|
User {
|
||||||
id: friend1,
|
id: friend1,
|
||||||
github_login: "friend-1".to_string(),
|
github_login: "friend-1".to_string(),
|
||||||
admin: false,
|
admin: false,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
User {
|
User {
|
||||||
id: friend2,
|
id: friend2,
|
||||||
github_login: "friend-2".to_string(),
|
github_login: "friend-2".to_string(),
|
||||||
admin: false,
|
admin: false,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
User {
|
User {
|
||||||
id: friend3,
|
id: friend3,
|
||||||
github_login: "friend-3".to_string(),
|
github_login: "friend-3".to_string(),
|
||||||
admin: false,
|
admin: false,
|
||||||
|
..Default::default()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -1547,6 +1553,8 @@ pub mod tests {
|
||||||
id: user_id,
|
id: user_id,
|
||||||
github_login: github_login.to_string(),
|
github_login: github_login.to_string(),
|
||||||
admin,
|
admin,
|
||||||
|
invite_code: None,
|
||||||
|
invite_count: 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Ok(user_id)
|
Ok(user_id)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue