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

View File

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

View File

@@ -1,20 +1,16 @@
use diesel::prelude::*;
use diesel::pg::data_types::PgDate;
use crate::models::{Driver, NewDriver};
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::*;
let queury = drivers.load::<Driver>(connection).expect("KANKER");
for driver in queury
{
println!("{} {}",driver.name ,driver.address);
for driver in queury {
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::*;
diesel::insert_into(drivers)
.values(&new_driver)
@@ -33,7 +29,6 @@ pub fn get_driver(connection: &mut PgConnection, driver_id: i32) -> CommonDriver
id: driver.id,
name: String::from(&driver.name),
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 diesel::{data_types::PgDate, prelude::*};
//Admins
#[derive(Queryable,Debug,AsChangeset,Identifiable)]
pub
struct Admin {
#[derive(Queryable, Debug, AsChangeset, Identifiable)]
pub struct Admin {
pub id: i32,
pub name: String,
pub address: String
pub address: String,
}
#[derive(Insertable)]
#[diesel(table_name = admins)]
pub
struct NewAdmin<'a> {
pub struct NewAdmin<'a> {
pub id: i32,
pub name: &'a str,
pub address: &'a str
pub address: &'a str,
}
#[derive(Queryable,AsChangeset,Associations)]
#[derive(Queryable, AsChangeset, Associations)]
#[diesel(belongs_to(Admin))]
pub struct AdminEmail {
pub admin_id: i32,
pub email: String,
}
#[derive(Insertable,Associations)]
#[derive(Insertable, Associations)]
#[diesel(belongs_to(Admin))]
#[diesel(table_name = admin_emails)]
pub struct NewAdminEmail<'a> {
@@ -36,14 +32,13 @@ pub struct NewAdminEmail<'a> {
pub email: &'a str,
}
//Ticket things
#[derive(Queryable)]
pub struct Ticket {
pub id: i32,
pub category: String,
pub description: String,
pub issue_date: PgDate
pub issue_date: PgDate,
}
#[derive(Insertable)]
@@ -72,7 +67,7 @@ pub struct AutoIssuedTicket<'a> {
}
//Drivers
#[derive(Queryable,AsChangeset,Identifiable)]
#[derive(Queryable, AsChangeset, Identifiable)]
pub struct Driver {
pub id: i32,
pub name: String,
@@ -92,7 +87,7 @@ pub struct NewDriver<'a> {
}
//Vehicles
#[derive(Queryable,AsChangeset)]
#[derive(Queryable, AsChangeset)]
#[diesel(belongs_to(Driver))]
pub struct Vehicle {
pub model: Option<String>,
@@ -100,6 +95,5 @@ pub struct Vehicle {
pub chasse_num: i32,
pub plate_num: String,
pub vehicle_type: String,
pub owner: i32
pub owner: i32,
}