platz_sdk/resources/
users.rs

1use crate::client::PlatzClient;
2use anyhow::Result;
3use chrono::prelude::*;
4use kv_derive::{prelude::*, IntoVec};
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7
8#[derive(Debug, Deserialize, Clone)]
9pub struct User {
10    pub id: Uuid,
11    pub created_at: DateTime<Utc>,
12    pub display_name: String,
13    pub email: String,
14    pub is_admin: bool,
15    pub is_active: bool,
16}
17
18#[derive(Default, IntoVec)]
19pub struct UserFilter {
20    #[kv(optional)]
21    pub display_name: Option<String>,
22    #[kv(optional)]
23    pub email: Option<String>,
24    #[kv(optional)]
25    pub is_active: Option<bool>,
26}
27
28#[derive(Debug, Serialize)]
29pub struct UpdateUser {
30    pub is_admin: Option<bool>,
31    pub is_active: Option<bool>,
32}
33
34impl PlatzClient {
35    pub async fn users(&self, filters: UserFilter) -> Result<Vec<User>> {
36        Ok(self
37            .request(reqwest::Method::GET, "/api/v2/users")
38            .add_to_query(filters.into_vec())
39            .paginated()
40            .await?)
41    }
42
43    pub async fn user(&self, user_id: Uuid) -> Result<User> {
44        Ok(self
45            .request(reqwest::Method::GET, format!("/api/v2/users/{user_id}"))
46            .send()
47            .await?)
48    }
49
50    pub async fn update_user(&self, user_id: Uuid, update_user: UpdateUser) -> Result<User> {
51        Ok(self
52            .request(reqwest::Method::PUT, format!("/api/v2/users/{user_id}"))
53            .send_with_body(update_user)
54            .await?)
55    }
56}