GG EZ now we have json insertion
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
use actix_web::{get, web, HttpResponse, Responder, post};
|
use actix_web::{get, web::{self, Json}, HttpResponse, Responder, post};
|
||||||
|
|
||||||
pub fn init_arrivals_scope() -> actix_web::Scope {
|
pub fn init_arrivals_scope() -> actix_web::Scope {
|
||||||
let scope = web::scope("/arrivals")
|
let scope = web::scope("/arrivals")
|
||||||
.service(show_arrivals)
|
.service(show_arrivals)
|
||||||
.service(show_specific)
|
.service(show_specific)
|
||||||
.service(insert_arrival);
|
.service(insert_arrival)
|
||||||
|
.service(insert_arrival_json);
|
||||||
scope
|
scope
|
||||||
}
|
}
|
||||||
use chrono::NaiveTime;
|
use chrono::NaiveTime;
|
||||||
@@ -71,3 +72,15 @@ async fn insert_arrival(db_pool: Data<PgPool>, arrival: web::Query<Arrival>) ->
|
|||||||
).execute(db_pool.get_ref()).await.expect("I shat");
|
).execute(db_pool.get_ref()).await.expect("I shat");
|
||||||
HttpResponse::Ok().body("inserted")
|
HttpResponse::Ok().body("inserted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("insert")]
|
||||||
|
async fn insert_arrival_json(db_pool: Data<PgPool>, arrival: Json<Arrival>) -> impl Responder {
|
||||||
|
query!(
|
||||||
|
"INSERT INTO arrivals (time_of_day,week_day,tram_line,direction) VALUES ($1, $2, $3, $4)",
|
||||||
|
arrival.time_of_day,
|
||||||
|
arrival.week_day,
|
||||||
|
arrival.tram_line,
|
||||||
|
arrival.direction
|
||||||
|
).execute(db_pool.get_ref()).await.expect("I shat");
|
||||||
|
HttpResponse::Ok().body("inserted")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user