tapis-pgrest 0.3.1

The Tapis PgREST API provides a RESTful interface to a managed SQL-db-as-a-service.
Documentation
/*
 * Tapis PgREST API
 *
 * The Tapis PgREST API provides a RESTful interface to a managed SQL-db-as-a-service.
 *
 * The version of the OpenAPI document: 1.0.0
 * Contact: cicsupport@tacc.utexas.edu
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};

/// struct for typed errors of method [`create_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateTableError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteTableError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetTableError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`list_tables`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListTablesError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`update_table`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateTableError {
    UnknownValue(serde_json::Value),
}

/// Create a table.
pub async fn create_table(
    configuration: &configuration::Configuration,
    new_table: models::NewTable,
) -> Result<models::CreateTable201Response, Error<CreateTableError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_new_table = new_table;

    let uri_str = format!("{}/v3/pgrest/manage/tables", configuration.base_path);
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    req_builder = req_builder.json(&p_body_new_table);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTable201Response`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTable201Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CreateTableError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete a specific table and all associted data. WARNING -- this action cannot be undone.
pub async fn delete_table(
    configuration: &configuration::Configuration,
    table_id: &str,
) -> Result<models::BasicResponse, Error<DeleteTableError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_table_id = table_id;

    let uri_str = format!(
        "{}/v3/pgrest/manage/tables/{table_id}",
        configuration.base_path,
        table_id = crate::apis::urlencode(p_path_table_id)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BasicResponse`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::BasicResponse`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<DeleteTableError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Get details about a specific table.
pub async fn get_table(
    configuration: &configuration::Configuration,
    table_id: &str,
    details: Option<bool>,
) -> Result<models::CreateTable201Response, Error<GetTableError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_table_id = table_id;
    let p_query_details = details;

    let uri_str = format!(
        "{}/v3/pgrest/manage/tables/{table_id}",
        configuration.base_path,
        table_id = crate::apis::urlencode(p_path_table_id)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_details {
        req_builder = req_builder.query(&[("details", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTable201Response`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTable201Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<GetTableError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// List tables in the tenant's schema.
pub async fn list_tables(
    configuration: &configuration::Configuration,
) -> Result<models::ListTables200Response, Error<ListTablesError>> {
    let uri_str = format!("{}/v3/pgrest/manage/tables", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListTables200Response`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListTables200Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<ListTablesError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Update a table definition with specific table operations.
pub async fn update_table(
    configuration: &configuration::Configuration,
    table_id: &str,
    update_table: models::UpdateTable,
) -> Result<models::CreateTable201Response, Error<UpdateTableError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_table_id = table_id;
    let p_body_update_table = update_table;

    let uri_str = format!(
        "{}/v3/pgrest/manage/tables/{table_id}",
        configuration.base_path,
        table_id = crate::apis::urlencode(p_path_table_id)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    req_builder = req_builder.json(&p_body_update_table);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateTable201Response`"))),
            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateTable201Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<UpdateTableError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}