Skip to main content

dogehouse_api/
queries.rs

1use serde::Deserialize;
2
3/// Defines a query, which takes one or more arguments.
4#[async_trait::async_trait]
5pub trait Query {
6    /// Defines the scheme that the API shall return.
7    type Scheme;
8    /// Defines which args will be passed into the API.
9    type Args;
10    /// Sends the query to the API.
11    async fn send(_: Self::Args) -> Result<Self::Scheme, crate::ErrorType>;
12}
13
14/// Query users by username. The passed-in arg will be a username.
15pub struct UserByUsername;
16#[async_trait::async_trait]
17impl Query for UserByUsername {
18    type Scheme = UsersScheme;
19    /// The username you are searching for.
20    type Args = &'static str;
21    async fn send(username: Self::Args) -> Result<Self::Scheme, crate::ErrorType> {
22        let url = format!("{}/search/{}", crate::endpoints::BASE_URL, username);
23        crate::endpoint!(UsersScheme,url)
24    }
25}
26
27#[derive(Deserialize, PartialEq, Clone, Debug)]
28#[serde(rename_all = "camelCase")]
29/// Defines all users which are caught by the [UserByUsername] request.
30pub struct UsersScheme {
31    items: Vec<crate::endpoints::User>,
32}