Compare commits
No commits in common. "7c8f20623c1411dd3ab6cdaffc68fda8fbfacf4e" and "073b2aca0438856ea960c7961419a3840b5b24d0" have entirely different histories.
7c8f20623c
...
073b2aca04
@ -343,14 +343,6 @@ ORDER BY amount_seats DESC
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn owner(&self, db: &SqlitePool) -> Option<User> {
|
|
||||||
if let Some(owner_id) = self.owner {
|
|
||||||
Some(User::find_by_id(db, owner_id as i32).await.unwrap())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete(&self, db: &SqlitePool) {
|
pub async fn delete(&self, db: &SqlitePool) {
|
||||||
sqlx::query!("DELETE FROM boat WHERE id=?", self.id)
|
sqlx::query!("DELETE FROM boat WHERE id=?", self.id)
|
||||||
.execute(db)
|
.execute(db)
|
||||||
|
@ -5,8 +5,6 @@ use chrono::Datelike;
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sqlx::{FromRow, Row, SqlitePool};
|
use sqlx::{FromRow, Row, SqlitePool};
|
||||||
|
|
||||||
use super::boat::Boat;
|
|
||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone)]
|
||||||
pub struct BoatStat {
|
pub struct BoatStat {
|
||||||
pot_years: Vec<i32>,
|
pot_years: Vec<i32>,
|
||||||
@ -28,7 +26,7 @@ impl BoatStat {
|
|||||||
let rows = sqlx::query(
|
let rows = sqlx::query(
|
||||||
"
|
"
|
||||||
SELECT
|
SELECT
|
||||||
boat.id,
|
boat.name,
|
||||||
location.name AS location,
|
location.name AS location,
|
||||||
CAST(strftime('%Y', arrival) AS INTEGER) AS year,
|
CAST(strftime('%Y', arrival) AS INTEGER) AS year,
|
||||||
CAST(SUM(distance_in_km) AS INTEGER) AS rowed_km
|
CAST(SUM(distance_in_km) AS INTEGER) AS rowed_km
|
||||||
@ -51,14 +49,7 @@ impl BoatStat {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
for row in rows {
|
for row in rows {
|
||||||
let id: i32 = row.get("id");
|
let name: String = row.get("name");
|
||||||
let boat = Boat::find_by_id(db, id).await.unwrap();
|
|
||||||
let owner = if let Some(owner) = boat.owner(db).await {
|
|
||||||
owner.name
|
|
||||||
} else {
|
|
||||||
String::from("Verein")
|
|
||||||
};
|
|
||||||
let name = format!("{} ({})", boat.name, owner);
|
|
||||||
let location: String = row.get("location");
|
let location: String = row.get("location");
|
||||||
let year: i32 = row.get("year");
|
let year: i32 = row.get("year");
|
||||||
if year == 0 {
|
if year == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user