gcs_location.rs (6572B)
1 use radroots_types::types::{IResult, IResultList}; 2 use serde::{Deserialize, Serialize}; 3 use serde_json::Value; 4 5 #[derive(Serialize, Deserialize)] 6 pub struct GcsLocation { 7 pub id: String, 8 pub created_at: String, 9 pub updated_at: String, 10 pub d_tag: String, 11 pub lat: f64, 12 pub lng: f64, 13 pub geohash: String, 14 pub point: String, 15 pub polygon: String, 16 pub accuracy: Option<f64>, 17 pub altitude: Option<f64>, 18 pub tag_0: Option<String>, 19 pub label: Option<String>, 20 pub area: Option<f64>, 21 pub elevation: Option<u32>, 22 pub soil: Option<String>, 23 pub climate: Option<String>, 24 pub gc_id: Option<String>, 25 pub gc_name: Option<String>, 26 pub gc_admin1_id: Option<String>, 27 pub gc_admin1_name: Option<String>, 28 pub gc_country_id: Option<String>, 29 pub gc_country_name: Option<String>, 30 } 31 32 #[derive(Clone, Deserialize, Serialize)] 33 pub struct IGcsLocationFields { 34 pub d_tag: String, 35 pub lat: f64, 36 pub lng: f64, 37 pub geohash: String, 38 pub point: String, 39 pub polygon: String, 40 pub accuracy: Option<f64>, 41 pub altitude: Option<f64>, 42 pub tag_0: Option<String>, 43 pub label: Option<String>, 44 pub area: Option<f64>, 45 pub elevation: Option<u32>, 46 pub soil: Option<String>, 47 pub climate: Option<String>, 48 pub gc_id: Option<String>, 49 pub gc_name: Option<String>, 50 pub gc_admin1_id: Option<String>, 51 pub gc_admin1_name: Option<String>, 52 pub gc_country_id: Option<String>, 53 pub gc_country_name: Option<String>, 54 } 55 56 #[derive(Clone, Deserialize, Serialize)] 57 pub struct IGcsLocationFieldsPartial { 58 pub d_tag: Option<serde_json::Value>, 59 pub lat: Option<serde_json::Value>, 60 pub lng: Option<serde_json::Value>, 61 pub geohash: Option<serde_json::Value>, 62 pub point: Option<serde_json::Value>, 63 pub polygon: Option<serde_json::Value>, 64 pub accuracy: Option<serde_json::Value>, 65 pub altitude: Option<serde_json::Value>, 66 pub tag_0: Option<serde_json::Value>, 67 pub label: Option<serde_json::Value>, 68 pub area: Option<serde_json::Value>, 69 pub elevation: Option<serde_json::Value>, 70 pub soil: Option<serde_json::Value>, 71 pub climate: Option<serde_json::Value>, 72 pub gc_id: Option<serde_json::Value>, 73 pub gc_name: Option<serde_json::Value>, 74 pub gc_admin1_id: Option<serde_json::Value>, 75 pub gc_admin1_name: Option<serde_json::Value>, 76 pub gc_country_id: Option<serde_json::Value>, 77 pub gc_country_name: Option<serde_json::Value>, 78 } 79 80 #[derive(Clone, Deserialize, Serialize)] 81 pub struct IGcsLocationFieldsFilter { 82 pub id: Option<String>, 83 pub created_at: Option<String>, 84 pub updated_at: Option<String>, 85 pub d_tag: Option<String>, 86 pub lat: Option<f64>, 87 pub lng: Option<f64>, 88 pub geohash: Option<String>, 89 pub point: Option<String>, 90 pub polygon: Option<String>, 91 pub accuracy: Option<f64>, 92 pub altitude: Option<f64>, 93 pub tag_0: Option<String>, 94 pub label: Option<String>, 95 pub area: Option<f64>, 96 pub elevation: Option<u32>, 97 pub soil: Option<String>, 98 pub climate: Option<String>, 99 pub gc_id: Option<String>, 100 pub gc_name: Option<String>, 101 pub gc_admin1_id: Option<String>, 102 pub gc_admin1_name: Option<String>, 103 pub gc_country_id: Option<String>, 104 pub gc_country_name: Option<String>, 105 } 106 107 #[derive(Clone, Deserialize, Serialize)] 108 #[serde(untagged)] 109 pub enum GcsLocationQueryBindValues { 110 Id { id: String }, 111 DTag { d_tag: String }, 112 Geohash { geohash: String }, 113 } 114 impl GcsLocationQueryBindValues { 115 pub fn to_filter_param(&self) -> (&'static str, Value) { 116 match self { 117 Self::Id { id } => ("id", Value::from(id.clone())), 118 Self::DTag { d_tag } => ("d_tag", Value::from(d_tag.clone())), 119 Self::Geohash { geohash } => ("geohash", Value::from(geohash.clone())), 120 } 121 } 122 123 pub fn primary_key(&self) -> Option<String> { 124 match self { 125 Self::Id { id } => Some(id.clone()), 126 _ => None, 127 } 128 } 129 130 pub fn lookup_key(&self) -> String { 131 match self { 132 Self::Id { id } => id.clone(), 133 Self::DTag { d_tag } => d_tag.clone(), 134 Self::Geohash { geohash } => geohash.clone(), 135 } 136 } 137 } 138 139 #[derive(Clone, Deserialize, Serialize)] 140 pub struct GcsLocationTradeProductArgs { 141 pub id: String, 142 } 143 144 #[derive(Clone, Deserialize, Serialize)] 145 pub struct GcsLocationFarmArgs { 146 pub id: String, 147 } 148 149 #[derive(Clone, Deserialize, Serialize)] 150 pub struct GcsLocationPlotArgs { 151 pub id: String, 152 } 153 154 #[derive(Clone, Deserialize, Serialize)] 155 pub enum GcsLocationFindManyRel { 156 #[serde(rename = "on_trade_product")] 157 OnTradeProduct(GcsLocationTradeProductArgs), 158 #[serde(rename = "off_trade_product")] 159 OffTradeProduct(GcsLocationTradeProductArgs), 160 #[serde(rename = "on_farm")] 161 OnFarm(GcsLocationFarmArgs), 162 #[serde(rename = "off_farm")] 163 OffFarm(GcsLocationFarmArgs), 164 #[serde(rename = "on_plot")] 165 OnPlot(GcsLocationPlotArgs), 166 #[serde(rename = "off_plot")] 167 OffPlot(GcsLocationPlotArgs), 168 } 169 170 pub struct IGcsLocationCreateTs; 171 pub type IGcsLocationCreate = IGcsLocationFields; 172 pub struct IGcsLocationCreateResolveTs; 173 pub type IGcsLocationCreateResolve = IResult<GcsLocation>; 174 #[derive(Deserialize, Serialize)] 175 pub struct IGcsLocationFindOneArgs { 176 pub on: GcsLocationQueryBindValues, 177 } 178 179 #[derive(Deserialize, Serialize)] 180 pub struct IGcsLocationFindOneRelArgs { 181 pub rel: GcsLocationFindManyRel, 182 } 183 184 #[derive(Deserialize, Serialize)] 185 #[serde(untagged)] 186 pub enum IGcsLocationFindOne { 187 On(IGcsLocationFindOneArgs), 188 Rel(IGcsLocationFindOneRelArgs), 189 } 190 191 pub struct IGcsLocationFindOneResolveTs; 192 pub type IGcsLocationFindOneResolve = IResult<Option<GcsLocation>>; 193 #[derive(Deserialize, Serialize)] 194 #[serde(untagged)] 195 pub enum IGcsLocationFindMany { 196 Filter { 197 filter: Box<Option<IGcsLocationFieldsFilter>>, 198 }, 199 Rel { 200 rel: GcsLocationFindManyRel, 201 }, 202 } 203 pub struct IGcsLocationFindManyResolveTs; 204 pub type IGcsLocationFindManyResolve = IResultList<GcsLocation>; 205 pub struct IGcsLocationDeleteTs; 206 pub type IGcsLocationDelete = IGcsLocationFindOne; 207 pub struct IGcsLocationDeleteResolveTs; 208 pub type IGcsLocationDeleteResolve = IResult<String>; 209 #[derive(Deserialize, Serialize)] 210 pub struct IGcsLocationUpdateArgs { 211 pub on: GcsLocationQueryBindValues, 212 pub fields: IGcsLocationFieldsPartial, 213 } 214 pub type IGcsLocationUpdate = IGcsLocationUpdateArgs; 215 pub struct IGcsLocationUpdateResolveTs; 216 pub type IGcsLocationUpdateResolve = IResult<GcsLocation>;