use crate::framework::endpoint::{EndpointSpec, Method};
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub struct WriteBulk<'a> {
pub account_identifier: &'a str,
pub namespace_identifier: &'a str,
pub bulk_key_value_pairs: Vec<KeyValuePair>,
}
impl<'a> EndpointSpec<()> for WriteBulk<'a> {
fn method(&self) -> Method {
Method::PUT
}
fn path(&self) -> String {
format!(
"accounts/{}/storage/kv/namespaces/{}/bulk",
self.account_identifier, self.namespace_identifier
)
}
#[inline]
fn body(&self) -> Option<String> {
let body = serde_json::to_string(&self.bulk_key_value_pairs).unwrap();
Some(body)
}
}
#[serde_with::skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct KeyValuePair {
pub key: String,
pub value: String,
pub expiration: Option<i64>,
pub expiration_ttl: Option<i64>,
pub base64: Option<bool>,
}