working example

This commit is contained in:
Jonas Rabenstein 2026-03-05 01:57:37 +01:00
commit e69bcfc23d
18 changed files with 1290 additions and 252 deletions

41
api/src/user.rs Normal file
View file

@ -0,0 +1,41 @@
use serde::Deserialize;
use restson::{RestClient, RestPath, Error};
use super::{
UserId as Id,
};
#[derive(Debug, Deserialize)]
pub struct User {
pub id: Id,
#[serde(flatten)]
unknown: serde_json::Value,
}
impl std::fmt::Display for User {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", serde_json::to_string_pretty(&self.unknown).unwrap())
}
}
impl RestPath<()> for User {
fn get_path(_: ()) -> std::result::Result<String, Error> {
Ok(format!("user"))
}
}
impl RestPath<(Id, )> for User {
fn get_path(args: (Id, )) -> std::result::Result<String, Error> {
let (id, ) = args;
Ok(format!("user/{id}"))
}
}
pub async fn identity(client: &RestClient) -> Result<User, Error> {
Ok(client.get_with::<_, User>((), &[]).await?.into_inner())
}
pub async fn with_id(client: &RestClient, id: Id) -> Result<User, Error> {
Ok(client.get_with::<_, User>((id, ), &[]).await?.into_inner())
}