Its friday and the drivers are happy

This commit is contained in:
LinlyBoi
2022-12-23 21:54:20 +02:00
parent bcf3ec0d8c
commit d466c1199d
5 changed files with 169 additions and 36 deletions

147
Cargo.lock generated
View File

@@ -222,6 +222,15 @@ dependencies = [
"alloc-no-stdlib", "alloc-no-stdlib",
] ]
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "anymap2" name = "anymap2"
version = "0.13.0" version = "0.13.0"
@@ -239,7 +248,7 @@ name = "backend"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"chrono", "chrono 0.2.25",
"common", "common",
"diesel", "diesel",
"dotenv", "dotenv",
@@ -356,6 +365,28 @@ dependencies = [
"time 0.1.45", "time 0.1.45",
] ]
[[package]]
name = "chrono"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
dependencies = [
"iana-time-zone",
"num-integer",
"num-traits",
"winapi",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]] [[package]]
name = "common" name = "common"
version = "0.1.0" version = "0.1.0"
@@ -391,6 +422,12 @@ dependencies = [
"version_check", "version_check",
] ]
[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.5" version = "0.2.5"
@@ -419,6 +456,50 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "cxx"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5add3fc1717409d029b20c5b6903fc0c0b02fa6741d820054f4a2efa5e5816fd"
dependencies = [
"cc",
"cxxbridge-flags",
"cxxbridge-macro",
"link-cplusplus",
]
[[package]]
name = "cxx-build"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4c87959ba14bc6fbc61df77c3fcfe180fc32b93538c4f1031dd802ccb5f2ff0"
dependencies = [
"cc",
"codespan-reporting",
"once_cell",
"proc-macro2",
"quote",
"scratch",
"syn",
]
[[package]]
name = "cxxbridge-flags"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69a3e162fde4e594ed2b07d0f83c6c67b745e7f28ce58c6df5e6b6bef99dfb59"
[[package]]
name = "cxxbridge-macro"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e7e2adeb6a0d4a282e581096b06e1791532b7d576dcde5ccd9382acf55db8e6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "db-frontend" name = "db-frontend"
version = "0.1.0" version = "0.1.0"
@@ -458,6 +539,7 @@ checksum = "68c186a7418a2aac330bb76cde82f16c36b03a66fb91db32d20214311f9f6545"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"byteorder", "byteorder",
"chrono 0.4.23",
"diesel_derives", "diesel_derives",
"itoa", "itoa",
"pq-sys", "pq-sys",
@@ -846,6 +928,30 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "iana-time-zone"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
"cxx",
"cxx-build",
]
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.3.0" version = "0.3.0"
@@ -911,6 +1017,15 @@ version = "0.2.138"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
[[package]]
name = "link-cplusplus"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5"
dependencies = [
"cc",
]
[[package]] [[package]]
name = "local-channel" name = "local-channel"
version = "0.1.3" version = "0.1.3"
@@ -1303,6 +1418,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2"
[[package]] [[package]]
name = "semver" name = "semver"
version = "1.0.14" version = "1.0.14"
@@ -1420,6 +1541,15 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.37" version = "1.0.37"
@@ -1609,6 +1739,12 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]] [[package]]
name = "url" name = "url"
version = "2.3.1" version = "2.3.1"
@@ -1736,6 +1872,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

View File

@@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
diesel = { version = "2.0.0",features = ["postgres","r2d2"] } diesel = { version = "2.0.0",features = ["postgres","r2d2","chrono"] }
dotenv = "0.15" dotenv = "0.15"
chrono = "0.2.25" chrono = "0.2.25"
common = { path = "../common"} common = { path = "../common"}

View File

@@ -1,20 +1,16 @@
use diesel::prelude::*; use crate::models::{Driver, NewDriver};
use diesel::pg::data_types::PgDate;
use common::CommonDriver; use common::CommonDriver;
use crate::models::{Driver,NewDriver}; use diesel::prelude::*;
pub fn listdrivers(connection: &mut PgConnection) pub fn listdrivers(connection: &mut PgConnection) {
{
use crate::schema::drivers::dsl::*; use crate::schema::drivers::dsl::*;
let queury = drivers.load::<Driver>(connection).expect("KANKER"); let queury = drivers.load::<Driver>(connection).expect("KANKER");
for driver in queury for driver in queury {
{ println!("{} {}", driver.name, driver.address);
println!("{} {}",driver.name ,driver.address);
} }
} }
pub fn addriver(connection: &mut PgConnection, new_driver: NewDriver){ pub fn addriver(connection: &mut PgConnection, new_driver: NewDriver) {
use crate::schema::drivers::dsl::*; use crate::schema::drivers::dsl::*;
diesel::insert_into(drivers) diesel::insert_into(drivers)
.values(&new_driver) .values(&new_driver)
@@ -33,7 +29,6 @@ pub fn get_driver(connection: &mut PgConnection, driver_id: i32) -> CommonDriver
id: driver.id, id: driver.id,
name: String::from(&driver.name), name: String::from(&driver.name),
address: String::from(&driver.address), address: String::from(&driver.address),
reg_date: &driver.regdate,
birthdate: String::from(&driver.birthdate),
}; };
} }

View File

@@ -1,34 +1,30 @@
use diesel::{prelude::*, data_types::PgDate};
use crate::schema::*; use crate::schema::*;
use diesel::{data_types::PgDate, prelude::*};
//Admins //Admins
#[derive(Queryable,Debug,AsChangeset,Identifiable)] #[derive(Queryable, Debug, AsChangeset, Identifiable)]
pub pub struct Admin {
struct Admin {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub address: String pub address: String,
} }
#[derive(Insertable)] #[derive(Insertable)]
#[diesel(table_name = admins)] #[diesel(table_name = admins)]
pub pub struct NewAdmin<'a> {
struct NewAdmin<'a> {
pub id: i32, pub id: i32,
pub name: &'a str, pub name: &'a str,
pub address: &'a str pub address: &'a str,
} }
#[derive(Queryable,AsChangeset,Associations)] #[derive(Queryable, AsChangeset, Associations)]
#[diesel(belongs_to(Admin))] #[diesel(belongs_to(Admin))]
pub struct AdminEmail { pub struct AdminEmail {
pub admin_id: i32, pub admin_id: i32,
pub email: String, pub email: String,
} }
#[derive(Insertable,Associations)] #[derive(Insertable, Associations)]
#[diesel(belongs_to(Admin))] #[diesel(belongs_to(Admin))]
#[diesel(table_name = admin_emails)] #[diesel(table_name = admin_emails)]
pub struct NewAdminEmail<'a> { pub struct NewAdminEmail<'a> {
@@ -36,14 +32,13 @@ pub struct NewAdminEmail<'a> {
pub email: &'a str, pub email: &'a str,
} }
//Ticket things //Ticket things
#[derive(Queryable)] #[derive(Queryable)]
pub struct Ticket { pub struct Ticket {
pub id: i32, pub id: i32,
pub category: String, pub category: String,
pub description: String, pub description: String,
pub issue_date: PgDate pub issue_date: PgDate,
} }
#[derive(Insertable)] #[derive(Insertable)]
@@ -72,7 +67,7 @@ pub struct AutoIssuedTicket<'a> {
} }
//Drivers //Drivers
#[derive(Queryable,AsChangeset,Identifiable)] #[derive(Queryable, AsChangeset, Identifiable)]
pub struct Driver { pub struct Driver {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
@@ -92,7 +87,7 @@ pub struct NewDriver<'a> {
} }
//Vehicles //Vehicles
#[derive(Queryable,AsChangeset)] #[derive(Queryable, AsChangeset)]
#[diesel(belongs_to(Driver))] #[diesel(belongs_to(Driver))]
pub struct Vehicle { pub struct Vehicle {
pub model: Option<String>, pub model: Option<String>,
@@ -100,6 +95,5 @@ pub struct Vehicle {
pub chasse_num: i32, pub chasse_num: i32,
pub plate_num: String, pub plate_num: String,
pub vehicle_type: String, pub vehicle_type: String,
pub owner: i32 pub owner: i32,
} }

View File

@@ -22,6 +22,5 @@ pub struct CommonDriver {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub address: String, pub address: String,
pub reg_date: i32, }
pub birthdate: i32,
}