feat(server): working friend page

This commit is contained in:
Maieul BOYER 2026-02-08 23:34:44 +01:00
parent 83433186f3
commit 0b17c760cb
Signed by: maix
SSH key fingerprint: SHA256:iqCzqFFF5KjRixmDExqbAltCIj9ndlBWIGJf3t9Ln9g
2126 changed files with 35620 additions and 42 deletions

View file

@ -14,6 +14,7 @@ thiserror = "2.0.18"
url = "2.5.8"
serde = { workspace = true }
smol_str = { workspace = true }
log = { workspace = true }
[dev-dependencies]
tokio = { workspace = true }

View file

@ -96,6 +96,12 @@ impl State {
let mut u = self.base_url.clone();
u.set_path(url.as_ref());
u.set_query(qs);
log::debug!(
"Making request to upstream: [{}] {} {}",
method,
u.path(),
u.query().unwrap_or("")
);
let builder = self
.client
.request(method, u)
@ -126,7 +132,10 @@ impl State {
self.request(Method::POST, url.as_ref(), qs, None).await
}
pub async fn get_user(&self, name: &str) -> Result<Option<crate::types::Profile>, GetUserError> {
pub async fn get_user(
&self,
name: &str,
) -> Result<Option<crate::types::Profile>, GetUserError> {
let req = self.get(format!("/getuser/{name}"), None).await?;
let text = req.text().await?;
let json = serde_json::from_str::<crate::types::ProfileRaw>(&text)?;
@ -170,6 +179,31 @@ impl State {
.await
.map(|r| r.status().is_success())
}
pub async fn remove_friend(&self, name: impl AsRef<str>) -> Result<bool, reqwest::Error> {
self.get(format!("/friends/remove/{}", name.as_ref()), None)
.await
.map(|r| r.status().is_success())
}
pub async fn set_friend_relation(
&self,
name: impl AsRef<str>,
relation: i32,
) -> Result<bool, reqwest::Error> {
self.get(
format!("/friends/set_relation/{}/{relation}", name.as_ref()),
None,
)
.await
.map(|r| r.status().is_success())
}
pub async fn get_friend_list(&self) -> Result<crate::types::Friends, reqwest::Error> {
Ok(crate::parsing::friend_page(
self.get("/friends/", None).await?.text().await?,
))
}
}
#[derive(Debug, thiserror::Error)]