use serde::{Deserialize, Serialize}; use crate::{TypedValue, ID}; /// Update or insert a value #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UpsertValue { /// PK, null if creating pub id: Option, /// Property template ID pub model: ID, /// Property value pub value: TypedValue, } /// Update or insert a relation #[derive(Debug, Clone, Serialize, Deserialize)] pub struct UpsertRelation { /// PK, null if creating pub id: Option, /// Relation template ID pub model: ID, /// Related model ID pub related: ID, /// Relation values to update or create pub values: Vec, } /// Update an existing object #[derive(Deserialize, Debug)] pub struct UpdateObj { /// Updated object's ID pub id: ID, /// Property to use as the object's name pub name_property: Option, /// Values to update or create pub values: Vec, /// Relations to update or create pub relations: Vec, } #[cfg(test)] mod tests { use crate::update::UpdateObj; #[test] #[cfg(not(feature = "uuid-ids"))] fn deserialize() { let json = json!({ "model_id": 0, "id": 10, "name": "Recipe1", "values": [ { "id": 11, "model": 3, "object": 10, "value": { "String": "Bla bla bla" } }, { "value": { "String": "sdfsdfsdf" }, "model": 3 } ], "relations": [ { "id": 12, "model": 5, "object": 10, "related": 8, "values": [ { "id": 13, "model": 6, "object": 12, "value": { "Integer": 15 }, "model": 6 } ] } ] }); let _obj: UpdateObj = serde_json::from_value(json).unwrap(); } }