Consistency added
This commit is contained in:
@@ -87,7 +87,7 @@ pub struct NewDriver<'a> {
|
||||
}
|
||||
|
||||
//Vehicles
|
||||
#[derive(Queryable, AsChangeset)]
|
||||
#[derive(Queryable)]
|
||||
#[diesel(belongs_to(Driver))]
|
||||
pub struct Vehicle {
|
||||
pub model: Option<String>,
|
||||
@@ -96,10 +96,10 @@ pub struct Vehicle {
|
||||
pub plate_num: String,
|
||||
pub vehicle_type: String,
|
||||
pub category: String,
|
||||
pub owner: Option<String>,
|
||||
pub owner: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Queryable, AsChangeset)]
|
||||
#[derive(Queryable)]
|
||||
pub struct Radar {
|
||||
pub id: i32,
|
||||
pub category: Option<String>,
|
||||
|
||||
@@ -4,7 +4,7 @@ use diesel::PgConnection;
|
||||
|
||||
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::*;
|
||||
let vehicle = &mut vehicles
|
||||
.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 {
|
||||
use crate::schema::vehicles::dsl::*;
|
||||
//convert CommonVehicle to Vehicle
|
||||
let vehicle = Vehicle {
|
||||
model: vehicle.model,
|
||||
color: vehicle.color,
|
||||
chasse_num: vehicle.chasse_num,
|
||||
plate_num: vehicle.plate_num,
|
||||
vehicle_type: vehicle.vehicle_type,
|
||||
category: vehicle.category,
|
||||
owner: vehicle.owner,
|
||||
};
|
||||
diesel::insert_into(vehicles)
|
||||
.values(&vehicle)
|
||||
.execute(connection)
|
||||
.is_ok()
|
||||
}
|
||||
// pub fn insert_vehicle(connection: &mut PgConnection, vehicle: CommonVehicle) -> bool {
|
||||
// use crate::schema::vehicles::dsl::*;
|
||||
// //convert CommonVehicle to Vehicle
|
||||
// let vehicle = Vehicle {
|
||||
// model: vehicle.model,
|
||||
// color: vehicle.color,
|
||||
// chasse_num: vehicle.chasse_num,
|
||||
// plate_num: vehicle.plate_num,
|
||||
// vehicle_type: vehicle.vehicle_type,
|
||||
// category: vehicle.category,
|
||||
// owner: vehicle.owner,
|
||||
// };
|
||||
// diesel::insert_into(vehicles)
|
||||
// .values(&vehicle)
|
||||
// .execute(connection)
|
||||
// .is_ok()
|
||||
// }
|
||||
|
||||
@@ -40,7 +40,7 @@ pub struct CommonVehicle {
|
||||
pub category: String,
|
||||
pub color: Option<String>,
|
||||
pub chasse_num: Option<i32>,
|
||||
pub plate_num: i32,
|
||||
pub plate_num: String,
|
||||
pub vehicle_type: String,
|
||||
pub owner: Option<String>,
|
||||
pub owner: Option<i32>,
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use actix_web::{
|
||||
};
|
||||
use backend::{
|
||||
admin_data::get_admin, driver_data::get_driver, establish_connection, ticket_data::get_ticket,
|
||||
vehicle_data::get_vehicle,
|
||||
};
|
||||
// use common::{CommonAdmin, CommonDriver, CommonTicket};
|
||||
|
||||
@@ -86,7 +87,8 @@ async fn api_test() -> impl Responder {
|
||||
|
||||
#[get("api/vehicle/{id}")]
|
||||
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()
|
||||
.content_type(ContentType::plaintext())
|
||||
.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 ",
|
||||
))
|
||||
.body(format!(
|
||||
"Vehicle ID: {}, Vehicle Model: {}, Vehicle Color: {}",
|
||||
fetched_vehicle_data.plate_num, fetched_vehicle_data.model, fetched_vehicle_data.color
|
||||
"Vehicle ID: {}, Vehicle Category: {}",
|
||||
fetched_vehicle_data.plate_num, fetched_vehicle_data.category
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user