Compare commits

..

2 Commits

Author SHA1 Message Date
7c8f20623c Merge pull request 'show owner of boat in boat km list' (#344) from staging into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m24s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 5m34s
Reviewed-on: #344
2024-04-06 18:57:57 +02:00
8b07ace876 show owner of boat in boat km list
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m18s
CI/CD Pipeline / deploy-staging (push) Successful in 5m32s
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-04-06 18:55:38 +02:00
2 changed files with 19 additions and 2 deletions

View File

@ -343,6 +343,14 @@ ORDER BY amount_seats DESC
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) {
sqlx::query!("DELETE FROM boat WHERE id=?", self.id)
.execute(db)

View File

@ -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 {