Consistency added
This commit is contained in:
@@ -87,7 +87,7 @@ pub struct NewDriver<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Vehicles
|
//Vehicles
|
||||||
#[derive(Queryable, AsChangeset)]
|
#[derive(Queryable)]
|
||||||
#[diesel(belongs_to(Driver))]
|
#[diesel(belongs_to(Driver))]
|
||||||
pub struct Vehicle {
|
pub struct Vehicle {
|
||||||
pub model: Option<String>,
|
pub model: Option<String>,
|
||||||
@@ -96,10 +96,10 @@ pub struct Vehicle {
|
|||||||
pub plate_num: String,
|
pub plate_num: String,
|
||||||
pub vehicle_type: String,
|
pub vehicle_type: String,
|
||||||
pub category: String,
|
pub category: String,
|
||||||
pub owner: Option<String>,
|
pub owner: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, AsChangeset)]
|
#[derive(Queryable)]
|
||||||
pub struct Radar {
|
pub struct Radar {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub category: Option<String>,
|
pub category: Option<String>,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use diesel::PgConnection;
|
|||||||
|
|
||||||
use crate::models::Vehicle;
|
use crate::models::Vehicle;
|
||||||
|
|
||||||
pub fn get_vehicle(connection: &mut PgConnection, vehicle_id: i32) -> CommonVehicle {
|
pub fn get_vehicle(connection: &mut PgConnection, vehicle_id: String) -> CommonVehicle {
|
||||||
use crate::schema::vehicles::dsl::*;
|
use crate::schema::vehicles::dsl::*;
|
||||||
let vehicle = &mut vehicles
|
let vehicle = &mut vehicles
|
||||||
.filter(plate_num.eq(vehicle_id))
|
.filter(plate_num.eq(vehicle_id))
|
||||||
@@ -22,20 +22,20 @@ pub fn get_vehicle(connection: &mut PgConnection, vehicle_id: i32) -> CommonVehi
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_vehicle(connection: &mut PgConnection, vehicle: CommonVehicle) -> bool {
|
// pub fn insert_vehicle(connection: &mut PgConnection, vehicle: CommonVehicle) -> bool {
|
||||||
use crate::schema::vehicles::dsl::*;
|
// use crate::schema::vehicles::dsl::*;
|
||||||
//convert CommonVehicle to Vehicle
|
// //convert CommonVehicle to Vehicle
|
||||||
let vehicle = Vehicle {
|
// let vehicle = Vehicle {
|
||||||
model: vehicle.model,
|
// model: vehicle.model,
|
||||||
color: vehicle.color,
|
// color: vehicle.color,
|
||||||
chasse_num: vehicle.chasse_num,
|
// chasse_num: vehicle.chasse_num,
|
||||||
plate_num: vehicle.plate_num,
|
// plate_num: vehicle.plate_num,
|
||||||
vehicle_type: vehicle.vehicle_type,
|
// vehicle_type: vehicle.vehicle_type,
|
||||||
category: vehicle.category,
|
// category: vehicle.category,
|
||||||
owner: vehicle.owner,
|
// owner: vehicle.owner,
|
||||||
};
|
// };
|
||||||
diesel::insert_into(vehicles)
|
// diesel::insert_into(vehicles)
|
||||||
.values(&vehicle)
|
// .values(&vehicle)
|
||||||
.execute(connection)
|
// .execute(connection)
|
||||||
.is_ok()
|
// .is_ok()
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ pub struct CommonVehicle {
|
|||||||
pub category: String,
|
pub category: String,
|
||||||
pub color: Option<String>,
|
pub color: Option<String>,
|
||||||
pub chasse_num: Option<i32>,
|
pub chasse_num: Option<i32>,
|
||||||
pub plate_num: i32,
|
pub plate_num: String,
|
||||||
pub vehicle_type: String,
|
pub vehicle_type: String,
|
||||||
pub owner: Option<String>,
|
pub owner: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use actix_web::{
|
|||||||
};
|
};
|
||||||
use backend::{
|
use backend::{
|
||||||
admin_data::get_admin, driver_data::get_driver, establish_connection, ticket_data::get_ticket,
|
admin_data::get_admin, driver_data::get_driver, establish_connection, ticket_data::get_ticket,
|
||||||
|
vehicle_data::get_vehicle,
|
||||||
};
|
};
|
||||||
// use common::{CommonAdmin, CommonDriver, CommonTicket};
|
// use common::{CommonAdmin, CommonDriver, CommonTicket};
|
||||||
|
|
||||||
@@ -86,7 +87,8 @@ async fn api_test() -> impl Responder {
|
|||||||
|
|
||||||
#[get("api/vehicle/{id}")]
|
#[get("api/vehicle/{id}")]
|
||||||
async fn api_vehicle(id: web::Path<String>) -> impl Responder {
|
async fn api_vehicle(id: web::Path<String>) -> impl Responder {
|
||||||
let fetched_vehicle_data = get_vehicle(&mut establish_connection(), *id);
|
let id = id.into_inner();
|
||||||
|
let fetched_vehicle_data = get_vehicle(&mut establish_connection(), String::from(id));
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type(ContentType::plaintext())
|
.content_type(ContentType::plaintext())
|
||||||
.insert_header(("Access-Control-Allow-Origin", "*"))
|
.insert_header(("Access-Control-Allow-Origin", "*"))
|
||||||
@@ -97,7 +99,7 @@ async fn api_vehicle(id: web::Path<String>) -> impl Responder {
|
|||||||
"Content-Type, Content-Length, User-Agent, X-Requested-With, Range, DNT ",
|
"Content-Type, Content-Length, User-Agent, X-Requested-With, Range, DNT ",
|
||||||
))
|
))
|
||||||
.body(format!(
|
.body(format!(
|
||||||
"Vehicle ID: {}, Vehicle Model: {}, Vehicle Color: {}",
|
"Vehicle ID: {}, Vehicle Category: {}",
|
||||||
fetched_vehicle_data.plate_num, fetched_vehicle_data.model, fetched_vehicle_data.color
|
fetched_vehicle_data.plate_num, fetched_vehicle_data.category
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user