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