1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
6pub struct Pointer {
7 #[serde(rename = "__type")]
8 pub __type: String, #[serde(rename = "className")]
10 pub class_name: String,
11 #[serde(rename = "objectId")]
12 pub object_id: String,
13}
14
15impl Pointer {
16 pub fn new(class_name: impl Into<String>, object_id: impl Into<String>) -> Self {
18 Pointer {
19 __type: "Pointer".to_string(),
20 class_name: class_name.into(),
21 object_id: object_id.into(),
22 }
23 }
24}
25
26#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
29pub struct ParseDate {
30 #[serde(rename = "__type")]
31 pub __type: String, pub iso: String, }
34
35impl ParseDate {
36 pub fn new(iso_string: impl Into<String>) -> Self {
39 ParseDate {
40 __type: "Date".to_string(),
41 iso: iso_string.into(),
42 }
43 }
44
45 }
48
49#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
51pub struct RelationOp<'a, T>
52where
53 T: Serialize,
54{
55 #[serde(rename = "__op")]
56 op_type: &'static str,
57 objects: &'a [T],
58}
59
60impl<'a, T> RelationOp<'a, T>
61where
62 T: Serialize,
63{
64 pub fn add(objects: &'a [T]) -> Self {
65 RelationOp {
66 op_type: "AddRelation",
67 objects,
68 }
69 }
70
71 pub fn remove(objects: &'a [T]) -> Self {
72 RelationOp {
73 op_type: "RemoveRelation",
74 objects,
75 }
76 }
77}
78
79#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
83pub struct ParseRelation {
84 #[serde(rename = "__type")]
85 pub __type: String, #[serde(rename = "className")]
87 pub class_name: String, }
89
90impl ParseRelation {
91 pub fn new(class_name: impl Into<String>) -> Self {
95 ParseRelation {
96 __type: "Relation".to_string(),
97 class_name: class_name.into(),
98 }
99 }
100}
101
102#[derive(Debug, Clone, PartialEq, Eq)]
104pub enum Endpoint {
105 Classes(String), Objects(String, Option<String>), Users,
108 UsersLogin,
109 UsersLogout,
110 UsersMe,
111 RequestPasswordReset,
112 Roles,
113 RolesSpecific(String), Schemas,
115 SchemasSpecific(String), Files(String), Functions(String), Config,
119 Aggregate(String), }
122
123impl Endpoint {
124 pub fn build_url(&self, base_path: &str) -> String {
126 let path = match self {
127 Endpoint::Classes(class_name) => format!("{}/classes/{}", base_path, class_name),
128 Endpoint::Objects(class_name, Some(object_id)) => {
129 format!("{}/classes/{}/{}", base_path, class_name, object_id)
130 }
131 Endpoint::Objects(class_name, None) => format!("{}/classes/{}", base_path, class_name),
132 Endpoint::Users => format!("{}/users", base_path),
133 Endpoint::UsersLogin => format!("{}/login", base_path),
134 Endpoint::UsersLogout => format!("{}/logout", base_path),
135 Endpoint::UsersMe => format!("{}/users/me", base_path),
136 Endpoint::RequestPasswordReset => format!("{}/requestPasswordReset", base_path),
137 Endpoint::Roles => format!("{}/roles", base_path),
138 Endpoint::RolesSpecific(role_id) => format!("{}/roles/{}", base_path, role_id),
139 Endpoint::Schemas => format!("{}/schemas", base_path),
140 Endpoint::SchemasSpecific(class_name) => {
141 format!("{}/schemas/{}", base_path, class_name)
142 }
143 Endpoint::Files(file_name) => format!("{}/files/{}", base_path, file_name),
144 Endpoint::Functions(function_name) => {
145 format!("{}/functions/{}", base_path, function_name)
146 }
147 Endpoint::Config => format!("{}/config", base_path),
148 Endpoint::Aggregate(class_name) => format!("{}/aggregate/{}", base_path, class_name),
149 };
150 path.replace("//", "/")
152 }
153}
154
155pub type QueryParams = std::collections::HashMap<String, String>;
157
158#[derive(Debug, Serialize, Deserialize, Clone)]
160pub struct Results<T> {
161 pub results: Vec<T>,
162 #[serde(skip_serializing_if = "Option::is_none")]
164 pub count: Option<i64>,
165}
166
167#[derive(Debug, Serialize, Deserialize, Clone)]
169pub struct UpdateResponseData {
170 #[serde(rename = "updatedAt")]
171 pub updated_at: String, #[serde(rename = "objectId", skip_serializing_if = "Option::is_none")]
174 pub object_id: Option<String>,
175}
176
177#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
180pub struct EmptyResponse {}