mongodb_atlas_admin/api/projects/
delete_one.rs1use std::borrow::Cow;
2
3use http::{Method, StatusCode};
4use reqwest::Response;
5use serde::{Deserialize, Serialize};
6
7use crate::{endpoint::RequestError, Endpoint};
8
9#[derive(Debug, Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct DeleteOneProject {
12 pub group_id: String,
13}
14
15#[derive(Debug, Deserialize)]
16pub struct DeleteOneProjectData {}
17
18#[derive(Debug, thiserror::Error)]
19pub enum Error {
20 #[error("Bad request JSON")]
21 BadRequestJson(#[from] serde_json::Error),
22 #[error("Bad request")]
23 BadRequest(RequestError),
24 #[error("Conflict")]
25 Conflict(RequestError),
26 #[error("Internal server error")]
27 InternalServerError(RequestError),
28 #[error("Bad response")]
29 BadResponse(#[from] reqwest::Error),
30}
31
32#[async_trait::async_trait]
33impl Endpoint for DeleteOneProject {
34 type Data = DeleteOneProjectData;
35 type Error = Error;
36
37 fn method() -> Method {
38 Method::DELETE
39 }
40
41 fn path(&self) -> Cow<'static, str> {
42 format!("/groups/{}", self.group_id).into()
43 }
44
45 fn body(&self) -> Result<Option<Vec<u8>>, Self::Error> {
46 Ok(Some(serde_json::to_vec(self)?))
47 }
48
49 async fn get_data(res: Response) -> Result<Self::Data, Self::Error> {
50 match res.status() {
51 StatusCode::NO_CONTENT => Ok(res.json::<Self::Data>().await?),
52 StatusCode::BAD_REQUEST => Err(Error::BadRequest(res.json::<RequestError>().await?)),
53 StatusCode::CONFLICT => Err(Error::Conflict(res.json::<RequestError>().await?)),
54 _ => todo!(),
55 }
56 }
57}