clippy
This commit is contained in:
parent
2f5129c325
commit
0228cec056
@ -45,16 +45,14 @@ impl Station {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn login(db: &SqlitePool, id: i64, code: &str) -> Option<Self> {
|
pub async fn login(db: &SqlitePool, id: i64, code: &str) -> Option<Self> {
|
||||||
let Some(station) = sqlx::query_as!(
|
let station = sqlx::query_as!(
|
||||||
Self,
|
Self,
|
||||||
"SELECT id, name, notes, amount_people, last_login, pw, lat, lng FROM station WHERE id = ? AND pw = ?",
|
"SELECT id, name, notes, amount_people, last_login, pw, lat, lng FROM station WHERE id = ? AND pw = ?",
|
||||||
id, code
|
id, code
|
||||||
)
|
)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await
|
.await
|
||||||
.ok() else {
|
.ok()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"UPDATE station SET last_login = CURRENT_TIMESTAMP WHERE id = ?",
|
"UPDATE station SET last_login = CURRENT_TIMESTAMP WHERE id = ?",
|
||||||
@ -80,13 +78,13 @@ impl Station {
|
|||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
team: &Team,
|
team: &Team,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let teams = TeamsAtStationLocation::for_station(db, &self).await;
|
let teams = TeamsAtStationLocation::for_station(db, self).await;
|
||||||
|
|
||||||
if !teams.not_yet_here.contains(team) {
|
if !teams.not_yet_here.contains(team) {
|
||||||
return Err(format!("Kann Team nicht der Warteschlange hinzufügen, weil das Team {} nicht zu deiner Station kommen soll.", team.name));
|
return Err(format!("Kann Team nicht der Warteschlange hinzufügen, weil das Team {} nicht zu deiner Station kommen soll.", team.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rating::create(db, &self, team).await?;
|
Rating::create(db, self, team).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -96,7 +94,7 @@ impl Station {
|
|||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
team: &Team,
|
team: &Team,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let teams = TeamsAtStationLocation::for_station(db, &self).await;
|
let teams = TeamsAtStationLocation::for_station(db, self).await;
|
||||||
|
|
||||||
let waiting_teams: Vec<&Team> = teams.waiting.iter().map(|(team, _)| team).collect();
|
let waiting_teams: Vec<&Team> = teams.waiting.iter().map(|(team, _)| team).collect();
|
||||||
|
|
||||||
@ -104,13 +102,13 @@ impl Station {
|
|||||||
return Err(format!("Kann Team nicht von der Warteschlange gelöscht werden, weil das Team {} nicht in der Warteschlange ist.", team.name));
|
return Err(format!("Kann Team nicht von der Warteschlange gelöscht werden, weil das Team {} nicht in der Warteschlange ist.", team.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rating::delete(db, &self, team).await?;
|
Rating::delete(db, self, team).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn team_starting(&self, db: &SqlitePool, team: &Team) -> Result<(), String> {
|
pub(crate) async fn team_starting(&self, db: &SqlitePool, team: &Team) -> Result<(), String> {
|
||||||
let teams = TeamsAtStationLocation::for_station(db, &self).await;
|
let teams = TeamsAtStationLocation::for_station(db, self).await;
|
||||||
|
|
||||||
let waiting_teams: Vec<&Team> = teams.waiting.iter().map(|(team, _)| team).collect();
|
let waiting_teams: Vec<&Team> = teams.waiting.iter().map(|(team, _)| team).collect();
|
||||||
|
|
||||||
@ -138,7 +136,7 @@ impl Station {
|
|||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
team: &Team,
|
team: &Team,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let teams = TeamsAtStationLocation::for_station(db, &self).await;
|
let teams = TeamsAtStationLocation::for_station(db, self).await;
|
||||||
|
|
||||||
let doing_teams: Vec<&Team> = teams.doing.iter().map(|(team, _)| team).collect();
|
let doing_teams: Vec<&Team> = teams.doing.iter().map(|(team, _)| team).collect();
|
||||||
|
|
||||||
@ -162,7 +160,7 @@ impl Station {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn team_finished(&self, db: &SqlitePool, team: &Team) -> Result<(), String> {
|
pub(crate) async fn team_finished(&self, db: &SqlitePool, team: &Team) -> Result<(), String> {
|
||||||
let teams = TeamsAtStationLocation::for_station(db, &self).await;
|
let teams = TeamsAtStationLocation::for_station(db, self).await;
|
||||||
|
|
||||||
let doing_teams: Vec<&Team> = teams.doing.iter().map(|(team, _)| team).collect();
|
let doing_teams: Vec<&Team> = teams.doing.iter().map(|(team, _)| team).collect();
|
||||||
|
|
||||||
@ -190,7 +188,7 @@ impl Station {
|
|||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
team: &Team,
|
team: &Team,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let teams = TeamsAtStationLocation::for_station(db, &self).await;
|
let teams = TeamsAtStationLocation::for_station(db, self).await;
|
||||||
|
|
||||||
let left_teams: Vec<&Team> = teams.left.iter().map(|(team, _)| team).collect();
|
let left_teams: Vec<&Team> = teams.left.iter().map(|(team, _)| team).collect();
|
||||||
|
|
||||||
@ -307,7 +305,7 @@ impl Station {
|
|||||||
let Some(last_login) = &self.last_login else {
|
let Some(last_login) = &self.last_login else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(last_login.clone(), Utc);
|
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(*last_login, Utc);
|
||||||
Some(datetime_utc.with_timezone(&Local))
|
Some(datetime_utc.with_timezone(&Local))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,16 +45,6 @@ impl Rating {
|
|||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub(crate) async fn all_with_station(db: &SqlitePool, station: &Station) -> Vec<Self> {
|
|
||||||
sqlx::query_as::<_, Self>(
|
|
||||||
"SELECT team_id, station_id, points, notes, arrived_at, started_at, left_at FROM rating WHERE station_id = ?;",
|
|
||||||
)
|
|
||||||
.bind(station.id)
|
|
||||||
.fetch_all(db)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_team_and_station(
|
pub async fn find_by_team_and_station(
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
team: &Team,
|
team: &Team,
|
||||||
@ -67,7 +57,7 @@ impl Rating {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn local_time_arrived_at(&self) -> String {
|
pub(crate) fn local_time_arrived_at(&self) -> String {
|
||||||
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(self.arrived_at.clone(), Utc);
|
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(self.arrived_at, Utc);
|
||||||
let datetime_local = datetime_utc.with_timezone(&Local);
|
let datetime_local = datetime_utc.with_timezone(&Local);
|
||||||
|
|
||||||
datetime_local.format("%H:%M").to_string()
|
datetime_local.format("%H:%M").to_string()
|
||||||
@ -76,7 +66,7 @@ impl Rating {
|
|||||||
let Some(started_at) = self.started_at else {
|
let Some(started_at) = self.started_at else {
|
||||||
return String::from("noch nicht gestartet");
|
return String::from("noch nicht gestartet");
|
||||||
};
|
};
|
||||||
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(started_at.clone(), Utc);
|
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(started_at, Utc);
|
||||||
let datetime_local = datetime_utc.with_timezone(&Local);
|
let datetime_local = datetime_utc.with_timezone(&Local);
|
||||||
|
|
||||||
datetime_local.format("%H:%M").to_string()
|
datetime_local.format("%H:%M").to_string()
|
||||||
@ -86,7 +76,7 @@ impl Rating {
|
|||||||
let Some(left_at) = self.left_at else {
|
let Some(left_at) = self.left_at else {
|
||||||
return String::from("noch nicht fertig");
|
return String::from("noch nicht fertig");
|
||||||
};
|
};
|
||||||
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(left_at.clone(), Utc);
|
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(left_at, Utc);
|
||||||
let datetime_local = datetime_utc.with_timezone(&Local);
|
let datetime_local = datetime_utc.with_timezone(&Local);
|
||||||
|
|
||||||
datetime_local.format("%H:%M").to_string()
|
datetime_local.format("%H:%M").to_string()
|
||||||
@ -103,7 +93,7 @@ pub(crate) struct TeamsAtStationLocation {
|
|||||||
|
|
||||||
impl TeamsAtStationLocation {
|
impl TeamsAtStationLocation {
|
||||||
pub(crate) async fn for_station(db: &SqlitePool, station: &Station) -> TeamsAtStationLocation {
|
pub(crate) async fn for_station(db: &SqlitePool, station: &Station) -> TeamsAtStationLocation {
|
||||||
let teams = station.teams(&db).await;
|
let teams = station.teams(db).await;
|
||||||
let total_teams = teams.len() as i64;
|
let total_teams = teams.len() as i64;
|
||||||
|
|
||||||
let mut not_yet_here = Vec::new();
|
let mut not_yet_here = Vec::new();
|
||||||
@ -112,7 +102,7 @@ impl TeamsAtStationLocation {
|
|||||||
let mut left = Vec::new();
|
let mut left = Vec::new();
|
||||||
|
|
||||||
for team in teams {
|
for team in teams {
|
||||||
match Rating::find_by_team_and_station(db, &team, &station).await {
|
match Rating::find_by_team_and_station(db, &team, station).await {
|
||||||
Some(rating) => {
|
Some(rating) => {
|
||||||
if rating.left_at.is_some() {
|
if rating.left_at.is_some() {
|
||||||
left.push((team, rating));
|
left.push((team, rating));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user