Working on inserting metars and cleanup

This commit is contained in:
2023-09-12 07:58:12 -04:00
parent f7aaa1dc81
commit e8462665b0
8 changed files with 65327 additions and 19794 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -56,9 +56,9 @@ impl Airports {
Ok(airports) Ok(airports)
} }
pub fn find(id: i32) -> Result<Self, CustomError> { pub fn find(icao: String) -> Result<Self, CustomError> {
let mut conn = db::connection()?; let mut conn = db::connection()?;
let airport = airports::table.filter(airports::id.eq(id)).first(&mut conn)?; let airport = airports::table.filter(airports::icao.eq(icao)).first(&mut conn)?;
Ok(airport) Ok(airport)
} }

View File

@@ -45,9 +45,9 @@ async fn find_all(req: HttpRequest) -> HttpResponse {
} }
} }
#[get("/airports/{id}")] #[get("/airports/{icao}")]
async fn find(id: web::Path<i32>) -> HttpResponse { async fn find(icao: web::Path<String>) -> HttpResponse {
match Airports::find(id.into_inner()) { match Airports::find(icao.into_inner()) {
Ok(a) => HttpResponse::Ok().json(a), Ok(a) => HttpResponse::Ok().json(a),
Err(err) => { Err(err) => {
error!("{}", err); error!("{}", err);

View File

@@ -1,7 +1,7 @@
use crate::{error_handler::CustomError, db}; use crate::{error_handler::CustomError, db};
use crate::schema::metars; use crate::schema::metars;
use diesel::prelude::*; use diesel::prelude::*;
use log::warn; use log::{warn, error, debug};
use std::io::BufRead; use std::io::BufRead;
use quick_xml::{Reader, events::{Event, BytesStart}, Writer, de::Deserializer}; use quick_xml::{Reader, events::{Event, BytesStart}, Writer, de::Deserializer};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -171,11 +171,15 @@ impl Metars {
vec![] vec![]
} }
}; };
match diesel::insert_into(metars::table).values(&metars).execute(&mut conn) {
Ok(rows) => debug!("Inserted {} metar rows", rows),
Err(err) => error!("Unable to insert metar data; {}", err)
};
let mut returned_metars: Vec<Self> = vec![]; let mut returned_metars: Vec<Self> = vec![];
for metar in &metars { for metar in &metars {
let _ = diesel::insert_into(metars::table) // let _ = diesel::insert_into(metars::table)
.values(metar) // .values(metar)
.execute(&mut conn); // .execute(&mut conn);
returned_metars.push(Self { returned_metars.push(Self {
id: 0, id: 0,
raw_text: metar.raw_text.to_string(), raw_text: metar.raw_text.to_string(),

View File

@@ -7,7 +7,7 @@ export default async function Page({ params }: { params: { icao: string } }) {
return ( return (
<> <>
<div className='border-b border-gray-200 bg-gray-400 px-4 py-5 sm:px-6 flex justify-between'> <div className='border-b border-gray-200 bg-gray-400 px-4 py-5 sm:px-6 flex justify-between'>
<h3 className='text-base font-semibold leading-6 text-gray-900'>{airport?.name}</h3> <h3 className='text-base font-semibold leading-6 text-gray-900'>{airport.full_name}</h3>
<Link href={'/'}>Back</Link> <Link href={'/'}>Back</Link>
</div> </div>
</> </>

View File

@@ -18,7 +18,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
</head> </head>
<body className='bg-gray-600'> <body className='bg-gray-600'>
<div className='flex justify-between bg-gray-700 px-4 py-1 sm:px-6 select-none'> <div className='flex justify-between bg-gray-700 px-4 py-1 sm:px-6 select-none'>
<h3 className='text-lg font-bold leading-6 text-gray-200'>Aviation Weather</h3> <Link href={'/'}>
<h3 className='text-lg font-bold leading-6 text-gray-200'>Aviation Weather</h3>
</Link>
<Link className='text-base text-gray-200' href={'/profile'}> <Link className='text-base text-gray-200' href={'/profile'}>
Profile Profile
</Link> </Link>

View File

@@ -0,0 +1,3 @@
export default async function Page() {
return <></>;
}

View File

@@ -141,8 +141,8 @@ function MapTiles() {
return ( return (
<> <>
<TileLayer <TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution='&copy; <a href="https://www.osm.org/copyright">OpenStreetMap</a> contributors'
url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
/> />
{airports.map((airport) => ( {airports.map((airport) => (
<Marker key={airport.icao} position={[airport.point.y, airport.point.x]} icon={icon(airport)}> <Marker key={airport.icao} position={[airport.point.y, airport.point.x]} icon={icon(airport)}>