4 Commits

Author SHA1 Message Date
LinlyBoi
d466c1199d Its friday and the drivers are happy 2022-12-23 21:54:20 +02:00
LinlyBoi
bcf3ec0d8c TyPe MiSmAtCh pGdAtE eXpEcTeD StRiNg 2022-12-23 19:35:08 +00:00
LinlyBoi
99ec37991e third time's a charm 2022-12-23 19:10:33 +02:00
LinlyBoi
f99e1504f6 bum 2022-12-23 17:07:10 +00:00
9 changed files with 229 additions and 36 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target /target
.env

148
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,11 +456,56 @@ 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"
dependencies = [ dependencies = [
"common", "common",
"diesel",
"yew", "yew",
] ]
@@ -457,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",
@@ -845,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"
@@ -910,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"
@@ -1302,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"
@@ -1419,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"
@@ -1608,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"
@@ -1735,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,4 +1,5 @@
use crate::models::{Admin, AdminEmail, NewAdmin, NewAdminEmail}; use crate::models::{Admin, AdminEmail, NewAdmin, NewAdminEmail};
use common::CommonAdmin;
use diesel::prelude::*; use diesel::prelude::*;
pub fn listadmins(connection: &mut PgConnection) -> String { pub fn listadmins(connection: &mut PgConnection) -> String {
@@ -38,3 +39,17 @@ pub fn listadminmails(connection: &mut PgConnection) {
println!("{} {}", addmail.email, addmail.admin_id); println!("{} {}", addmail.email, addmail.admin_id);
} }
} }
pub fn get_admin(connection: &mut PgConnection, admin_id: i32) -> CommonAdmin {
use crate::schema::admins::dsl::*;
let admin = &mut admins
.filter(id.eq(admin_id))
.limit(1)
.load::<Admin>(connection)
.expect("no admins :(")[0];
return CommonAdmin {
id: admin.id,
name: String::from(&admin.name),
address: String::from(&admin.address),
};
}

View File

@@ -1,21 +1,34 @@
use crate::models::{Driver, NewDriver};
use common::CommonDriver;
use diesel::prelude::*; use diesel::prelude::*;
use crate::models::{Driver,NewDriver};
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)
.execute(connection) .execute(connection)
.expect("Couldn't insert new driver :)"); .expect("Couldn't insert new driver :)");
} }
pub fn get_driver(connection: &mut PgConnection, driver_id: i32) -> CommonDriver {
use crate::schema::drivers::dsl::*;
let driver = &mut drivers
.filter(id.eq(driver_id))
.limit(1)
.load::<Driver>(connection)
.expect("no drivers :(")[0];
return CommonDriver {
id: driver.id,
name: String::from(&driver.name),
address: String::from(&driver.address),
};
}

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,
@@ -83,8 +78,7 @@ pub struct Driver {
#[derive(Insertable)] #[derive(Insertable)]
#[diesel(table_name = drivers)] #[diesel(table_name = drivers)]
pub pub struct NewDriver<'a> {
struct NewDriver<'a> {
pub id: i32, pub id: i32,
pub name: &'a str, pub name: &'a str,
pub address: &'a str, pub address: &'a str,
@@ -93,7 +87,7 @@ 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>,
@@ -101,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

@@ -15,3 +15,12 @@ pub struct CommonAdmin {
pub name: String, pub name: String,
pub address: String, pub address: String,
} }
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CommonDriver {
pub id: i32,
pub name: String,
pub address: String,
}

View File

@@ -8,3 +8,4 @@ edition = "2021"
[dependencies] [dependencies]
yew = { version = "0.20.0", features = ["csr"] } yew = { version = "0.20.0", features = ["csr"] }
common = { path = "../common"} common = { path = "../common"}
diesel = { version = "2.0.0",features = ["postgres","r2d2"] }

View File

@@ -3,8 +3,10 @@ use actix_web::{
web::{self, Json}, web::{self, Json},
App, HttpServer, App, HttpServer,
}; };
use backend::{establish_connection, ticket_data::get_ticket}; use backend::{establish_connection, admin_data::get_admin, ticket_data::get_ticket, driver_data::get_driver};
use common::CommonAdmin;
use common::CommonTicket; use common::CommonTicket;
use common::CommonDriver;
// //Admin Services // //Admin Services
// #[get("/api/admin/{id}")] // #[get("/api/admin/{id}")]
@@ -18,15 +20,28 @@ use common::CommonTicket;
//Ticket Table Services //Ticket Table Services
#[get("api/ticket/{id}")] #[get("api/ticket/{id}")]
async fn ticket(id: web::Path<i32>) -> Json<CommonTicket> { async fn api_ticket(id: web::Path<i32>) -> Json<CommonTicket> {
let fetched_ticket = get_ticket(&mut establish_connection(), *id); let fetched_ticket_data = get_ticket(&mut establish_connection(), *id);
Json(fetched_ticket) Json(fetched_ticket_data)
}
// Getting admin data or smth idk
#[get("api/admin/{id}")]
async fn api_admin(id: web::Path<i32>) -> Json<CommonAdmin> {
let fetched_admin_data = get_admin(&mut establish_connection(), *id);
Json(fetched_admin_data)
}
#[get("api/driver/{id}")]
async fn api_driver(id: web::Path<i32>) -> Json<CommonDriver> {
let fetched_driver_data = get_driver(&mut establish_connection(), *id);
Json(fetched_driver_data)
} }
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(ticket)) HttpServer::new(|| App::new().service(api_ticket).service(api_admin).service(api_driver))
.bind(("127.0.0.1", 8081))? .bind(("0.0.0.0", 48590))?
.run() .run()
.await .await
} }