use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Pointer {
#[serde(rename = "__type")]
pub __type: String, #[serde(rename = "className")]
pub class_name: String,
#[serde(rename = "objectId")]
pub object_id: String,
}
impl Pointer {
pub fn new(class_name: impl Into<String>, object_id: impl Into<String>) -> Self {
Pointer {
__type: "Pointer".to_string(),
class_name: class_name.into(),
object_id: object_id.into(),
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct ParseDate {
#[serde(rename = "__type")]
pub __type: String, pub iso: String, }
impl ParseDate {
pub fn new(iso_string: impl Into<String>) -> Self {
ParseDate {
__type: "Date".to_string(),
iso: iso_string.into(),
}
}
}
#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
pub struct RelationOp<'a, T>
where
T: Serialize,
{
#[serde(rename = "__op")]
op_type: &'static str,
objects: &'a [T],
}
impl<'a, T> RelationOp<'a, T>
where
T: Serialize,
{
pub fn add(objects: &'a [T]) -> Self {
RelationOp {
op_type: "AddRelation",
objects,
}
}
pub fn remove(objects: &'a [T]) -> Self {
RelationOp {
op_type: "RemoveRelation",
objects,
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct ParseRelation {
#[serde(rename = "__type")]
pub __type: String, #[serde(rename = "className")]
pub class_name: String, }
impl ParseRelation {
pub fn new(class_name: impl Into<String>) -> Self {
ParseRelation {
__type: "Relation".to_string(),
class_name: class_name.into(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Endpoint {
Classes(String), Objects(String, Option<String>), Users,
UsersLogin,
UsersLogout,
UsersMe,
RequestPasswordReset,
Roles,
RolesSpecific(String), Schemas,
SchemasSpecific(String), Files(String), Functions(String), Config,
Aggregate(String), }
impl Endpoint {
pub fn build_url(&self, base_path: &str) -> String {
let path = match self {
Endpoint::Classes(class_name) => format!("{}/classes/{}", base_path, class_name),
Endpoint::Objects(class_name, Some(object_id)) => {
format!("{}/classes/{}/{}", base_path, class_name, object_id)
}
Endpoint::Objects(class_name, None) => format!("{}/classes/{}", base_path, class_name),
Endpoint::Users => format!("{}/users", base_path),
Endpoint::UsersLogin => format!("{}/login", base_path),
Endpoint::UsersLogout => format!("{}/logout", base_path),
Endpoint::UsersMe => format!("{}/users/me", base_path),
Endpoint::RequestPasswordReset => format!("{}/requestPasswordReset", base_path),
Endpoint::Roles => format!("{}/roles", base_path),
Endpoint::RolesSpecific(role_id) => format!("{}/roles/{}", base_path, role_id),
Endpoint::Schemas => format!("{}/schemas", base_path),
Endpoint::SchemasSpecific(class_name) => {
format!("{}/schemas/{}", base_path, class_name)
}
Endpoint::Files(file_name) => format!("{}/files/{}", base_path, file_name),
Endpoint::Functions(function_name) => {
format!("{}/functions/{}", base_path, function_name)
}
Endpoint::Config => format!("{}/config", base_path),
Endpoint::Aggregate(class_name) => format!("{}/aggregate/{}", base_path, class_name),
};
path.replace("//", "/")
}
}
pub type QueryParams = std::collections::HashMap<String, String>;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Results<T> {
pub results: Vec<T>,
#[serde(skip_serializing_if = "Option::is_none")]
pub count: Option<i64>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct UpdateResponseData {
#[serde(rename = "updatedAt")]
pub updated_at: String, #[serde(rename = "objectId", skip_serializing_if = "Option::is_none")]
pub object_id: Option<String>,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
pub struct EmptyResponse {}