use actix_web::{ get, http::header::ContentType, post, web::{self, Json}, HttpResponse, Responder, }; use backend::{ admin_data::get_admin, driver_data::get_driver, establish_connection, models::NewTicket, ticket_data::{create_ticket, get_ticket, get_tickets}, }; use common::{CommonAdmin, CommonDriver, CommonTicket}; // Json goodies? NAHH // Ticket Table Services #[get("api/json/ticket/{id}")] async fn api_json_ticket(id: web::Path) -> impl Responder { let fetched_ticket_data = get_ticket(&mut establish_connection(), *id); HttpResponse::Ok() .content_type(ContentType::json()) .insert_header(("Access-Control-Allow-Origin", "*")) .insert_header(("content-encoded", "gzip")) .insert_header(( "Access-Control-Allow-Headers", "Content-Type, Content-Length, User-Agent, X-Requested-With, Range, DNT ", )) .json(fetched_ticket_data) } #[post("api/json/ticket/new")] async fn api_json_ticket_new(ticket: web::Json) -> impl Responder { let input = ticket.into_inner(); let input_result = NewTicket { id: input.id, description: &input.description, category: &input.category, }; create_ticket(&mut establish_connection(), input_result); HttpResponse::Ok() .content_type(ContentType::plaintext()) .insert_header(("Access-Control-Allow-Origin", "*")) .insert_header(("Access-Control-Allow-Methods", "GET")) .insert_header(( "Access-Control-Allow-Headers", "Content-Type, Content-Length, User-Agent, X-Requested-With, Range, DNT ", )) .insert_header(("content-type", "text/plain")) .insert_header(("content-encoded", "gzip")) .body("Alles gut") } // Getting admin data or smth idk #[get("api/json/admin/{id}")] async fn api_json_admin(id: web::Path) -> Json { let fetched_admin_data = get_admin(&mut establish_connection(), *id); Json(fetched_admin_data) } #[get("api/json/driver/{id}")] async fn api_json_driver(id: web::Path) -> Json { let fetched_driver_data = get_driver(&mut establish_connection(), *id); Json(fetched_driver_data) } #[get("api/json/tickets/{driver}")] async fn api_json_driver_tickets(id: web::Path) -> impl Responder { let fetched_tickets = get_tickets(&mut establish_connection(), *id); HttpResponse::Ok() .content_type(ContentType::json()) .insert_header(("Access-Control-Allow-Origin", "*")) .insert_header(("content-encoded", "gzip")) .insert_header(( "Access-Control-Allow-Headers", "Content-Type, Content-Length, User-Agent, X-Requested-With, Range, DNT ", )) .json(fetched_tickets) }