[#28] Switched search_streets to database
This commit is contained in:
parent
95564e8111
commit
91985a1710
11 changed files with 48 additions and 22 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Reference in a new issue