|
1 | | -use std::fmt::Display; |
2 | | -use serde_json::{Value, json}; |
3 | | -use serde::{Serialize, Deserialize}; |
4 | | -use crate::cli::Upload; |
5 | | - |
6 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
7 | | -pub struct Atomic { |
8 | | - id: IdQuark, |
9 | | - meta: MetaQuark, |
10 | | - data: DataQuark, |
11 | | -} |
12 | | - |
13 | | -impl Atomic { |
14 | | - pub fn get_data(&self) -> Value { |
15 | | - self.data.0.clone() |
16 | | - } |
17 | | - |
18 | | - pub fn from_array_in_object(_array_field: &str, _value: Value) -> Self { |
19 | | - todo!() |
20 | | - } |
21 | | - |
22 | | - pub fn basic_value(value: Value) -> Self { |
23 | | - Atomic { |
24 | | - id: IdQuark("".to_string()), |
25 | | - meta: MetaQuark(json!({})), |
26 | | - data: DataQuark(value) |
27 | | - } |
28 | | - } |
29 | | -} |
30 | | - |
31 | | -impl From<Value> for Atomic { |
32 | | - fn from(value: Value) -> Self { |
33 | | - Atomic::basic_value(value) |
34 | | - } |
35 | | - |
36 | | -} |
37 | | -impl From<Upload> for Atomic { |
38 | | - fn from(value: Upload) -> Self { |
39 | | - let data = value.get_data(); |
40 | | - data.into() |
41 | | - } |
42 | | - |
43 | | -} |
44 | | -impl Display for Atomic { |
45 | | - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
46 | | - f.write_str(&serde_json::to_string(self).expect("Failed to stringify Atomic")) |
47 | | - } |
48 | | -} |
49 | | - |
50 | | -// impl Store for Atomic { |
51 | | -// async fn store_object(index: String, input: Atomic) -> Result<(), Error> { |
52 | | -// todo!() |
53 | | -// } |
54 | | -// } |
55 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
56 | | -pub struct IdQuark(String); |
57 | | - |
58 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
59 | | -pub struct DataQuark(Value); |
60 | | - |
61 | | -#[derive(Debug, Clone, Serialize, Deserialize)] |
62 | | -pub struct MetaQuark(Value); |
| 1 | +use crate::cli::Upload; |
| 2 | +use serde::{Deserialize, Serialize}; |
| 3 | +use serde_json::{Value, json}; |
| 4 | +use std::fmt::Display; |
| 5 | + |
| 6 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 7 | +pub struct Atomic { |
| 8 | + id: IdQuark, |
| 9 | + meta: MetaQuark, |
| 10 | + data: DataQuark, |
| 11 | +} |
| 12 | + |
| 13 | +impl Atomic { |
| 14 | + pub fn get_data(&self) -> Value { |
| 15 | + self.data.0.clone() |
| 16 | + } |
| 17 | + |
| 18 | + pub fn from_array_in_object(_array_field: &str, _value: Value) -> Self { |
| 19 | + todo!() |
| 20 | + } |
| 21 | + |
| 22 | + pub fn basic_value(value: Value) -> Self { |
| 23 | + Atomic { |
| 24 | + id: IdQuark("".to_string()), |
| 25 | + meta: MetaQuark(json!({})), |
| 26 | + data: DataQuark(value), |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +impl From<Value> for Atomic { |
| 32 | + fn from(value: Value) -> Self { |
| 33 | + Atomic::basic_value(value) |
| 34 | + } |
| 35 | +} |
| 36 | +impl From<Upload> for Atomic { |
| 37 | + fn from(value: Upload) -> Self { |
| 38 | + let data = value.get_data(); |
| 39 | + data.into() |
| 40 | + } |
| 41 | +} |
| 42 | +impl Display for Atomic { |
| 43 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 44 | + f.write_str(&serde_json::to_string(self).expect("Failed to stringify Atomic")) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +// impl Store for Atomic { |
| 49 | +// async fn store_object(index: String, input: Atomic) -> Result<(), Error> { |
| 50 | +// todo!() |
| 51 | +// } |
| 52 | +// } |
| 53 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 54 | +pub struct IdQuark(String); |
| 55 | + |
| 56 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 57 | +pub struct DataQuark(Value); |
| 58 | + |
| 59 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 60 | +pub struct MetaQuark(Value); |
0 commit comments