fix: 修复多处代码质量问题-移除unwrap/println/dead-code/重复代码/错误吞咽

This commit is contained in:
2026-05-11 13:38:41 +08:00
parent 0cba52f545
commit 061c2bbb5a
7 changed files with 74 additions and 117 deletions

View File

@@ -11,7 +11,7 @@ use crate::error::AppError;
pub async fn insert_weather_data(pool: &PgPool, weather_data: &WeatherData, user_id: i32) -> Result<i32, AppError> {
// 配额检查:非付费用户数据条数限制
let user = get_user_by_id(pool, user_id).await?;
let is_paid_active = user.is_paid && (user.paid_expires_at.is_none() || user.paid_expires_at.unwrap() > Utc::now());
let is_paid_active = user.is_paid && user.paid_expires_at.map_or(true, |expires| expires > Utc::now());
if !is_paid_active {
let current_count = count_user_weather_data(pool, user_id).await?;
@@ -490,8 +490,7 @@ pub async fn get_user_quota(
) -> Result<(i64, bool, Option<chrono::DateTime<chrono::Utc>>), AppError> {
let user = get_user_by_id(pool, user_id).await?;
let is_paid_active = user.is_paid
&& (user.paid_expires_at.is_none()
|| user.paid_expires_at.unwrap() > chrono::Utc::now());
&& user.paid_expires_at.map_or(true, |expires| expires > chrono::Utc::now());
let used = count_user_weather_data(pool, user_id).await?;
Ok((used, is_paid_active, user.paid_expires_at))
}