Post added, new service, commented out id

This commit is contained in:
2023-12-19 13:22:14 +02:00
parent 45136a8e10
commit 061ff570a6

View File

@@ -1,27 +1,31 @@
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, 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);
scope scope
} }
use chrono::NaiveTime; use chrono::NaiveTime;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Arrival { pub struct Arrival {
a_id: i32, // a_id: i32,
time_of_day: NaiveTime, time_of_day: NaiveTime,
week_day: i32, week_day: i32,
tram_line: i32, tram_line: i32,
direction: bool, direction: bool,
} }
use sqlx::{PgPool, query_as}; use sqlx::{query, query_as, PgPool};
use web::Data; use web::Data;
#[get("all")] #[get("all")]
async fn show_arrivals(db_pool: Data<PgPool>) -> impl Responder { async fn show_arrivals(db_pool: Data<PgPool>) -> impl Responder {
let arrivals = query_as!(Arrival, r#"SELECT * FROM arrivals"#) let arrivals = query_as!(
Arrival,
r#"SELECT time_of_day,week_day,tram_line,direction FROM arrivals"#
)
.fetch_all(db_pool.get_ref()) .fetch_all(db_pool.get_ref())
.await .await
.expect("Could not fetch arrivals"); .expect("Could not fetch arrivals");
@@ -41,7 +45,7 @@ async fn show_specific(db_pool: Data<PgPool>, filter: web::Query<ArrivalFilter>)
//Le query //Le query
let arrivals = query_as!( let arrivals = query_as!(
Arrival, Arrival,
"SELECT * FROM arrivals WHERE tram_line = $1 AND week_day = $2", "SELECT time_of_day,week_day,tram_line,direction FROM arrivals WHERE tram_line = $1 AND week_day = $2",
filter.tram_line, filter.tram_line,
filter.week_day filter.week_day
) )