mongodb_atlas_admin/api/projects/
create_one.rs1use std::borrow::Cow;
2
3use http::Method;
4use reqwest::Response;
5use serde::Serialize;
6
7use super::Project;
8use crate::Endpoint;
9
10#[derive(Debug, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct CreateOneProject {
13 pub name: String,
14 pub org_id: String,
15}
16
17pub type CreateOneProjectData = Project;
18
19#[derive(Debug, thiserror::Error)]
20#[error("Error")]
21pub struct Error;
22
23#[async_trait::async_trait]
24impl Endpoint for CreateOneProject {
25 type Data = CreateOneProjectData;
26 type Error = Error;
27
28 fn method() -> Method {
29 Method::POST
30 }
31
32 fn path(&self) -> Cow<'static, str> {
33 Cow::from("/groups")
34 }
35
36 fn body(&self) -> Result<Option<Vec<u8>>, Self::Error> {
37 Ok(Some(serde_json::to_vec(self).unwrap()))
38 }
39
40 async fn get_data(res: Response) -> Result<Self::Data, Self::Error> {
41 Ok(res.json::<Self::Data>().await.unwrap())
42 }
43}