diff --git a/backend/src/models.rs b/backend/src/models.rs index 0b4698c..336137d 100644 --- a/backend/src/models.rs +++ b/backend/src/models.rs @@ -92,8 +92,16 @@ pub struct NewDriver<'a> { pub struct Vehicle { pub model: Option, pub color: Option, - pub chasse_num: i32, + pub chasse_num: Option, pub plate_num: String, pub vehicle_type: String, - pub owner: i32, + pub category: String, + pub owner: Option, +} + +#[derive(Queryable, AsChangeset)] +pub struct Radar { + pub id: i32, + pub category: Option, + pub address: Option, } diff --git a/backend/src/radar_data.rs b/backend/src/radar_data.rs index e69de29..ca68574 100644 --- a/backend/src/radar_data.rs +++ b/backend/src/radar_data.rs @@ -0,0 +1,19 @@ +use common::CommonRadar; +use diesel::prelude::*; +use diesel::PgConnection; + +use crate::models::Radar; + +pub fn get_radar(connection: &mut PgConnection, radar_id: i32) -> CommonRadar { + use crate::schema::radars::dsl::*; + let radar = &mut radars + .filter(id.eq(radar_id)) + .limit(1) + .load::(connection) + .expect("no radars :(")[0]; + return CommonRadar { + id: radar.id, + category: radar.category.clone(), + address: radar.address.clone(), + }; +} diff --git a/backend/src/schema.rs b/backend/src/schema.rs index 5c41e55..470b923 100644 --- a/backend/src/schema.rs +++ b/backend/src/schema.rs @@ -73,10 +73,9 @@ diesel::table! { } diesel::table! { - radars (serialnumber) { - serialnumber -> Int4, - #[sql_name = "type"] - type_ -> Nullable, + radars (id) { + id -> Int4, + category -> Nullable, address -> Nullable, } } diff --git a/backend/src/vehicle_data.rs b/backend/src/vehicle_data.rs index e69de29..c3ece2a 100644 --- a/backend/src/vehicle_data.rs +++ b/backend/src/vehicle_data.rs @@ -0,0 +1,41 @@ +use common::CommonVehicle; +use diesel::prelude::*; +use diesel::PgConnection; + +use crate::models::Vehicle; + +pub fn get_vehicle(connection: &mut PgConnection, vehicle_id: i32) -> CommonVehicle { + use crate::schema::vehicles::dsl::*; + let vehicle = &mut vehicles + .filter(plate_num.eq(vehicle_id)) + .limit(1) + .load::(connection) + .expect("no vehicles :(")[0]; + return CommonVehicle { + model: vehicle.model.clone(), + color: vehicle.color.clone(), + chasse_num: vehicle.chasse_num, + plate_num: vehicle.plate_num.clone(), + vehicle_type: vehicle.vehicle_type.clone(), + category: vehicle.category.clone(), + owner: vehicle.owner, + }; +} + +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() +} diff --git a/common/src/lib.rs b/common/src/lib.rs index c6b8fb9..54c496d 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -23,3 +23,24 @@ pub struct CommonDriver { pub name: String, pub address: String, } + +//generate common radar struct +#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct CommonRadar { + pub id: i32, + pub category: Option, + pub address: Option, +} + +#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct CommonVehicle { + pub model: Option, + pub category: String, + pub color: Option, + pub chasse_num: Option, + pub plate_num: i32, + pub vehicle_type: String, + pub owner: Option, +} diff --git a/frontend/dist/db-frontend-5a949c39a51fa2c9_bg.wasm b/frontend/dist/db-frontend-5a949c39a51fa2c9_bg.wasm deleted file mode 100644 index 00f6af0..0000000 Binary files a/frontend/dist/db-frontend-5a949c39a51fa2c9_bg.wasm and /dev/null differ diff --git a/frontend/dist/db-frontend-5a949c39a51fa2c9.js b/frontend/dist/db-frontend-c0621f030a0450bc.js similarity index 98% rename from frontend/dist/db-frontend-5a949c39a51fa2c9.js rename to frontend/dist/db-frontend-c0621f030a0450bc.js index a4a393b..c894770 100644 --- a/frontend/dist/db-frontend-5a949c39a51fa2c9.js +++ b/frontend/dist/db-frontend-c0621f030a0450bc.js @@ -204,6 +204,9 @@ function makeMutClosure(arg0, arg1, dtor, f) { return real; } +function __wbg_adapter_18(arg0, arg1, arg2) { + wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h414630ac9216cad4(arg0, arg1, addHeapObject(arg2)); +} let stack_pointer = 32; @@ -212,7 +215,7 @@ function addBorrowedObject(obj) { heap[--stack_pointer] = obj; return stack_pointer; } -function __wbg_adapter_18(arg0, arg1, arg2) { +function __wbg_adapter_21(arg0, arg1, arg2) { try { wasm._dyn_core__ops__function__FnMut___A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h9380123c3ed0eddb(arg0, arg1, addBorrowedObject(arg2)); } finally { @@ -220,10 +223,6 @@ function __wbg_adapter_18(arg0, arg1, arg2) { } } -function __wbg_adapter_21(arg0, arg1, arg2) { - wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h414630ac9216cad4(arg0, arg1, addHeapObject(arg2)); -} - let cachedUint32Memory0 = new Uint32Array(); function getUint32Memory0() { @@ -616,12 +615,12 @@ function getImports() { imports.wbg.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; - imports.wbg.__wbindgen_closure_wrapper3547 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 236, __wbg_adapter_18); + imports.wbg.__wbindgen_closure_wrapper4152 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 287, __wbg_adapter_18); return addHeapObject(ret); }; - imports.wbg.__wbindgen_closure_wrapper6208 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 263, __wbg_adapter_21); + imports.wbg.__wbindgen_closure_wrapper4211 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 303, __wbg_adapter_21); return addHeapObject(ret); }; @@ -659,7 +658,7 @@ function initSync(module) { async function init(input) { if (typeof input === 'undefined') { - input = new URL('db-frontend-5a949c39a51fa2c9_bg.wasm', import.meta.url); + input = new URL('db-frontend-c0621f030a0450bc_bg.wasm', import.meta.url); } const imports = getImports(); diff --git a/frontend/dist/db-frontend-c0621f030a0450bc_bg.wasm b/frontend/dist/db-frontend-c0621f030a0450bc_bg.wasm new file mode 100644 index 0000000..bc31daf Binary files /dev/null and b/frontend/dist/db-frontend-c0621f030a0450bc_bg.wasm differ diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 26caeaa..46ef420 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -2,10 +2,10 @@ Ze greatest - - + + -