Working on emails, updated swagger, added geometry column to airports
This commit is contained in:
@@ -15,6 +15,9 @@ use std::str::FromStr;
|
||||
use utoipa::{IntoParams, ToSchema};
|
||||
|
||||
const TABLE_NAME: &str = "airports";
|
||||
const DEFAULT_COLUMNS: &str = "icao, iata, local, name, category, iso_country, \
|
||||
iso_region, municipality, elevation_ft, longitude, latitude, has_tower, has_beacon,\
|
||||
public, metar_observation_time";
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct Airport {
|
||||
@@ -209,10 +212,13 @@ impl Airport {
|
||||
let pool = db::pool();
|
||||
|
||||
let airport_fut = async {
|
||||
sqlx::query_as(&format!("SELECT * FROM {} WHERE icao = $1", TABLE_NAME))
|
||||
.bind(icao)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
sqlx::query_as(&format!(
|
||||
"SELECT {} FROM {} WHERE icao = $1",
|
||||
DEFAULT_COLUMNS, TABLE_NAME
|
||||
))
|
||||
.bind(icao)
|
||||
.fetch_optional(pool)
|
||||
.await
|
||||
};
|
||||
|
||||
let metar_fut = async {
|
||||
@@ -283,8 +289,8 @@ impl Airport {
|
||||
pub async fn select_all(client: &Client, query: &AirportQuery) -> ApiResult<Vec<Self>> {
|
||||
let pool = db::pool();
|
||||
|
||||
let mut builder = QueryBuilder::<Postgres>::new("SELECT * FROM ");
|
||||
builder.push(TABLE_NAME);
|
||||
let mut builder =
|
||||
QueryBuilder::<Postgres>::new(format!("SELECT {} FROM {}", DEFAULT_COLUMNS, TABLE_NAME));
|
||||
|
||||
let mut has_where = false;
|
||||
Self::push_condition_array(&mut builder, &mut has_where, "icao", &query.icaos);
|
||||
@@ -445,15 +451,17 @@ impl Airport {
|
||||
r#"
|
||||
INSERT INTO {} (
|
||||
icao, iata, local, name, category, iso_country, iso_region, municipality,
|
||||
elevation_ft, longitude, latitude, has_tower, has_beacon, public
|
||||
elevation_ft, longitude, latitude, geometry, has_tower, has_beacon, public
|
||||
)
|
||||
VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7,
|
||||
$8, $9, $10, $11, $12, $13, $14
|
||||
$1, $2, $3, $4, $5, $6, $7, $8,
|
||||
$9, $10, $11,
|
||||
ST_SetSRID(ST_MakePoint($10, $11), 4326),
|
||||
$12, $13, $14
|
||||
)
|
||||
RETURNING *
|
||||
RETURNING {}
|
||||
"#,
|
||||
TABLE_NAME,
|
||||
TABLE_NAME, DEFAULT_COLUMNS
|
||||
))
|
||||
.bind(self.icao.to_string())
|
||||
.bind(&self.iata)
|
||||
@@ -497,7 +505,7 @@ impl Airport {
|
||||
let mut query_builder: QueryBuilder<Postgres> = QueryBuilder::new(
|
||||
"INSERT INTO airports (icao, iata, local, name, category, \
|
||||
iso_country, iso_region, municipality, elevation_ft, \
|
||||
longitude, latitude, has_tower, has_beacon, public) ",
|
||||
longitude, latitude, geometry, has_tower, has_beacon, public) ",
|
||||
);
|
||||
query_builder.push_values(chunk, |mut b, row| {
|
||||
b.push_bind(&row.icao)
|
||||
@@ -511,6 +519,11 @@ impl Airport {
|
||||
.push_bind(row.elevation_ft)
|
||||
.push_bind(row.longitude)
|
||||
.push_bind(row.latitude)
|
||||
.push_unseparated(", ST_SetSRID(ST_MakePoint(")
|
||||
.push_bind_unseparated(row.longitude)
|
||||
.push_unseparated(", ")
|
||||
.push_bind_unseparated(row.latitude)
|
||||
.push_unseparated("), 4326)")
|
||||
.push_bind(row.has_tower)
|
||||
.push_bind(row.has_beacon)
|
||||
.push_bind(row.public);
|
||||
@@ -641,15 +654,15 @@ impl Airport {
|
||||
let bounds = Bounds::parse(bounds_string)?;
|
||||
builder
|
||||
.push("(")
|
||||
.push("latitude BETWEEN ")
|
||||
.push_bind(bounds.south_west_lat)
|
||||
.push(" AND ")
|
||||
.push_bind(bounds.north_east_lat)
|
||||
.push(" AND ")
|
||||
.push("longitude BETWEEN ")
|
||||
.push("geometry && ST_MakeEnvelope(")
|
||||
.push_bind(bounds.south_west_lon)
|
||||
.push(" AND ")
|
||||
.push(", ")
|
||||
.push_bind(bounds.south_west_lat)
|
||||
.push(", ")
|
||||
.push_bind(bounds.north_east_lon)
|
||||
.push(", ")
|
||||
.push_bind(bounds.north_east_lat)
|
||||
.push(", 4326)")
|
||||
.push(")");
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user