use serde::{Deserialize, Serialize};
use crate::{field_access, impl_default, impl_display};
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Request {
file_path: String,
}
impl Request {
pub const fn new() -> Self {
Self {
file_path: String::new(),
}
}
}
field_access! {
Request {
file_path: cow { str },
}
}
impl_default!(Request);
impl_display!(Request);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_upload_file() {
let file_path = "/path/to/file.txt";
let file_path_json = serde_json::to_string(&file_path).unwrap();
let req = Request::new().with_file_path(file_path);
let req_json = format!(r#"{{"file_path":{file_path_json}}}"#);
assert_eq!(serde_json::to_string(&req).unwrap(), req_json);
assert_eq!(serde_json::from_str::<Request>(&req_json).unwrap(), req);
assert_eq!(req.file_path(), file_path);
}
}