根据前端上传数据的修改,修正了相关代码
This commit is contained in:
@@ -133,15 +133,14 @@ pub struct WeatherListResponse {
|
||||
}
|
||||
|
||||
// 天气数据结构体(修改后)
|
||||
#[derive(Debug, Deserialize, Serialize, FromRow)] // 添加 FromRow 派生
|
||||
#[derive(Debug, Deserialize, Serialize, FromRow)]
|
||||
pub struct WeatherData {
|
||||
// 添加 id 字段(数据库中应该有这个主键)
|
||||
#[serde(skip_deserializing)] // 1. 反序列化时忽略该字段;
|
||||
#[sqlx(rename = "id")] // 数据库表的 id 列(自增主键),查询映射时使用
|
||||
#[serde(skip_deserializing)]
|
||||
#[sqlx(rename = "id")]
|
||||
pub id: i32,
|
||||
|
||||
#[serde(rename = "areaType")]
|
||||
#[sqlx(rename = "areatype")] // 数据库列名是小写下划线式
|
||||
#[sqlx(rename = "areatype")]
|
||||
pub area_type: String,
|
||||
|
||||
#[serde(rename = "assignmentnumber")]
|
||||
@@ -162,15 +161,18 @@ pub struct WeatherData {
|
||||
|
||||
#[serde(rename = "calculatedwindspeed")]
|
||||
#[sqlx(rename = "calculatedwindspeed")]
|
||||
pub calculated_wind_speed: Option<f64>,
|
||||
pub calculated_wind_speed: Option<f64>, // 这个已经是 Option,很好
|
||||
|
||||
#[serde(rename = "cloudIndex")]
|
||||
#[sqlx(rename = "cloudindex")]
|
||||
pub cloud_index: String,
|
||||
|
||||
// --- 以下是修改的重点 ---
|
||||
// 这些字段在前端是条件性发送的,因此在 Rust 中也必须是可选的
|
||||
|
||||
#[serde(rename = "convertedWindSpeed")]
|
||||
#[sqlx(rename = "convertedwindspeed")]
|
||||
pub converted_wind_speed: i32,
|
||||
pub converted_wind_speed: Option<i32>, // <-- 修改: i32 -> Option<i32>
|
||||
|
||||
pub date: NaiveDate,
|
||||
|
||||
@@ -187,7 +189,7 @@ pub struct WeatherData {
|
||||
pub has_spot_check_wind_speed: bool,
|
||||
|
||||
#[serde(rename = "hours")]
|
||||
#[sqlx(rename = "hour")] // 数据库中是 hour 字段
|
||||
#[sqlx(rename = "hour")]
|
||||
pub hours: i32,
|
||||
|
||||
#[serde(rename = "inspectiontype")]
|
||||
@@ -203,11 +205,11 @@ pub struct WeatherData {
|
||||
|
||||
#[serde(rename = "measuredWindSpeed")]
|
||||
#[sqlx(rename = "measuredwindspeed")]
|
||||
pub measured_wind_speed: f64,
|
||||
pub measured_wind_speed: Option<f64>, // <-- 修改: f64 -> Option<f64>
|
||||
|
||||
#[serde(rename = "measurementHeight")]
|
||||
#[sqlx(rename = "measurementheight")]
|
||||
pub measurement_height: f64,
|
||||
pub measurement_height: Option<f64>, // <-- 修改: f64 -> Option<f64>
|
||||
|
||||
#[serde(rename = "min")]
|
||||
#[sqlx(rename = "min")]
|
||||
@@ -225,7 +227,7 @@ pub struct WeatherData {
|
||||
|
||||
#[serde(rename = "pointWindSpeed")]
|
||||
#[sqlx(rename = "pointwindspeed")]
|
||||
pub point_wind_speed: f64,
|
||||
pub point_wind_speed: Option<f64>, // <-- 修改: f64 -> Option<f64>
|
||||
|
||||
#[serde(rename = "solarDeclination")]
|
||||
#[sqlx(rename = "solardeclination")]
|
||||
|
||||
Reference in New Issue
Block a user