Overhaul refactor. Still things in progress

This commit is contained in:
2025-04-05 22:42:13 -04:00
parent 310d1eaad8
commit 769762dfa7
133 changed files with 119890 additions and 8784 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,45 +1,34 @@
use crate::{error::ApiError, db::Metadata};
use crate::error::Error;
use crate::metars::Metar;
use actix_web::{get, web, HttpResponse, HttpRequest};
use log::error;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct MetarsResponse {
pub data: Vec<Metar>,
pub meta: Metadata,
}
#[derive(Debug, Serialize, Deserialize)]
struct GetAllParameters {
struct FindAllParameters {
icaos: Option<String>,
}
#[get("metars")]
async fn get_all(req: HttpRequest) -> HttpResponse {
let params = web::Query::<GetAllParameters>::from_query(req.query_string()).unwrap();
let icao_option = params.icaos.clone();
async fn find_all(req: HttpRequest) -> HttpResponse {
let parameters = web::Query::<FindAllParameters>::from_query(req.query_string()).unwrap();
let icao_option = &parameters.icaos;
let icao_string = match icao_option {
Some(i) => i,
None => return HttpResponse::UnprocessableEntity().body("Missing icaos parameter"),
};
let icaos: Vec<&str> = icao_string.split(',').collect();
let metars =
match web::block(|| Ok::<_, ApiError>(async { Metar::get_all(icao_string).await }))
.await
.unwrap()
.unwrap()
.await
{
Ok(a) => a,
Err(err) => {
error!("{}", err);
return err.to_http_response();
}
};
let metars = match Metar::find_all(&icaos).await {
Ok(a) => a,
Err(err) => {
error!("{}", err);
return err.to_http_response();
}
};
HttpResponse::Ok().json(metars)
}
pub fn init_routes(config: &mut web::ServiceConfig) {
config.service(get_all);
config.service(find_all);
}