core-api-upgrade

This commit is contained in:
Untone 2023-11-28 12:14:18 +03:00
parent 77420289be
commit e44590a6a3

View File

@ -65,12 +65,8 @@ pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
async fn get_shout_followers(shout_id: &str) -> Result<Vec<i32>, Box<dyn Error>> {
let api_base = env::var("API_BASE")?;
let query = r#"query ShoutFollowers($shout: Int!) {
shoutFollowers(shout: $shout) {
follower {
id
}
}
let query = r#"query GetShoutFollowers($slug: String, shout_id: Int) {
get_shout_followers(slug: $slug, shout_id: $shout_id) { id }
}
"#;
let shout_id = shout_id.parse::<i32>()?;
@ -79,7 +75,7 @@ async fn get_shout_followers(shout_id: &str) -> Result<Vec<i32>, Box<dyn Error>>
});
let body = json!({
"query": query,
"operationName": "ShoutFollowers",
"operationName": "GetShoutFollowers",
"variables": variables
});
@ -88,11 +84,11 @@ async fn get_shout_followers(shout_id: &str) -> Result<Vec<i32>, Box<dyn Error>>
if response.status().is_success() {
let response_body: serde_json::Value = response.json().await?;
let ids: Vec<i32> = response_body["data"]["shoutFollowers"]
let ids: Vec<i32> = response_body["data"]["get_shout_followers"]
.as_array()
.ok_or("Failed to parse follower array")?
.iter()
.filter_map(|f| f["follower"]["id"].as_i64().map(|id| id as i32))
.filter_map(|f| f["id"].as_i64().map(|id| id as i32))
.collect();
Ok(ids)