Its friday and the drivers are happy
This commit is contained in:
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user