radars and vehicles
This commit is contained in:
@@ -92,8 +92,16 @@ pub struct NewDriver<'a> {
|
||||
pub struct Vehicle {
|
||||
pub model: Option<String>,
|
||||
pub color: Option<String>,
|
||||
pub chasse_num: i32,
|
||||
pub chasse_num: Option<i32>,
|
||||
pub plate_num: String,
|
||||
pub vehicle_type: String,
|
||||
pub owner: i32,
|
||||
pub category: String,
|
||||
pub owner: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Queryable, AsChangeset)]
|
||||
pub struct Radar {
|
||||
pub id: i32,
|
||||
pub category: Option<String>,
|
||||
pub address: Option<String>,
|
||||
}
|
||||
|
||||
@@ -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::<Radar>(connection)
|
||||
.expect("no radars :(")[0];
|
||||
return CommonRadar {
|
||||
id: radar.id,
|
||||
category: radar.category.clone(),
|
||||
address: radar.address.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,10 +73,9 @@ diesel::table! {
|
||||
}
|
||||
|
||||
diesel::table! {
|
||||
radars (serialnumber) {
|
||||
serialnumber -> Int4,
|
||||
#[sql_name = "type"]
|
||||
type_ -> Nullable<Text>,
|
||||
radars (id) {
|
||||
id -> Int4,
|
||||
category -> Nullable<Text>,
|
||||
address -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::<Vehicle>(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()
|
||||
}
|
||||
|
||||
@@ -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<String>,
|
||||
pub address: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CommonVehicle {
|
||||
pub model: Option<String>,
|
||||
pub category: String,
|
||||
pub color: Option<String>,
|
||||
pub chasse_num: Option<i32>,
|
||||
pub plate_num: i32,
|
||||
pub vehicle_type: String,
|
||||
pub owner: Option<String>,
|
||||
}
|
||||
|
||||
BIN
frontend/dist/db-frontend-5a949c39a51fa2c9_bg.wasm
vendored
BIN
frontend/dist/db-frontend-5a949c39a51fa2c9_bg.wasm
vendored
Binary file not shown.
@@ -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();
|
||||
|
||||
BIN
frontend/dist/db-frontend-c0621f030a0450bc_bg.wasm
vendored
Normal file
BIN
frontend/dist/db-frontend-c0621f030a0450bc_bg.wasm
vendored
Normal file
Binary file not shown.
6
frontend/dist/index.html
vendored
6
frontend/dist/index.html
vendored
@@ -2,10 +2,10 @@
|
||||
<meta charset="utf-8">
|
||||
<title>Ze greatest</title>
|
||||
|
||||
<link rel="preload" href="/db-frontend-5a949c39a51fa2c9_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
||||
<link rel="modulepreload" href="/db-frontend-5a949c39a51fa2c9.js"></head>
|
||||
<link rel="preload" href="/db-frontend-c0621f030a0450bc_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
|
||||
<link rel="modulepreload" href="/db-frontend-c0621f030a0450bc.js"></head>
|
||||
<body>
|
||||
<script type="module">import init from '/db-frontend-5a949c39a51fa2c9.js';init('/db-frontend-5a949c39a51fa2c9_bg.wasm');</script><script>(function () {
|
||||
<script type="module">import init from '/db-frontend-c0621f030a0450bc.js';init('/db-frontend-c0621f030a0450bc_bg.wasm');</script><script>(function () {
|
||||
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
var url = protocol + '//' + window.location.host + '/_trunk/ws';
|
||||
var poll_interval = 5000;
|
||||
|
||||
@@ -114,7 +114,9 @@ impl Component for RandomCommit {
|
||||
</>
|
||||
},
|
||||
FetchState::Fetching => html! { "Fetching" },
|
||||
FetchState::Success(data) => html! { <p> {data} </p> },
|
||||
FetchState::Success(data) => {
|
||||
html! { <> <h2> {"Commit Header:"} </h2> {data}</> }
|
||||
}
|
||||
FetchState::Failed(err) => html! { err },
|
||||
}
|
||||
}
|
||||
@@ -177,7 +179,7 @@ impl Component for Driver {
|
||||
</>
|
||||
},
|
||||
FetchState::Fetching => html! { "Fetching" },
|
||||
FetchState::Success(data) => html! { <p> {data} </p> },
|
||||
FetchState::Success(data) => html! { <> <h2> {"Driver"} </h2> {data} </> },
|
||||
FetchState::Failed(err) => html! { err },
|
||||
}
|
||||
}
|
||||
@@ -232,7 +234,8 @@ async fn fetch_driver(url: &'static str) -> Result<String, FetchError> {
|
||||
let mut opts = RequestInit::new();
|
||||
opts.method("GET");
|
||||
opts.mode(RequestMode::Cors); //Cors is required for fetch to work
|
||||
//initialise request
|
||||
|
||||
//initialise request
|
||||
let request = Request::new_with_str_and_init(url, &opts)?;
|
||||
let window = gloo::utils::window();
|
||||
let resp_value = JsFuture::from(window.fetch_with_request(&request)).await?;
|
||||
|
||||
24
src/api.rs
24
src/api.rs
@@ -8,8 +8,7 @@ use backend::{
|
||||
admin_data::get_admin, driver_data::get_driver, establish_connection, ticket_data::get_ticket,
|
||||
};
|
||||
// use common::{CommonAdmin, CommonDriver, CommonTicket};
|
||||
//Json goodies? NAHH
|
||||
//Ticket Table Services
|
||||
|
||||
#[get("api/ticket/{id}")]
|
||||
async fn api_ticket(id: web::Path<i32>) -> impl Responder {
|
||||
let fetched_ticket_data = get_ticket(&mut establish_connection(), *id);
|
||||
@@ -69,6 +68,7 @@ async fn api_driver(id: web::Path<i32>) -> impl Responder {
|
||||
fetched_driver_data.id
|
||||
))
|
||||
}
|
||||
|
||||
#[get("api/test")]
|
||||
async fn api_test() -> impl Responder {
|
||||
HttpResponse::Ok()
|
||||
@@ -81,5 +81,23 @@ async fn api_test() -> impl Responder {
|
||||
))
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-encoded", "gzip"))
|
||||
.body("My balls are on fire :(")
|
||||
.body("Alles gut")
|
||||
}
|
||||
|
||||
#[get("api/vehicle/{id}")]
|
||||
async fn api_vehicle(id: web::Path<String>) -> impl Responder {
|
||||
let fetched_vehicle_data = get_vehicle(&mut establish_connection(), *id);
|
||||
HttpResponse::Ok()
|
||||
.content_type(ContentType::plaintext())
|
||||
.insert_header(("Access-Control-Allow-Origin", "*"))
|
||||
.insert_header(("content-type", "text/plain"))
|
||||
.insert_header(("content-encoded", "gzip"))
|
||||
.insert_header((
|
||||
"Access-Control-Allow-Headers",
|
||||
"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
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user