show owner of boat in boat km list
This commit is contained in:
@ -5,6 +5,8 @@ use chrono::Datelike;
|
||||
use serde::Serialize;
|
||||
use sqlx::{FromRow, Row, SqlitePool};
|
||||
|
||||
use super::boat::Boat;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct BoatStat {
|
||||
pot_years: Vec<i32>,
|
||||
@ -26,7 +28,7 @@ impl BoatStat {
|
||||
let rows = sqlx::query(
|
||||
"
|
||||
SELECT
|
||||
boat.name,
|
||||
boat.id,
|
||||
location.name AS location,
|
||||
CAST(strftime('%Y', arrival) AS INTEGER) AS year,
|
||||
CAST(SUM(distance_in_km) AS INTEGER) AS rowed_km
|
||||
@ -49,7 +51,14 @@ impl BoatStat {
|
||||
.unwrap();
|
||||
|
||||
for row in rows {
|
||||
let name: String = row.get("name");
|
||||
let id: i32 = row.get("id");
|
||||
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 year: i32 = row.get("year");
|
||||
if year == 0 {
|
||||
|
Reference in New Issue
Block a user