gitea_sdk/api/search/
users.rs

1use build_it::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::Result;
5use crate::model::user::User;
6
7/// Options for searching users.
8/// All fields are optional.
9#[derive(Default, Debug, Clone, Serialize, Builder)]
10#[build_it(into)]
11pub struct SearchUsersBuilder {
12    /// Keyword to search for
13    #[serde(rename = "q")]
14    query: Option<String>,
15    /// ID of the user to search for
16    uid: Option<i64>,
17    /// Page number of results to return (1-based)
18    page: Option<i32>,
19    /// Page size of results
20    limit: Option<i32>,
21}
22
23impl SearchUsersBuilder {
24    pub fn new() -> Self {
25        Self::default()
26    }
27    /// Send the request to get the repository.
28    /// This will return a [Vec<User>] object if the repository exists and is visible to the
29    /// currently authenticated user.
30    pub async fn send(&self, client: &crate::Client) -> Result<Vec<User>> {
31        let req = client.get("users/search".to_string()).query(self).build()?;
32        #[derive(Deserialize)]
33        struct Response {
34            #[allow(dead_code)]
35            ok: bool,
36            data: Vec<User>,
37        }
38        let res = client.make_request(req).await?;
39        Ok(client.parse_response::<Response>(res).await?.data)
40    }
41}