Refactor project into workspaces
This commit is contained in:
		
							parent
							
								
									131bdeec78
								
							
						
					
					
						commit
						bacea1e3e9
					
				
					 31 changed files with 119 additions and 99 deletions
				
			
		
							
								
								
									
										2
									
								
								.env
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								.env
									
										
									
									
									
								
							| 
						 | 
					@ -1,2 +0,0 @@
 | 
				
			||||||
# This is usually used in development by sqlx. It is not used in production
 | 
					 | 
				
			||||||
DATABASE_URL=sqlite://emgauwa-core.sqlite
 | 
					 | 
				
			||||||
							
								
								
									
										5
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -4,9 +4,8 @@
 | 
				
			||||||
/tests/testing_bak/
 | 
					/tests/testing_bak/
 | 
				
			||||||
/tests/testing_latest/
 | 
					/tests/testing_latest/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
emgauwa-core.conf.d
 | 
					emgauwa-*.sqlite
 | 
				
			||||||
emgauwa-core.sqlite
 | 
					emgauwa-*.sqlite-*
 | 
				
			||||||
emgauwa-core.sqlite-*
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Added by cargo
 | 
					# Added by cargo
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										31
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										31
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
					@ -819,12 +819,6 @@ version = "0.3.0"
 | 
				
			||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
 | 
					checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					 | 
				
			||||||
name = "dotenv"
 | 
					 | 
				
			||||||
version = "0.15.0"
 | 
					 | 
				
			||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
					 | 
				
			||||||
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "dotenvy"
 | 
					name = "dotenvy"
 | 
				
			||||||
version = "0.15.7"
 | 
					version = "0.15.7"
 | 
				
			||||||
| 
						 | 
					@ -849,15 +843,30 @@ dependencies = [
 | 
				
			||||||
 "actix-web-actors",
 | 
					 "actix-web-actors",
 | 
				
			||||||
 "chrono",
 | 
					 "chrono",
 | 
				
			||||||
 "config",
 | 
					 "config",
 | 
				
			||||||
 "dotenv",
 | 
					 "emgauwa-lib",
 | 
				
			||||||
 "futures",
 | 
					 "futures",
 | 
				
			||||||
 "lazy_static",
 | 
					 | 
				
			||||||
 "libsqlite3-sys",
 | 
					 | 
				
			||||||
 "log",
 | 
					 "log",
 | 
				
			||||||
 "serde",
 | 
					 "serde",
 | 
				
			||||||
 "serde_derive",
 | 
					 "serde_derive",
 | 
				
			||||||
 "serde_json",
 | 
					 "serde_json",
 | 
				
			||||||
 "simple_logger",
 | 
					 "simple_logger",
 | 
				
			||||||
 | 
					 "uuid",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "emgauwa-lib"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "actix",
 | 
				
			||||||
 | 
					 "actix-web",
 | 
				
			||||||
 | 
					 "actix-web-actors",
 | 
				
			||||||
 | 
					 "chrono",
 | 
				
			||||||
 | 
					 "futures",
 | 
				
			||||||
 | 
					 "libsqlite3-sys",
 | 
				
			||||||
 | 
					 "log",
 | 
				
			||||||
 | 
					 "serde",
 | 
				
			||||||
 | 
					 "serde_derive",
 | 
				
			||||||
 | 
					 "serde_json",
 | 
				
			||||||
 "sqlx",
 | 
					 "sqlx",
 | 
				
			||||||
 "uuid",
 | 
					 "uuid",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
| 
						 | 
					@ -2618,9 +2627,9 @@ dependencies = [
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "uuid"
 | 
					name = "uuid"
 | 
				
			||||||
version = "1.5.0"
 | 
					version = "1.6.1"
 | 
				
			||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc"
 | 
					checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
 "getrandom",
 | 
					 "getrandom",
 | 
				
			||||||
 "serde",
 | 
					 "serde",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										36
									
								
								Cargo.toml
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								Cargo.toml
									
										
									
									
									
								
							| 
						 | 
					@ -1,30 +1,6 @@
 | 
				
			||||||
[package]
 | 
					[workspace]
 | 
				
			||||||
name = "emgauwa-core"
 | 
					resolver = "2"
 | 
				
			||||||
version = "0.1.0"
 | 
					members = [
 | 
				
			||||||
edition = "2018"
 | 
					    "emgauwa-core",
 | 
				
			||||||
authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
					    "emgauwa-lib",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
[dependencies]
 | 
					 | 
				
			||||||
actix = "0.13"
 | 
					 | 
				
			||||||
actix-web = "4.4"
 | 
					 | 
				
			||||||
actix-web-actors = "4.2"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
sqlx = { version = "0.7", features = ["sqlite", "runtime-async-std", "macros", "chrono"] }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
dotenv = "0.15"
 | 
					 | 
				
			||||||
config = "0.13"
 | 
					 | 
				
			||||||
lazy_static = { version = "1.4.0", features = [] }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
simple_logger = "4.2"
 | 
					 | 
				
			||||||
log = "0.4"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
chrono = { version = "0.4", features = ["serde"] }
 | 
					 | 
				
			||||||
uuid = { version = "1.5", features = ["serde", "v4"] }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
serde = "1.0"
 | 
					 | 
				
			||||||
serde_json = "1.0"
 | 
					 | 
				
			||||||
serde_derive = "1.0"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
libsqlite3-sys = { version = "*", features = ["bundled"] }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
futures = "0.3.29"
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								build.rs
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								build.rs
									
										
									
									
									
								
							| 
						 | 
					@ -1,3 +0,0 @@
 | 
				
			||||||
fn main() {
 | 
					 | 
				
			||||||
	println!("cargo:rerun-if-changed=migrations");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										26
									
								
								emgauwa-core/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								emgauwa-core/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,26 @@
 | 
				
			||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "emgauwa-core"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					emgauwa-lib = { path = "../emgauwa-lib" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					actix = "0.13"
 | 
				
			||||||
 | 
					actix-web = "4.4"
 | 
				
			||||||
 | 
					actix-web-actors = "4.2"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config = "0.13"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					simple_logger = "4.2"
 | 
				
			||||||
 | 
					log = "0.4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chrono = { version = "0.4", features = ["serde"] }
 | 
				
			||||||
 | 
					uuid = { version = "1.5", features = ["serde", "v4"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					serde = "1.0"
 | 
				
			||||||
 | 
					serde_json = "1.0"
 | 
				
			||||||
 | 
					serde_derive = "1.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					futures = "0.3.29"
 | 
				
			||||||
							
								
								
									
										3
									
								
								emgauwa-core/build.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								emgauwa-core/build.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						println!("cargo:rustc-env=DATABASE_URL=sqlite://emgauwa-core.sqlite")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2,20 +2,15 @@ use std::str::FromStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use actix_web::middleware::TrailingSlash;
 | 
					use actix_web::middleware::TrailingSlash;
 | 
				
			||||||
use actix_web::{middleware, web, App, HttpServer};
 | 
					use actix_web::{middleware, web, App, HttpServer};
 | 
				
			||||||
 | 
					use emgauwa_lib::handlers;
 | 
				
			||||||
use log::{trace, LevelFilter};
 | 
					use log::{trace, LevelFilter};
 | 
				
			||||||
use simple_logger::SimpleLogger;
 | 
					use simple_logger::SimpleLogger;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod db;
 | 
					 | 
				
			||||||
mod handlers;
 | 
					 | 
				
			||||||
mod return_models;
 | 
					 | 
				
			||||||
mod settings;
 | 
					mod settings;
 | 
				
			||||||
mod types;
 | 
					 | 
				
			||||||
mod utils;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[actix_web::main]
 | 
					#[actix_web::main]
 | 
				
			||||||
async fn main() -> std::io::Result<()> {
 | 
					async fn main() -> std::io::Result<()> {
 | 
				
			||||||
	settings::init();
 | 
						let settings = settings::init();
 | 
				
			||||||
	let settings = settings::get();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let log_level: LevelFilter = log::LevelFilter::from_str(&settings.logging.level)
 | 
						let log_level: LevelFilter = log::LevelFilter::from_str(&settings.logging.level)
 | 
				
			||||||
		.unwrap_or_else(|_| panic!("Error parsing log level."));
 | 
							.unwrap_or_else(|_| panic!("Error parsing log level."));
 | 
				
			||||||
| 
						 | 
					@ -26,7 +21,7 @@ async fn main() -> std::io::Result<()> {
 | 
				
			||||||
		.init()
 | 
							.init()
 | 
				
			||||||
		.unwrap_or_else(|_| panic!("Error initializing logger."));
 | 
							.unwrap_or_else(|_| panic!("Error initializing logger."));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let pool = db::init(&settings.database).await;
 | 
						let pool = emgauwa_lib::db::init(&settings.database).await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	HttpServer::new(move || {
 | 
						HttpServer::new(move || {
 | 
				
			||||||
		App::new()
 | 
							App::new()
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,4 @@
 | 
				
			||||||
use std::sync::RwLock;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use config::Config;
 | 
					use config::Config;
 | 
				
			||||||
use lazy_static::lazy_static;
 | 
					 | 
				
			||||||
use serde_derive::Deserialize;
 | 
					use serde_derive::Deserialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Debug, Deserialize)]
 | 
					#[derive(Clone, Debug, Deserialize)]
 | 
				
			||||||
| 
						 | 
					@ -42,12 +39,8 @@ impl Default for Logging {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
lazy_static! {
 | 
					pub fn init() -> Settings {
 | 
				
			||||||
	static ref SETTINGS: RwLock<Settings> = RwLock::new(Settings::default());
 | 
						Config::builder()
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn init() {
 | 
					 | 
				
			||||||
	let settings = Config::builder()
 | 
					 | 
				
			||||||
		.add_source(config::File::with_name("emgauwa-core"))
 | 
							.add_source(config::File::with_name("emgauwa-core"))
 | 
				
			||||||
		.add_source(
 | 
							.add_source(
 | 
				
			||||||
			config::Environment::with_prefix("EMGAUWA")
 | 
								config::Environment::with_prefix("EMGAUWA")
 | 
				
			||||||
| 
						 | 
					@ -57,11 +50,5 @@ pub fn init() {
 | 
				
			||||||
		.build()
 | 
							.build()
 | 
				
			||||||
		.unwrap()
 | 
							.unwrap()
 | 
				
			||||||
		.try_deserialize::<Settings>()
 | 
							.try_deserialize::<Settings>()
 | 
				
			||||||
		.unwrap_or_else(|_| panic!("Error reading settings."));
 | 
							.unwrap_or_else(|_| panic!("Error reading settings."))
 | 
				
			||||||
 | 
					 | 
				
			||||||
	*SETTINGS.write().unwrap() = settings;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub fn get() -> Settings {
 | 
					 | 
				
			||||||
	SETTINGS.read().unwrap().clone()
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										23
									
								
								emgauwa-lib/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								emgauwa-lib/Cargo.toml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,23 @@
 | 
				
			||||||
 | 
					[package]
 | 
				
			||||||
 | 
					name = "emgauwa-lib"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					edition = "2021"
 | 
				
			||||||
 | 
					authors = ["Tobias Reisinger <tobias@msrg.cc>"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[dependencies]
 | 
				
			||||||
 | 
					actix = "0.13"
 | 
				
			||||||
 | 
					actix-web = "4.4"
 | 
				
			||||||
 | 
					actix-web-actors = "4.2"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					serde = "1.0"
 | 
				
			||||||
 | 
					serde_json = "1.0"
 | 
				
			||||||
 | 
					serde_derive = "1.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chrono = { version = "0.4", features = ["serde"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sqlx = { version = "0.7", features = ["sqlite", "runtime-async-std", "macros", "chrono"] }
 | 
				
			||||||
 | 
					libsqlite3-sys = { version = "*", features = ["bundled"] }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					log = "0.4"
 | 
				
			||||||
 | 
					uuid = "1.6"
 | 
				
			||||||
 | 
					futures = "0.3"
 | 
				
			||||||
							
								
								
									
										4
									
								
								emgauwa-lib/build.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								emgauwa-lib/build.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
						println!("cargo:rerun-if-changed=migrations");
 | 
				
			||||||
 | 
						println!("cargo:rustc-env=DATABASE_URL=sqlite://emgauwa-dev.sqlite")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,19 +1,20 @@
 | 
				
			||||||
use log::{info, trace};
 | 
					use log::{info, trace};
 | 
				
			||||||
use sqlx::migrate::Migrator;
 | 
					use sqlx::migrate::Migrator;
 | 
				
			||||||
use sqlx::sqlite::SqlitePoolOptions;
 | 
					use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
 | 
				
			||||||
use sqlx::{Pool, Sqlite};
 | 
					use sqlx::{Pool, Sqlite};
 | 
				
			||||||
 | 
					use std::str::FromStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::db::errors::DatabaseError;
 | 
					use crate::db::errors::DatabaseError;
 | 
				
			||||||
use crate::db::model_utils::Period;
 | 
					use crate::db::model_utils::Period;
 | 
				
			||||||
use crate::db::schedules::{Periods, Schedule};
 | 
					use crate::db::schedules::{Periods, Schedule};
 | 
				
			||||||
use crate::types::EmgauwaUid;
 | 
					use crate::db::types::EmgauwaUid;
 | 
				
			||||||
 | 
					 | 
				
			||||||
pub mod errors;
 | 
					 | 
				
			||||||
pub mod models;
 | 
					 | 
				
			||||||
pub mod schedules;
 | 
					 | 
				
			||||||
pub mod tag;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub(crate) mod errors;
 | 
				
			||||||
mod model_utils;
 | 
					mod model_utils;
 | 
				
			||||||
 | 
					mod models;
 | 
				
			||||||
 | 
					pub(crate) mod schedules;
 | 
				
			||||||
 | 
					pub(crate) mod tag;
 | 
				
			||||||
 | 
					pub mod types;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static MIGRATOR: Migrator = sqlx::migrate!(); // defaults to "./migrations"
 | 
					static MIGRATOR: Migrator = sqlx::migrate!(); // defaults to "./migrations"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,12 +53,16 @@ async fn init_schedule(
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub async fn init(db: &str) -> Pool<Sqlite> {
 | 
					pub async fn init(db: &str) -> Pool<Sqlite> {
 | 
				
			||||||
 | 
						let options = SqliteConnectOptions::from_str(db)
 | 
				
			||||||
 | 
							.expect("Error parsing database path")
 | 
				
			||||||
 | 
							.create_if_missing(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let pool: Pool<Sqlite> = SqlitePoolOptions::new()
 | 
						let pool: Pool<Sqlite> = SqlitePoolOptions::new()
 | 
				
			||||||
		.acquire_timeout(std::time::Duration::from_secs(1))
 | 
							.acquire_timeout(std::time::Duration::from_secs(1))
 | 
				
			||||||
		.max_connections(5)
 | 
							.max_connections(5)
 | 
				
			||||||
		.connect(db)
 | 
							.connect_with(options)
 | 
				
			||||||
		.await
 | 
							.await
 | 
				
			||||||
		.expect("Error connecting to database.");
 | 
							.expect("Error connecting to database");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	run_migrations(&pool).await;
 | 
						run_migrations(&pool).await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@ use sqlx::Sqlite;
 | 
				
			||||||
use crate::db::errors::DatabaseError;
 | 
					use crate::db::errors::DatabaseError;
 | 
				
			||||||
use crate::db::model_utils::Period;
 | 
					use crate::db::model_utils::Period;
 | 
				
			||||||
use crate::db::tag::Tag;
 | 
					use crate::db::tag::Tag;
 | 
				
			||||||
use crate::types::EmgauwaUid;
 | 
					use crate::db::types::EmgauwaUid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Serialize, Clone)]
 | 
					#[derive(Debug, Serialize, Clone)]
 | 
				
			||||||
pub struct Schedule {
 | 
					pub struct Schedule {
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,12 @@ use sqlx::sqlite::{SqliteTypeInfo, SqliteValueRef};
 | 
				
			||||||
use sqlx::{Decode, Encode, Sqlite, Type};
 | 
					use sqlx::{Decode, Encode, Sqlite, Type};
 | 
				
			||||||
use uuid::Uuid;
 | 
					use uuid::Uuid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::types::EmgauwaUid;
 | 
					#[derive(Clone)]
 | 
				
			||||||
 | 
					pub enum EmgauwaUid {
 | 
				
			||||||
 | 
						Off,
 | 
				
			||||||
 | 
						On,
 | 
				
			||||||
 | 
						Any(Uuid),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl EmgauwaUid {
 | 
					impl EmgauwaUid {
 | 
				
			||||||
	const OFF_STR: &'static str = "off";
 | 
						const OFF_STR: &'static str = "off";
 | 
				
			||||||
							
								
								
									
										2
									
								
								emgauwa-lib/src/db/types/mod.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								emgauwa-lib/src/db/types/mod.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					pub mod emgauwa_uid;
 | 
				
			||||||
 | 
					pub use emgauwa_uid::EmgauwaUid;
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,3 @@
 | 
				
			||||||
use std::borrow::Borrow;
 | 
					 | 
				
			||||||
use std::convert::TryFrom;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use actix_web::{delete, get, post, put, web, HttpResponse};
 | 
					use actix_web::{delete, get, post, put, web, HttpResponse};
 | 
				
			||||||
use serde::{Deserialize, Serialize};
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
use sqlx::pool::PoolConnection;
 | 
					use sqlx::pool::PoolConnection;
 | 
				
			||||||
| 
						 | 
					@ -9,9 +6,9 @@ use sqlx::{Pool, Sqlite};
 | 
				
			||||||
use crate::db::errors::DatabaseError;
 | 
					use crate::db::errors::DatabaseError;
 | 
				
			||||||
use crate::db::schedules::*;
 | 
					use crate::db::schedules::*;
 | 
				
			||||||
use crate::db::tag::Tag;
 | 
					use crate::db::tag::Tag;
 | 
				
			||||||
 | 
					use crate::db::types::EmgauwaUid;
 | 
				
			||||||
use crate::handlers::errors::ApiError;
 | 
					use crate::handlers::errors::ApiError;
 | 
				
			||||||
use crate::return_models::ReturnSchedule;
 | 
					use crate::return_models::ReturnSchedule;
 | 
				
			||||||
use crate::types::EmgauwaUid;
 | 
					 | 
				
			||||||
use crate::utils::vec_has_error;
 | 
					use crate::utils::vec_has_error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Serialize, Deserialize)]
 | 
					#[derive(Debug, Serialize, Deserialize)]
 | 
				
			||||||
| 
						 | 
					@ -156,7 +153,7 @@ pub async fn update(
 | 
				
			||||||
	let schedule = Schedule::get_by_uid(&mut pool_conn, &emgauwa_uid).await?;
 | 
						let schedule = Schedule::get_by_uid(&mut pool_conn, &emgauwa_uid).await?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let schedule = schedule
 | 
						let schedule = schedule
 | 
				
			||||||
		.update(&mut pool_conn, data.name.as_str(), data.periods.borrow())
 | 
							.update(&mut pool_conn, data.name.as_str(), &data.periods)
 | 
				
			||||||
		.await?;
 | 
							.await?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	schedule
 | 
						schedule
 | 
				
			||||||
							
								
								
									
										4
									
								
								emgauwa-lib/src/lib.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								emgauwa-lib/src/lib.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					pub mod db;
 | 
				
			||||||
 | 
					pub mod handlers;
 | 
				
			||||||
 | 
					pub mod return_models;
 | 
				
			||||||
 | 
					pub mod utils;
 | 
				
			||||||
							
								
								
									
										10
									
								
								src/types.rs
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/types.rs
									
										
									
									
									
								
							| 
						 | 
					@ -1,10 +0,0 @@
 | 
				
			||||||
use uuid::Uuid;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
pub mod emgauwa_uid;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[derive(PartialEq, Clone)]
 | 
					 | 
				
			||||||
pub enum EmgauwaUid {
 | 
					 | 
				
			||||||
	Off,
 | 
					 | 
				
			||||||
	On,
 | 
					 | 
				
			||||||
	Any(Uuid),
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue