diff --git a/Cargo.lock b/Cargo.lock index 2b45361..0976151 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -387,6 +387,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-link 0.1.3", ] @@ -1813,6 +1814,7 @@ dependencies = [ "dotenvy", "reqwest", "serde", + "serde_json", "sqlx", ] diff --git a/Cargo.toml b/Cargo.toml index c767a0a..0aacf7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,9 @@ edition = "2024" [dependencies] actix-web = "4.11.0" -chrono = "0.4.41" +chrono = {version = "0.4.41", features=["serde"]} dotenvy = "0.15.7" reqwest = { version = "0.12.23", features=["json"]} serde = { version = "1.0.219", features = ["derive"] } +serde_json = "1.0.143" sqlx = { version = "0.8.6", features = ["runtime-tokio-rustls", "postgres", "chrono", "uuid"] } diff --git a/src/models.rs b/src/models.rs index 31a188f..981c19a 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,5 +1,6 @@ +use chrono::NaiveDate; use serde::Serialize; -use sqlx::FromRow; +use sqlx::FromRow; // 处理日期类型 #[derive(Debug, Serialize, FromRow)] pub struct User { @@ -17,4 +18,45 @@ pub struct User { #[serde(rename = "desc")] #[sqlx(rename = "desc")] pub description: Option, -} \ No newline at end of file +} + +#[derive(Debug, Serialize, FromRow)] +pub struct WeatherData { + pub id: i32, + pub user_id: i32, + pub title: Option, + #[serde(rename = "date")] + #[sqlx(rename = "date")] + pub record_date: Option, // 避免与关键字冲突 + pub hour: Option, + pub min: Option, + pub longitude: Option, + pub latitude: Option, + pub daysincejanfirst: Option, + pub theta: Option, + pub solardeclination: Option, + pub sunaltitude: Option, + pub overallcloudiness: Option, + pub lowcloudiness: Option, + pub cloudindex: Option, + pub solarradiationlevel: Option, + pub hasmeasuredwindspeed: Option, + pub measuredwindspeed: Option, + pub convertedwindspeed: Option, + pub measurementheight: Option, + pub areatype: Option, + pub pointwindspeed: Option, + pub atmosphericstability: Option, + pub suitabilitydegree: Option, + pub winddirection: Option, // JSONB类型 + pub averagewinddirection: Option, + pub winddirectionstandarddeviation: Option, + pub windspeed: Option, // JSONB类型 + pub averagewindspeed: Option, + pub windspeedsuitability: Option, + pub winddirectionsuitability: Option, + pub overallsuitability: Option, + pub inspectiontype: Option, + pub assignmentnumber: Option, + pub calculatedwindspeed: Option, +}