add load time and page titles
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 15m56s

This commit is contained in:
Nicholas Orlowsky 2025-09-21 21:25:04 -04:00
parent 8fd41b1090
commit 95bef54eed
No known key found for this signature in database
GPG key ID: A9F3BA4C0AA7A70B
6 changed files with 32 additions and 177 deletions

View file

@ -1,6 +1,4 @@
use actix_web::{get, web::{self, Data}, App, HttpResponse, HttpServer, Responder};
use chrono::TimeDelta;
use database::get_nta_by_stop_id;
use actix_web::{get, web::Data, App, HttpResponse, HttpServer, Responder};
use env_logger::Env;
use log::*;
use dotenv::dotenv;
@ -23,22 +21,11 @@ async fn get_index() -> impl Responder {
HttpResponse::Ok().body(templates::ContentTemplate {
page_title: None,
page_desc: None,
content: templates::IndexTemplate {}
content: templates::IndexTemplate {},
load_time_ms: None
}.render().unwrap())
}
#[get("/api/stop/{stop_id}/nta")]
async fn api_get_nta(state: Data<Arc<AppState>>, path: web::Path<String>) -> impl Responder {
let route_id = path.into_inner().split(',') .map(|s| s.parse::<i64>())
.collect::<Result<Vec<i64>, _>>().unwrap();
let route_r = get_nta_by_stop_id(route_id, chrono::Utc::now(), chrono::Utc::now() + TimeDelta::minutes(30), &mut state.database.begin().await.unwrap()).await;
if let Ok(route) = route_r {
HttpResponse::Ok().json(route)
} else {
HttpResponse::InternalServerError().body(format!("Error {:?}", route_r.err()))
}
}
#[actix_web::main]
async fn main() -> ::anyhow::Result<()> {
env_logger::init_from_env(Env::default().default_filter_or("septastic_api=info"));
@ -47,8 +34,6 @@ async fn main() -> ::anyhow::Result<()> {
let version: &str = option_env!("CARGO_PKG_VERSION").expect("Expected package version");
info!("Starting SEPTASTIC Server v{} (commit: {})", version, "NONE");
info!("Connecting to postgres database");
let connection_string =
std::env::var("DB_CONNSTR").expect("Expected database connection string");
@ -65,12 +50,10 @@ async fn main() -> ::anyhow::Result<()> {
trip_tracking_service: tt_service
});
HttpServer::new(move || {
App::new()
.wrap(actix_cors::Cors::permissive())
.app_data(Data::new(state.clone()))
.service(api_get_nta)
.service(controllers::route::api_get_route)
.service(controllers::route::api_get_schedule)
.service(controllers::route::get_route)