Fixed airport responses
This commit is contained in:
@@ -22,7 +22,7 @@ pub struct Airport {
|
||||
pub iata_code: String,
|
||||
pub local_code: String,
|
||||
pub point: Point,
|
||||
pub tower: Option<bool>,
|
||||
pub has_tower: Option<bool>,
|
||||
}
|
||||
|
||||
impl Into<QueryAirport> for Airport {
|
||||
|
||||
@@ -106,10 +106,17 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
|
||||
let pages = ((total as f64) / (if limit <= 0 { 1 } else { limit} as f64)).ceil() as i64;
|
||||
|
||||
match web::block(move || QueryAirport::get_all(&filters, limit, page)).await.unwrap() {
|
||||
Ok(a) => HttpResponse::Ok().json(Response {
|
||||
data: a,
|
||||
meta: Some(Metadata { page, limit, pages, total })
|
||||
}),
|
||||
Ok(a) => {
|
||||
// Convert Vec<QueryAirport> to Vec<Airport>
|
||||
let mut airports: Vec<Airport> = vec![];
|
||||
for airport in a {
|
||||
airports.push(airport.into());
|
||||
}
|
||||
HttpResponse::Ok().json(Response {
|
||||
data: airports,
|
||||
meta: Some(Metadata { page, limit, pages, total })
|
||||
})
|
||||
},
|
||||
Err(err) => {
|
||||
error!("{}", err);
|
||||
err.to_http_response()
|
||||
@@ -120,10 +127,13 @@ async fn get_all(req: HttpRequest) -> HttpResponse {
|
||||
#[get("/{icao}")]
|
||||
async fn get(icao: web::Path<String>) -> HttpResponse {
|
||||
match QueryAirport::find(icao.into_inner()) {
|
||||
Ok(a) => HttpResponse::Ok().json(Response {
|
||||
data: a,
|
||||
meta: Some(Metadata { page: 1, limit: 1, pages: 1, total: 1 })
|
||||
}),
|
||||
Ok(a) => {
|
||||
let airport: Airport = a.into();
|
||||
HttpResponse::Ok().json(Response {
|
||||
data: airport,
|
||||
meta: Some(Metadata { page: 1, limit: 1, pages: 1, total: 1 })
|
||||
})
|
||||
},
|
||||
Err(err) => {
|
||||
error!("{}", err);
|
||||
err.to_http_response()
|
||||
@@ -139,7 +149,10 @@ async fn create(airport: web::Json<Airport>, auth: JwtAuth) -> HttpResponse {
|
||||
};
|
||||
let query_airport: QueryAirport = airport.into_inner().into();
|
||||
match QueryAirport::insert(query_airport) {
|
||||
Ok(a) => HttpResponse::Created().json(a),
|
||||
Ok(a) => {
|
||||
let airport: Airport = a.into();
|
||||
HttpResponse::Ok().json(airport)
|
||||
},
|
||||
Err(err) => {
|
||||
error!("{}", err);
|
||||
err.to_http_response()
|
||||
@@ -155,7 +168,10 @@ async fn update(icao: web::Path<String>, airport: web::Json<Airport>, auth: JwtA
|
||||
};
|
||||
let query_airport: QueryAirport = airport.into_inner().into();
|
||||
match QueryAirport::update(icao.into_inner(), query_airport) {
|
||||
Ok(a) => HttpResponse::Ok().json(a),
|
||||
Ok(a) => {
|
||||
let airport: Airport = a.into();
|
||||
HttpResponse::Ok().json(airport)
|
||||
},
|
||||
Err(err) => {
|
||||
error!("{}", err);
|
||||
err.to_http_response()
|
||||
|
||||
@@ -8,10 +8,15 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct QualityControlFlags {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auto: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auto_station_without_precipication: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub auto_station_with_precipication: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub maintenance_indicator_on: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub corrected: Option<bool>
|
||||
}
|
||||
|
||||
@@ -30,6 +35,7 @@ impl Default for QualityControlFlags {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SkyCondition {
|
||||
pub sky_cover: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub cloud_base_ft_agl: Option<i32>
|
||||
}
|
||||
|
||||
@@ -45,8 +51,11 @@ impl Default for SkyCondition {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct RunwayVisualRange {
|
||||
pub runway: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub visibility_ft: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub variable_visibility_high_ft: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub variable_visibility_low_ft: Option<String>
|
||||
}
|
||||
|
||||
@@ -75,23 +84,36 @@ pub struct Metar {
|
||||
pub raw_text: String,
|
||||
pub station_id: String,
|
||||
pub observation_time: chrono::NaiveDateTime,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub temp_c: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub dewpoint_c: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wind_dir_degrees: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wind_speed_kt: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wind_gust_kt: Option<i32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub variable_wind_dir_degrees: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub visibility_statute_mi: Option<String>,
|
||||
pub runway_visual_range: Vec<RunwayVisualRange>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub altim_in_hg: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sea_level_pressure_mb: Option<f64>,
|
||||
pub quality_control_flags: QualityControlFlags,
|
||||
pub weather_phenomena: Vec<String>,
|
||||
pub sky_condition: Vec<SkyCondition>,
|
||||
pub flight_category: FlightCategory,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub three_hr_pressure_tendency_mb: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max_t_c: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub min_t_c: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub precip_in: Option<f64>,
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export interface Metar {
|
||||
sky_condition: SkyCondition[];
|
||||
flight_category: 'VFR' | 'MVFR' | 'LIFR' | 'IFR' | 'UNKN';
|
||||
three_hr_pressure_tendency_mb: number;
|
||||
maxT_c: number;
|
||||
minT_c: number;
|
||||
max_t_c: number;
|
||||
min_t_c: number;
|
||||
precip_in: number;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export default function MapTiles() {
|
||||
}
|
||||
|
||||
function metarIcon(airport: Airport) {
|
||||
function innerIcon({ tag, color, size = 'sm' }: { tag: string; color: string; size?: string }) {
|
||||
function innerIcon({ tag, color, size = 'xs' }: { tag: string; color: string; size?: string }) {
|
||||
return new DivIcon({
|
||||
html: ReactDOMServer.renderToString(
|
||||
<MantineProvider>
|
||||
|
||||
@@ -48,7 +48,13 @@ export default function MetarModal({ airport, isOpen, onClose }: MetarModalProps
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal opened={isOpen} onClose={onClose} withCloseButton={false} size={'50%'} className='modal'>
|
||||
<Modal
|
||||
opened={isOpen}
|
||||
onClose={onClose}
|
||||
withCloseButton={false}
|
||||
size={'50%'}
|
||||
className='modal'
|
||||
>
|
||||
<span className='title'>
|
||||
<Link href={`/airport/${airport.icao}`}>
|
||||
{airport.icao} {airport.full_name}
|
||||
@@ -163,13 +169,14 @@ function MetarInfo({ metar }: { metar: Metar }) {
|
||||
</Grid>
|
||||
</Grid.Col>
|
||||
<Grid.Col className='gutter-row' span={12}>
|
||||
<Grid style={{ paddingTop: '1em', paddingBottom: '1em' }} gutter={48}>
|
||||
{metar.weather_phenomena &&
|
||||
metar.weather_phenomena.map((wx) => (
|
||||
<Grid.Col span={1}>
|
||||
<MetarIcon wx={wx} />
|
||||
</Grid.Col>
|
||||
))}
|
||||
<Grid gutter={18}>
|
||||
<Grid.Col className='gutter-row' span={12}>
|
||||
<Card shadow='sm' padding='sm' radius='md' style={{ textAlign: 'center' }}>
|
||||
<Card.Section>
|
||||
|
||||
</Card.Section>
|
||||
</Card>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Grid.Col>
|
||||
</Grid.Col>
|
||||
|
||||
Reference in New Issue
Block a user