1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use super::fields::*;
#[cfg(feature = "fp-bindgen")]
use fp_bindgen::prelude::Serializable;
use serde::{Deserialize, Serialize};

/// Defines the fields that should be included in the query data.
///
/// Query data is encoded as "application/x-www-form-urlencoded", unless a
/// `File` field is present in the schema, in which case "multipart/form-data"
/// may be used.
pub type QuerySchema = Vec<QueryField>;

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[cfg_attr(
    feature = "fp-bindgen",
    derive(Serializable),
    fp(rust_module = "fiberplane_models::providers")
)]
#[non_exhaustive]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum QueryField {
    Array(ArrayField),
    Checkbox(CheckboxField),
    DateTimeRange(DateTimeRangeField),
    File(FileField),
    Label(LabelField),
    Integer(IntegerField),
    Select(SelectField),
    Text(TextField),
}

impl From<CheckboxField> for QueryField {
    fn from(field: CheckboxField) -> Self {
        Self::Checkbox(field)
    }
}

impl From<DateTimeRangeField> for QueryField {
    fn from(field: DateTimeRangeField) -> Self {
        Self::DateTimeRange(field)
    }
}

impl From<FileField> for QueryField {
    fn from(field: FileField) -> Self {
        Self::File(field)
    }
}

impl From<LabelField> for QueryField {
    fn from(field: LabelField) -> Self {
        Self::Label(field)
    }
}

impl From<IntegerField> for QueryField {
    fn from(field: IntegerField) -> Self {
        Self::Integer(field)
    }
}

impl From<SelectField> for QueryField {
    fn from(field: SelectField) -> Self {
        Self::Select(field)
    }
}

impl From<TextField> for QueryField {
    fn from(field: TextField) -> Self {
        Self::Text(field)
    }
}

impl From<ArrayField> for QueryField {
    fn from(field: ArrayField) -> Self {
        Self::Array(field)
    }
}