plot.rs (3744B)
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 Plot { 7 pub id: String, 8 pub created_at: String, 9 pub updated_at: String, 10 pub d_tag: String, 11 pub farm_id: String, 12 pub name: String, 13 pub about: Option<String>, 14 pub location_primary: Option<String>, 15 pub location_city: Option<String>, 16 pub location_region: Option<String>, 17 pub location_country: Option<String>, 18 } 19 20 #[derive(Clone, Deserialize, Serialize)] 21 pub struct IPlotFields { 22 pub d_tag: String, 23 pub farm_id: String, 24 pub name: String, 25 pub about: Option<String>, 26 pub location_primary: Option<String>, 27 pub location_city: Option<String>, 28 pub location_region: Option<String>, 29 pub location_country: Option<String>, 30 } 31 32 #[derive(Clone, Deserialize, Serialize)] 33 pub struct IPlotFieldsPartial { 34 pub d_tag: Option<serde_json::Value>, 35 pub farm_id: Option<serde_json::Value>, 36 pub name: Option<serde_json::Value>, 37 pub about: Option<serde_json::Value>, 38 pub location_primary: Option<serde_json::Value>, 39 pub location_city: Option<serde_json::Value>, 40 pub location_region: Option<serde_json::Value>, 41 pub location_country: Option<serde_json::Value>, 42 } 43 44 #[derive(Clone, Deserialize, Serialize)] 45 pub struct IPlotFieldsFilter { 46 pub id: Option<String>, 47 pub created_at: Option<String>, 48 pub updated_at: Option<String>, 49 pub d_tag: Option<String>, 50 pub farm_id: Option<String>, 51 pub name: Option<String>, 52 pub about: Option<String>, 53 pub location_primary: Option<String>, 54 pub location_city: Option<String>, 55 pub location_region: Option<String>, 56 pub location_country: Option<String>, 57 } 58 59 #[derive(Clone, Deserialize, Serialize)] 60 #[serde(untagged)] 61 pub enum PlotQueryBindValues { 62 Id { id: String }, 63 DTag { d_tag: String }, 64 FarmId { farm_id: String }, 65 } 66 impl PlotQueryBindValues { 67 pub fn to_filter_param(&self) -> (&'static str, Value) { 68 match self { 69 Self::Id { id } => ("id", Value::from(id.clone())), 70 Self::DTag { d_tag } => ("d_tag", Value::from(d_tag.clone())), 71 Self::FarmId { farm_id } => ("farm_id", Value::from(farm_id.clone())), 72 } 73 } 74 75 pub fn primary_key(&self) -> Option<String> { 76 match self { 77 Self::Id { id } => Some(id.clone()), 78 _ => None, 79 } 80 } 81 82 pub fn lookup_key(&self) -> String { 83 match self { 84 Self::Id { id } => id.clone(), 85 Self::DTag { d_tag } => d_tag.clone(), 86 Self::FarmId { farm_id } => farm_id.clone(), 87 } 88 } 89 } 90 91 pub struct IPlotCreateTs; 92 pub type IPlotCreate = IPlotFields; 93 pub struct IPlotCreateResolveTs; 94 pub type IPlotCreateResolve = IResult<Plot>; 95 #[derive(Deserialize, Serialize)] 96 pub struct IPlotFindOneArgs { 97 pub on: PlotQueryBindValues, 98 } 99 100 #[derive(Deserialize, Serialize)] 101 #[serde(untagged)] 102 pub enum IPlotFindOne { 103 On(IPlotFindOneArgs), 104 } 105 106 pub struct IPlotFindOneResolveTs; 107 pub type IPlotFindOneResolve = IResult<Option<Plot>>; 108 #[derive(Deserialize, Serialize)] 109 pub struct IPlotFindManyArgs { 110 pub filter: Option<IPlotFieldsFilter>, 111 } 112 pub type IPlotFindMany = IPlotFindManyArgs; 113 pub struct IPlotFindManyResolveTs; 114 pub type IPlotFindManyResolve = IResultList<Plot>; 115 pub struct IPlotDeleteTs; 116 pub type IPlotDelete = IPlotFindOne; 117 pub struct IPlotDeleteResolveTs; 118 pub type IPlotDeleteResolve = IResult<String>; 119 #[derive(Deserialize, Serialize)] 120 pub struct IPlotUpdateArgs { 121 pub on: PlotQueryBindValues, 122 pub fields: IPlotFieldsPartial, 123 } 124 pub type IPlotUpdate = IPlotUpdateArgs; 125 pub struct IPlotUpdateResolveTs; 126 pub type IPlotUpdateResolve = IResult<Plot>;