[#28] Switched search_streets to database

This commit is contained in:
Jef Roosens 2021-04-17 22:39:22 +02:00
parent 95564e8111
commit 91985a1710
Signed by: Jef Roosens
GPG key ID: B580B976584B5F30
11 changed files with 48 additions and 22 deletions

View file

@ -47,7 +47,7 @@ embed_migrations!();
// This defines a connection to the database
#[database("postgres_fej")]
struct FejDbConn(diesel::PgConnection);
pub struct FejDbConn(diesel::PgConnection);
// I'd like to thank Stackoverflow for helping me with this
// https://stackoverflow.com/questions/61047355/how-to-run-diesel-migration-with-rocket-in-production

View file

@ -1,3 +1,4 @@
use crate::FejDbConn;
use fej::ivago::{get_pickup_times, search_streets, BasicDate, PickupTime, Street};
use rocket::http::Status;
use rocket_contrib::json::Json;
@ -9,8 +10,8 @@ use rocket_contrib::json::Json;
///
/// * `search_term` - Search term to use to look for streets
#[get("/search?<q>")]
pub fn route_search_streets(q: String) -> Result<Json<Vec<Street>>, Status> {
Ok(Json(search_streets(q.as_str())?))
pub fn route_search_streets(db_conn: FejDbConn, q: String) -> Result<Json<Vec<Street>>, Status> {
Ok(Json(search_streets(&db_conn.0, q.as_str())?))
}
/// Handles returning of pickup times for a specific address. It returns a list