allow to assign automatically current user on new work package
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
use crate::openproject::client::{handle_response_status, Client, Error};
|
||||
use crate::openproject::hal::Link;
|
||||
use crate::openproject::root::RootClient;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct UserLink {
|
||||
#[serde(rename = "self")]
|
||||
pub d_self: Link,
|
||||
}
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct User {
|
||||
#[serde(rename = "_type")]
|
||||
pub d_type: String,
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
#[serde(rename = "_links")]
|
||||
pub d_links: UserLink,
|
||||
}
|
||||
|
||||
pub trait GetMe {
|
||||
async fn me(&self) -> Result<User, Error>;
|
||||
}
|
||||
|
||||
impl GetMe for Client {
|
||||
async fn me(&self) -> Result<User, Error> {
|
||||
let r = self.root().await?;
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let response = client
|
||||
.get(format!("{}{}", self.base_url, r.links.user.href))
|
||||
.basic_auth("apikey", Some(&self.token))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
let u = handle_response_status(response, "Error while retrieving user").await?;
|
||||
|
||||
Ok(u)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user