Implement user score

This commit is contained in:
Natsu Kagami 2024-02-13 23:42:55 +01:00
parent da39e6ed25
commit 05ade8370d
Signed by: nki
GPG key ID: 55A032EB38B49ADB
3 changed files with 20 additions and 17 deletions

View file

@ -117,8 +117,6 @@ impl Client {
) -> Result<Vec<Score>, Error> { ) -> Result<Vec<Score>, Error> {
let mut r = UserScoreRequestBuilder::new(u, user); let mut r = UserScoreRequestBuilder::new(u, user);
f(&mut r); f(&mut r);
let res: Vec<raw::Score> = r.build(self).await?.json().await?; r.build(self).await
let res = vec_try_into(res)?;
Ok(res)
} }
} }

View file

@ -288,7 +288,7 @@ pub mod builders {
r.await r.await
} }
})? })?
.unwrap_or(vec![]); .ok_or_else(|| error!("beatmap or user not found"))?;
Ok(scores.into_iter().map(|v| v.into()).collect()) Ok(scores.into_iter().map(|v| v.into()).collect())
} }
} }
@ -325,18 +325,23 @@ pub mod builders {
self self
} }
pub(crate) async fn build(&self, client: &Client) -> Result<Response> { pub(crate) async fn build(self, client: &Client) -> Result<Vec<models::Score>> {
Ok(client let scores = handle_not_found({
.build_request(match self.score_type { let mut r = client.rosu.user_scores(self.user);
UserScoreType::Best => "https://osu.ppy.sh/api/get_user_best", r = match self.score_type {
UserScoreType::Recent => "https://osu.ppy.sh/api/get_user_recent", UserScoreType::Recent => r.recent(),
}) UserScoreType::Best => r.best(),
.await? };
.query(&self.user.to_query()) if let Some(mode) = self.mode {
.query(&self.mode.to_query()) r = r.mode(mode.into());
.query(&self.limit.map(|v| ("limit", v.to_string())).to_query()) }
.send() if let Some(limit) = self.limit {
.await?) r = r.limit(limit as usize);
}
r.await
})?
.ok_or_else(|| error!("user not found"))?;
Ok(scores.into_iter().map(|v| v.into()).collect())
} }
} }
} }

View file

@ -23,7 +23,7 @@ pub use pagination::{paginate, paginate_fn, paginate_reply, paginate_reply_fn, P
pub use async_trait::async_trait; pub use async_trait::async_trait;
/// Re-export the anyhow errors /// Re-export the anyhow errors
pub use anyhow::{Error, Result}; pub use anyhow::{anyhow as error, bail, Error, Result};
pub use debugging_ok::OkPrint; pub use debugging_ok::OkPrint;
/// Re-export useful future and stream utils /// Re-export useful future and stream utils