Working on fixing metars, airport layout, etc

This commit is contained in:
2025-06-02 16:54:53 -04:00
parent 7dedc7a8dc
commit 263c33fd5a
24 changed files with 691 additions and 510 deletions

View File

@@ -0,0 +1,67 @@
use serde::Deserialize;
use crate::db;
use crate::error::ApiResult;
const TABLE_NAME: &str = "user_airport_favorites";
#[derive(Debug, Deserialize, sqlx::FromRow)]
pub struct UserFavorite {
pub username: String,
pub icao: String,
}
impl UserFavorite {
pub async fn select_all(username: &str) -> ApiResult<Vec<String>> {
let pool = db::pool();
let user_favorites: Vec<UserFavorite> = sqlx::query_as::<_, UserFavorite>(&format!(
r#"
SELECT * FROM {} WHERE username = $1
"#,
TABLE_NAME
))
.bind(username)
.fetch_all(pool)
.await?;
let favorites = user_favorites
.iter()
.map(|uf| uf.icao.clone())
.collect();
Ok(favorites)
}
pub async fn insert(username: &str, icao: &str) -> ApiResult<()> {
let pool = db::pool();
sqlx::query(&format!(
r#"
INSERT INTO {} (
username, icao
) VALUES ($1, $2)
"#,
TABLE_NAME
))
.bind(username)
.bind(icao)
.execute(pool)
.await?;
Ok(())
}
pub async fn delete(username: &str, icao: &str) -> ApiResult<()> {
let pool = db::pool();
sqlx::query(&format!(
r#"
DELETE FROM {} WHERE username = $1 AND icao = $2
"#,
TABLE_NAME
))
.bind(username)
.bind(icao)
.execute(pool)
.await?;
Ok(())
}
}