clean code with clippy
Some checks are pending
CI/CD Pipeline / test (push) Waiting to run
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions

This commit is contained in:
2024-05-22 00:13:23 +02:00
parent 6b911f242a
commit 40f97f18a9
11 changed files with 151 additions and 124 deletions

View File

@ -2,7 +2,7 @@ use chrono::{DateTime, FixedOffset, NaiveDate, NaiveTime};
use serde::{Deserialize, Serialize};
use sqlx::SqlitePool;
use crate::model::waterlevel::Waterlevel;
use crate::model::waterlevel::{self, Waterlevel};
pub async fn update(db: &SqlitePool) -> Result<(), String> {
let mut tx = db.begin().await.unwrap();
@ -29,10 +29,18 @@ pub async fn update(db: &SqlitePool) -> Result<(), String> {
let time: NaiveTime = datetime.naive_utc().time();
let time_str = time.format("%H:%M").to_string();
Waterlevel::create(
&mut tx, date, time_str, max, min, mittel, tumax, tumin, tumittel,
)
.await?
let create = waterlevel::Create {
day: date,
time: time_str,
max,
min,
mittel,
tumax,
tumin,
tumittel,
};
Waterlevel::create(&mut tx, &create).await?
}
// 3. Save in DB
@ -77,25 +85,23 @@ fn fetch() -> Result<Station, String> {
if let Ok(data) = forecast {
if data.len() == 1 {
return Ok(data[0].clone());
Ok(data[0].clone())
} else {
return Err(format!(
Err(format!(
"Expected 1 station (Linz); got {} while fetching from {url}. Maybe the hydro data format changed?",
data.len()
));
))
}
} else {
return Err(format!(
Err(format!(
"Failed to parse the json received by {url}: {}",
forecast.err().unwrap()
));
))
}
}
Err(_) => {
return Err(format!(
"Could not fetch {url}, do you have internet? Maybe their server is down?"
));
}
Err(_) => Err(format!(
"Could not fetch {url}, do you have internet? Maybe their server is down?"
)),
}
}

View File

@ -103,18 +103,16 @@ fn fetch(api_key: &str) -> Result<Data, String> {
let data: Result<Data, _> = response.into_json();
if let Ok(data) = data {
return Ok(data);
Ok(data)
} else {
return Err(format!(
Err(format!(
"Failed to parse the json received by {url}: {}",
data.err().unwrap()
));
))
}
}
Err(_) => {
return Err(format!(
"Could not fetch {url}, do you have internet? Maybe their server is down?"
));
}
Err(_) => Err(format!(
"Could not fetch {url}, do you have internet? Maybe their server is down?"
)),
}
}