Skip to content

Commit

Permalink
chore: post creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Liendo committed Sep 15, 2024
1 parent 22c7cd6 commit 1908a7a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/client/src/modules/post/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod post_create;
pub mod posts;

use anyhow::Result;
use post_create::post_create::PostCreateInput;
use pxid::Pxid;
use reqwest::{Client, Url};

Expand All @@ -17,6 +19,10 @@ impl PostClient {
}
}

pub async fn post_create(&self, input: PostCreateInput) -> Result<post_create::PostCreate> {
post_create::posts(self, input).await
}

pub async fn posts(
&self,
after: Option<Pxid>,
Expand Down
38 changes: 38 additions & 0 deletions crates/client/src/modules/post/post_create/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use anyhow::{anyhow, Result};
use graphql_client::reqwest::post_graphql;
use graphql_client::GraphQLQuery;
use pxid::Pxid;

use post_create::{
PostCreateInput, PostCreatePostCreateError, PostCreatePostCreatePost, Variables,
};

use crate::{DateTime, GRAPHQL_PATH};

use super::PostClient;

#[derive(GraphQLQuery)]
#[graphql(
response_derives = "Clone,Debug,Deserialize",
schema_path = "schema.json",
query_path = "src/modules/post/post_create/PostCreate.gql"
)]
pub struct PostCreate {
pub post: Option<PostCreatePostCreatePost>,
pub error: Option<PostCreatePostCreateError>,
}

pub async fn posts(public_client: &PostClient, input: PostCreateInput) -> Result<PostCreate> {
let url = public_client.domain.join(GRAPHQL_PATH)?;
let variables = Variables { input };

let res = post_graphql::<PostCreate, _>(&public_client.client, url, variables)
.await
.map_err(|err| anyhow!("Failed to create post. {err}"))?;
let data = res.data.unwrap().post_create;

Ok(PostCreate {
post: data.post,
error: data.error,
})
}

0 comments on commit 1908a7a

Please sign in to comment.