Compare commits

..

No commits in common. "817a167223f4c40c9e37901eef96fab7d6fd94f0" and "9694fe6512f1acfbe2c22c98bf8341a382152e1b" have entirely different histories.

5 changed files with 31 additions and 2529 deletions

View File

@ -26,9 +26,9 @@ INSERT INTO "boat" (name, amount_seats, location_id) VALUES ('Ottensheim Boot',
INSERT INTO "boat" (name, amount_seats, location_id, owner) VALUES ('second_private_boat_from_rower', 1, 1, 2);
INSERT INTO "logbook_type" (name) VALUES ('Wanderfahrt');
INSERT INTO "logbook_type" (name) VALUES ('Regatta');
INSERT INTO "logbook" (boat_id, shipmaster,steering_person, shipmaster_only_steering, departure) VALUES (2, 2, 2, false, strftime('%Y', 'now') || '-12-24 10:00');
INSERT INTO "logbook" (boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (1, 4, 4, false, strftime('%Y', 'now') || '-12-24 10:00', strftime('%Y', 'now') || '-12-24 15:00', 'Ottensheim', 25);
INSERT INTO "logbook" (boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (3, 4, 4, false, strftime('%Y', 'now') || '-12-24 10:00', strftime('%Y', 'now') || '-12-24 11:30', 'Ottensheim + Regattastrecke', 29);
INSERT INTO "logbook" (boat_id, shipmaster,steering_person, shipmaster_only_steering, departure) VALUES (2, 2, 2, false, '1142-12-24 10:00');
INSERT INTO "logbook" (boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (1, 4, 4, false, '1141-12-24 10:00', '2141-12-24 15:00', 'Ottensheim', 25);
INSERT INTO "logbook" (boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km) VALUES (3, 4, 4, false, '1142-12-24 10:00', '2142-12-24 11:30', 'Ottensheim + Regattastrecke', 29);
INSERT INTO "rower" (logbook_id, rower_id) VALUES(3,3);
INSERT INTO "boat_damage" (boat_id, desc, user_id_created, created_at) VALUES(4,'Dolle bei Position 2 fehlt', 5, '2142-12-24 15:02');
INSERT INTO "boat_damage" (boat_id, desc, user_id_created, created_at, lock_boat) VALUES(5, 'TOHT', 5, '2142-12-24 15:02', 1);

View File

@ -1,4 +1,4 @@
use chrono::{Datelike, NaiveDateTime, Utc};
use chrono::{NaiveDateTime, Utc};
use rocket::FromForm;
use serde::Serialize;
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
@ -225,14 +225,14 @@ ORDER BY departure DESC
}
pub async fn completed(db: &SqlitePool) -> Vec<LogbookWithBoatAndRowers> {
let year = chrono::Utc::now().year();
let logs = sqlx::query_as(
&format!("
let logs = sqlx::query_as!(
Logbook,
"
SELECT id, boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype
FROM logbook
WHERE arrival is not null AND arrival LIKE '{}-%'
WHERE arrival is not null
ORDER BY departure DESC
", year)
"
)
.fetch_all(db)
.await
@ -553,11 +553,11 @@ mod test {
assert_eq!(
completed[0].logbook,
Logbook::find_by_id(&pool, 2).await.unwrap()
Logbook::find_by_id(&pool, 3).await.unwrap()
);
assert_eq!(
completed[1].logbook,
Logbook::find_by_id(&pool, 3).await.unwrap()
Logbook::find_by_id(&pool, 2).await.unwrap()
);
}

View File

@ -1,5 +1,4 @@
use crate::model::user::User;
use chrono::Datelike;
use serde::Serialize;
use sqlx::{FromRow, Row, SqlitePool};
@ -10,20 +9,15 @@ pub struct Stat {
}
impl Stat {
pub async fn boats(db: &SqlitePool, year: Option<i32>) -> Vec<Stat> {
let year = match year {
Some(year) => year,
None => chrono::Utc::now().year(),
};
pub async fn boats(db: &SqlitePool) -> Vec<Stat> {
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
sqlx::query(&format!(
sqlx::query(
"
SELECT (SELECT name FROM boat WHERE id=logbook.boat_id) as name, CAST(SUM(distance_in_km) AS INTEGER) AS rowed_km
FROM logbook
WHERE arrival LIKE '{}-%'
FROM logbook
GROUP BY boat_id
ORDER BY rowed_km DESC;
",year)
",
)
.fetch_all(db)
.await
@ -36,24 +30,19 @@ ORDER BY rowed_km DESC;
.collect()
}
pub async fn people(db: &SqlitePool, year: Option<i32>) -> Vec<Stat> {
let year = match year {
Some(year) => year,
None => chrono::Utc::now().year(),
};
pub async fn people(db: &SqlitePool) -> Vec<Stat> {
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
sqlx::query(&format!(
sqlx::query(
"
SELECT u.name, CAST(SUM(l.distance_in_km) AS INTEGER) AS rowed_km
FROM user u
INNER JOIN rower r ON u.id = r.rower_id
INNER JOIN logbook l ON r.logbook_id = l.id
WHERE u.is_guest = 0 AND l.distance_in_km IS NOT NULL AND l.arrival LIKE '{}-%'
WHERE u.is_guest = 0 AND l.distance_in_km IS NOT NULL
GROUP BY u.name
ORDER BY rowed_km DESC;
",
year
))
)
.fetch_all(db)
.await
.unwrap()

View File

@ -9,9 +9,9 @@ use crate::model::{
use super::log::KioskCookie;
#[get("/boats?<year>", rank = 2)]
async fn index_boat(db: &State<SqlitePool>, user: NonGuestUser, year: Option<i32>) -> Template {
let stat = Stat::boats(db, year).await;
#[get("/boats", rank = 2)]
async fn index_boat(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
let stat = Stat::boats(db).await;
let kiosk = false;
Template::render(
@ -20,21 +20,17 @@ async fn index_boat(db: &State<SqlitePool>, user: NonGuestUser, year: Option<i32
)
}
#[get("/boats?<year>")]
async fn index_boat_kiosk(
db: &State<SqlitePool>,
_kiosk: KioskCookie,
year: Option<i32>,
) -> Template {
let stat = Stat::boats(db, year).await;
#[get("/boats")]
async fn index_boat_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let stat = Stat::boats(db).await;
let kiosk = true;
Template::render("stat.boats", context!(stat, kiosk, show_kiosk_header: true))
}
#[get("/?<year>", rank = 2)]
async fn index(db: &State<SqlitePool>, user: NonGuestUser, year: Option<i32>) -> Template {
let stat = Stat::people(db, year).await;
#[get("/", rank = 2)]
async fn index(db: &State<SqlitePool>, user: NonGuestUser) -> Template {
let stat = Stat::people(db).await;
let personal = stat::get_personal(db, &user.user).await;
let kiosk = false;
@ -44,9 +40,9 @@ async fn index(db: &State<SqlitePool>, user: NonGuestUser, year: Option<i32>) ->
)
}
#[get("/?<year>")]
async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie, year: Option<i32>) -> Template {
let stat = Stat::people(db, year).await;
#[get("/")]
async fn index_kiosk(db: &State<SqlitePool>, _kiosk: KioskCookie) -> Template {
let stat = Stat::people(db).await;
let kiosk = true;
Template::render(

File diff suppressed because it is too large Load Diff