fix: 修复多处代码质量问题-移除unwrap/println/dead-code/重复代码/错误吞咽
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user