radars and vehicles

This commit is contained in:
LinlyBoi
2022-12-25 13:10:38 +02:00
parent 298b35af4c
commit f9dfb4bf64
11 changed files with 133 additions and 25 deletions

View File

@@ -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
))
}