Filter on airport category
This commit is contained in:
@@ -41,9 +41,22 @@ pub struct Airports {
|
||||
}
|
||||
|
||||
impl Airports {
|
||||
pub fn find_all(bounds: Option<Polygon<Point>>, limit: i32, page: i32) -> Result<Vec<Self>, CustomError> {
|
||||
pub fn find_all(bounds: Option<Polygon<Point>>, category: Option<String>, limit: i32, page: i32) -> Result<Vec<Self>, CustomError> {
|
||||
let mut conn = db::connection()?;
|
||||
let airports = airports::table
|
||||
let airports;
|
||||
if let Some(category) = category {
|
||||
airports = airports::table
|
||||
.limit(limit as i64)
|
||||
.filter(airports::id.gt(page * limit).and(match bounds {
|
||||
Some(b) => st_contains(b, airports::point),
|
||||
None => {
|
||||
let polygon: Polygon<Point> = Polygon::new(Some(4326));
|
||||
st_contains(polygon, airports::point)
|
||||
}
|
||||
}).and(airports::category.eq(category))).load::<Airports>(&mut conn)?;
|
||||
} else {
|
||||
airports = airports::table
|
||||
.order(airports::category.asc())
|
||||
.limit(limit as i64)
|
||||
.filter(airports::id.gt(page * limit).and(match bounds {
|
||||
Some(b) => st_contains(b, airports::point),
|
||||
@@ -53,6 +66,7 @@ impl Airports {
|
||||
}
|
||||
}))
|
||||
.load::<Airports>(&mut conn)?;
|
||||
}
|
||||
Ok(airports)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ struct FindAllParams {
|
||||
ne_lon: f64,
|
||||
sw_lat: f64,
|
||||
sw_lon: f64,
|
||||
category: Option<String>,
|
||||
limit: i32,
|
||||
page: i32
|
||||
}
|
||||
@@ -36,7 +37,12 @@ async fn find_all(req: HttpRequest) -> HttpResponse {
|
||||
polygon.add_point(Point { x: params.ne_lon, y: params.ne_lat, srid: Some(4326) });
|
||||
polygon.add_point(Point { x: params.sw_lon, y: params.ne_lat, srid: Some(4326) });
|
||||
polygon.add_point(Point { x: params.sw_lon, y: params.sw_lat, srid: Some(4326) });
|
||||
match web::block(move || Airports::find_all(Some(polygon), params.limit, params.page)).await.unwrap() {
|
||||
let category = match ¶ms.category {
|
||||
Some(c) => Some(c.to_string()),
|
||||
None => None
|
||||
};
|
||||
|
||||
match web::block(move || Airports::find_all(Some(polygon), category, params.limit, params.page)).await.unwrap() {
|
||||
Ok(a) => HttpResponse::Ok().json(a),
|
||||
Err(err) => {
|
||||
error!("{}", err);
|
||||
|
||||
@@ -150,6 +150,7 @@ impl Metars {
|
||||
Ok(m) => m,
|
||||
Err(err) => return Err(CustomError { error_status_code: 500, error_message: format!("{}", err) })
|
||||
};
|
||||
|
||||
fn get_missing_metar_icaos(db_metars: &Vec<Metars>, station_icaos: Vec<&str>) -> Vec<String> {
|
||||
let mut missing_metar_icaos: Vec<String> = vec![];
|
||||
let current_time = chrono::Local::now().naive_local().timestamp();
|
||||
|
||||
@@ -18,7 +18,6 @@ export default function Map() {
|
||||
zoom={8}
|
||||
maxZoom={12}
|
||||
minZoom={1}
|
||||
zoomControl={false}
|
||||
style={{ height: '96.5vh' }}
|
||||
className='overflow-y-hidden overflow-x-hidden'
|
||||
attributionControl={false}
|
||||
@@ -35,8 +34,9 @@ function MapTiles() {
|
||||
const map = useMap();
|
||||
|
||||
const mapEvents = useMapEvents({
|
||||
zoomend: () => {
|
||||
zoomend: async () => {
|
||||
setZoomLevel(mapEvents.getZoom());
|
||||
await updateAirports(mapEvents.getBounds());
|
||||
},
|
||||
movestart: () => {
|
||||
// setDragging(true);
|
||||
@@ -51,10 +51,10 @@ function MapTiles() {
|
||||
const ne = bounds.getNorthEast();
|
||||
const sw = bounds.getSouthWest();
|
||||
const _airports = await getAirports({
|
||||
ne_lat: ne.lat,
|
||||
ne_lon: ne.lng,
|
||||
sw_lat: sw.lat,
|
||||
sw_lon: sw.lng,
|
||||
bounds: {
|
||||
northEast: { lat: ne.lat, lon: ne.lng },
|
||||
southWest: { lat: sw.lat, lon: sw.lng }
|
||||
},
|
||||
limit: 100,
|
||||
page: 1
|
||||
});
|
||||
|
||||
@@ -2,14 +2,22 @@ import axios from 'axios';
|
||||
import { Airport } from './airport.types';
|
||||
|
||||
interface GetAirportsProps {
|
||||
ne_lat: number;
|
||||
ne_lon: number;
|
||||
sw_lat: number;
|
||||
sw_lon: number;
|
||||
bounds?: Bounds;
|
||||
category?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export interface Bounds {
|
||||
northEast: Coordinate;
|
||||
southWest: Coordinate;
|
||||
}
|
||||
|
||||
export interface Coordinate {
|
||||
lat: number;
|
||||
lon: number;
|
||||
}
|
||||
|
||||
interface GetAirportProps {
|
||||
icao: string;
|
||||
}
|
||||
@@ -19,16 +27,19 @@ export async function getAirport({ icao }: GetAirportProps) {
|
||||
return response?.data;
|
||||
}
|
||||
|
||||
export async function getAirports({
|
||||
ne_lat,
|
||||
ne_lon,
|
||||
sw_lat,
|
||||
sw_lon,
|
||||
limit = 10,
|
||||
page = 1
|
||||
}: GetAirportsProps): Promise<Airport[]> {
|
||||
export async function getAirports({ bounds, category, limit = 10, page = 1 }: GetAirportsProps): Promise<Airport[]> {
|
||||
const response = await axios
|
||||
.get(`http://localhost:5000/airports`, { params: { ne_lat, ne_lon, sw_lat, sw_lon, limit, page } })
|
||||
.get(`http://localhost:5000/airports`, {
|
||||
params: {
|
||||
ne_lat: bounds?.northEast.lat,
|
||||
ne_lon: bounds?.northEast.lon,
|
||||
sw_lat: bounds?.southWest.lat,
|
||||
sw_lon: bounds?.southWest.lon,
|
||||
category,
|
||||
limit,
|
||||
page
|
||||
}
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
return response?.data || [];
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { Metar } from './metar.types';
|
||||
|
||||
export enum AirportCategory {
|
||||
SMALL = 'small_airport',
|
||||
MEDIUM = 'medium_airport',
|
||||
LARGE = 'large_airport'
|
||||
}
|
||||
|
||||
export interface Airport {
|
||||
icao: string;
|
||||
category: string;
|
||||
category: AirportCategory;
|
||||
full_name: string;
|
||||
elevation_ft: string;
|
||||
continent: string;
|
||||
|
||||
Reference in New Issue
Block a user