Alright mark just message me to send an env file
This commit is contained in:
@@ -30,37 +30,34 @@ async fn show_arrivals(db_pool: Data<PgPool>) -> impl Responder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("specific")]
|
#[get("specific")]
|
||||||
async fn show_specific(db_pool: Data<PgPool>, t_line: Data<Vec<i8>>, week_day: Data<i8>) -> impl Responder {
|
async fn show_specific(db_pool: Data<PgPool>, t_line: Data<i32>, week_day: Data<i32>) -> impl Responder {
|
||||||
// Query Logic
|
// Query Logic
|
||||||
// Idea: Construct a query bit by bit depending on input
|
// Idea: Construct a query bit by bit depending on input
|
||||||
// GUESS NOT
|
// GUESS NOT
|
||||||
|
|
||||||
let mut dyn_query = QueryBuilder::new("SELECT * FROM arrivals WHERE tram_line = ");
|
// Extract data and match nullables
|
||||||
|
let tram_line: i32 = match t_line.into() {
|
||||||
|
Some(num) => **num,
|
||||||
|
None => 1 as i32
|
||||||
|
|
||||||
// Delet cuz we hardcoding
|
};
|
||||||
if t_line.len() == 1 {
|
let day = match week_day.into() {
|
||||||
dyn_query.push_bind(t_line[0]);
|
Some(num) => **num,
|
||||||
} else {
|
None => 1 as i32,
|
||||||
dyn_query.push_bind(t_line[0]);
|
};
|
||||||
dyn_query.push("OR tram_line = ");
|
//Le query
|
||||||
dyn_query.push_bind(t_line[1]);
|
let arrivals = query_as!(Arrival, "SELECT * FROM arrivals WHERE tram_line = $1 AND week_day = $2", tram_line, day)
|
||||||
} // Should be fine for tramline?
|
.fetch_all(db_pool.get_ref())
|
||||||
|
.await
|
||||||
// Murder this (And me possibly)
|
.expect("Could not fetch arrivals");
|
||||||
dyn_query.push("AND week_day = ");
|
|
||||||
// Yes ik it's giving an encoding error, no i dont know how to fix, just nuke it
|
|
||||||
dyn_query.push_bind(week_day);
|
|
||||||
|
|
||||||
dyn_query.build().sql().into();
|
|
||||||
|
|
||||||
// We don't talk about this
|
// We don't talk about this
|
||||||
// and idk if `query_as!()` will take a QueryBuilder
|
// and idk if `query_as!()` will take a QueryBuilder
|
||||||
let arrivals = String::from("AIDS");
|
let arrivals = String::from("AIDS");
|
||||||
|
|
||||||
// Idk what to do, can't test with db cuz no .env xdxd
|
// Delet cuz we hardcoding
|
||||||
// linly pls i never made an api before and royal son doesn't count
|
|
||||||
|
|
||||||
dbg!(&arrivals);
|
// dbg!(&arrivals);
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("application/json")
|
.content_type("application/json")
|
||||||
.json(arrivals)
|
.json(arrivals)
|
||||||
|
|||||||
Reference in New Issue
Block a user