feat: completed migration

Closes #4
This commit is contained in:
silver 2023-09-26 00:57:03 +01:00
parent f11fdb4dde
commit 8760f4440a
7 changed files with 43 additions and 219 deletions

View file

@ -16,8 +16,7 @@ async fn main() {
get_wolves_csv(&db, &config).await;
// handle wolves api here
get_wolves(&db).await;
// get from skynet for the compsoc server only
get_skynet(&db, &config).await;
}
async fn get_wolves_csv(db: &Pool<Sqlite>, config: &Config) {
@ -133,35 +132,6 @@ pub struct SkynetResult {
discord: String,
id_member: String,
}
async fn get_skynet(db: &Pool<Sqlite>, config: &Config) {
let url = format!("{}/ldap/discord?auth={}", &config.ldap_api, &config.auth);
if let Ok(result) = surf::get(url).recv_json::<Vec<SkynetResult>>().await {
for user in result {
add_users_skynet(db, &user).await;
}
}
}
async fn add_users_skynet(db: &Pool<Sqlite>, user: &SkynetResult) {
match sqlx::query_as::<_, Wolves>(
"
UPDATE wolves
SET discord = ?
WHERE id_wolves = ?
",
)
.bind(&user.discord)
.bind(&user.id_member)
.fetch_optional(db)
.await
{
Ok(_) => {}
Err(e) => {
println!("Failure to insert skynet user into database {:?}", user);
println!("{:?}", e);
}
}
}
#[derive(Debug, Deserialize)]
struct WolvesResult {