From 5d0b03e813d861bf32e606f891018df982170f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Vold=C5=99ich?= Date: Tue, 27 Aug 2024 15:34:43 +0200 Subject: [PATCH] Moving models into its own module --- src/lib.rs | 1 + src/main.rs | 33 +-------------------------------- src/models.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 src/lib.rs create mode 100644 src/models.rs diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c446ac8 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod models; diff --git a/src/main.rs b/src/main.rs index b01ae62..dbfb0ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,42 +1,11 @@ +use bcup::models::{Record, ServerConfiguration}; use futures::StreamExt; -use serde::{Deserialize, Serialize}; use surrealdb::{ engine::remote::ws::{Client, Ws}, opt::PatchOp, - sql::Thing, Notification, Result, Surreal, }; -#[derive(Debug, Serialize, Deserialize)] -struct State { - now: String, - required: String, -} - -impl State { - fn is_pending(&self) -> bool { - self.now == "pending".as_ref() - } -} - -#[derive(Debug, Serialize, Deserialize)] -struct ServerConfiguration { - id: Thing, - name: String, - domain: String, - directory: String, - volume: String, - repo_password: String, - rest_password: String, - state: State, -} - -#[derive(Debug, Deserialize)] -struct Record { - #[allow(dead_code)] - id: Thing, -} - #[tokio::main] async fn main() -> surrealdb::Result<()> { let db = Surreal::new::("127.0.0.1:8000").await?; diff --git a/src/models.rs b/src/models.rs new file mode 100644 index 0000000..17dfe50 --- /dev/null +++ b/src/models.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; +use surrealdb::sql::Thing; + +#[derive(Debug, Serialize, Deserialize)] +pub struct State { + pub now: String, + pub required: String, +} + +impl State { + pub fn is_pending(&self) -> bool { + self.now == "pending".as_ref() + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct ServerConfiguration { + pub id: Thing, + pub name: String, + pub domain: String, + pub directory: String, + pub volume: String, + pub repo_password: String, + pub rest_password: String, + pub state: State, +} + +#[derive(Debug, Deserialize)] +pub struct Record { + #[allow(dead_code)] + pub id: Thing, +}