#[derive(serde_derive::Serialize)]
struct BulkUpdateInput {
collection: String,
auth_code: String,
current_hash: String,
new_hash: String,
repo: String,
files: Vec<Action>,
}
#[derive(serde_derive::Serialize)]
struct File {
id: String,
content: String,
}
pub enum Error {
RealmClientError(realm_client::Error),
ContentMismatch { id: String },
}
#[allow(clippy::too_many_arguments)]
pub fn bulk_update(
collection: &str,
current_hash: &str,
new_hash: &str,
repo: &str,
files: Vec<Action>,
auth_code: &str,
platform: String,
client_version: String,
) -> realm_client::Result<()> {
let url = format!("/{}/~/bulk-update/", collection);
let update = BulkUpdateInput {
collection: collection.trim().to_string(),
auth_code: auth_code.trim().to_string(),
current_hash: current_hash.trim().to_string(),
new_hash: new_hash.trim().to_string(),
repo: repo.trim().to_string(),
files,
};
#[derive(serde_derive::Serialize)]
struct UpdatedWrapper {
data: BulkUpdateInput,
platform: String,
client_version: String,
}
realm_client::action::<crate::sync_status::Status, _>(
&url,
UpdatedWrapper {
data: update,
platform,
client_version,
},
Some("bulk_update".to_string()),
)?;
Ok(())
}
#[derive(serde_derive::Serialize, Debug)]
#[serde(tag = "type")]
pub enum Action {
Updated { id: String, content: String },
Added { id: String, content: String },
Deleted { id: String },
}
impl Action {
pub fn id(&self) -> &str {
match self {
Self::Updated { id, .. } => id,
Self::Added { id, .. } => id,
Self::Deleted { id } => id,
}
}
pub fn is_updated(&self) -> bool {
matches!(self, Self::Updated { .. })
}
pub fn is_added(&self) -> bool {
matches!(self, Self::Added { .. })
}
pub fn is_deleted(&self) -> bool {
matches!(self, Self::Deleted { .. })
}
}