Compare commits

...

30 Commits

Author SHA1 Message Date
817a167223 Merge pull request 'log-2022' (#63) from log-2022 into staging
All checks were successful
CI/CD Pipeline / test (push) Successful in 10m51s
CI/CD Pipeline / deploy-staging (push) Successful in 15m14s
CI/CD Pipeline / deploy-main (push) Has been skipped
Reviewed-on: #63
2023-11-19 22:21:46 +01:00
f004a34b54 Merge branch 'staging' into log-2022
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m3s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2023-11-19 22:20:53 +01:00
4199fadc0a use current year in test_db
All checks were successful
CI/CD Pipeline / test (push) Successful in 11m10s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2023-11-19 22:19:28 +01:00
7bc8293c65 add routes for different years
Some checks failed
CI/CD Pipeline / test (push) Failing after 11m0s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2023-11-19 22:02:43 +01:00
1d9824dfdc push 2023-11-19 22:02:25 +01:00
08202691f6 push 2023-11-19 22:02:25 +01:00
188dd50a84 push 2023-11-19 22:02:25 +01:00
930ecd490b push 2023-11-19 22:02:25 +01:00
0ea4fef9f7 push 2023-11-19 22:02:25 +01:00
d10b22f145 push 2023-11-19 22:02:25 +01:00
a4945e5972 push 2023-11-19 22:02:25 +01:00
33a4cc49e1 push 2023-11-19 22:02:25 +01:00
6c5448c464 push 2023-11-19 22:02:25 +01:00
b4eefb60c4 push 2023-11-19 22:02:25 +01:00
3c8d240549 push 2023-11-19 22:02:25 +01:00
262839f276 push 2023-11-19 22:02:25 +01:00
5cc08d657d push 2023-11-19 22:02:25 +01:00
c0353c0915 push 2023-11-19 22:02:25 +01:00
67ae4095cb push 2023-11-19 22:02:25 +01:00
14d82576f8 push 2023-11-19 22:02:25 +01:00
a9b67660b1 push 2023-11-19 22:02:25 +01:00
34123d9f79 ? 2023-11-19 22:02:25 +01:00
0b1a6acd3a push 2023-11-19 22:02:25 +01:00
c9e47abd8e push 2023-11-19 22:02:25 +01:00
98b2b3d5f4 push 2023-11-19 22:02:25 +01:00
0db0a0f590 switch to gitea 2023-11-19 22:02:25 +01:00
53ed032c25 Merge branch 'staging' into 'log-2022'
# Conflicts:
#   src/model/logbook.rs
2023-11-18 11:22:50 +00:00
f001aaf90f add routes for different years 2023-11-18 12:21:37 +01:00
e053ff96cf migrate 2022 entries 2023-11-18 12:03:31 +01:00
2c0057ca44 Merge branch 'ergo-again' into 'main'
link new urls + fix typo

See merge request PhilippHofer/rot!121
2023-11-16 14:24:43 +00:00
5 changed files with 2529 additions and 31 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 "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 ('Wanderfahrt');
INSERT INTO "logbook_type" (name) VALUES ('Regatta'); INSERT INTO "logbook_type" (name) VALUES ('Regatta');
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) 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, '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 (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, '1142-12-24 10:00', '2142-12-24 11:30', 'Ottensheim + Regattastrecke', 29); 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 "rower" (logbook_id, rower_id) VALUES(3,3); 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) 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); 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::{NaiveDateTime, Utc}; use chrono::{Datelike, NaiveDateTime, Utc};
use rocket::FromForm; use rocket::FromForm;
use serde::Serialize; use serde::Serialize;
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
@ -225,14 +225,14 @@ ORDER BY departure DESC
} }
pub async fn completed(db: &SqlitePool) -> Vec<LogbookWithBoatAndRowers> { pub async fn completed(db: &SqlitePool) -> Vec<LogbookWithBoatAndRowers> {
let logs = sqlx::query_as!( let year = chrono::Utc::now().year();
Logbook, let logs = sqlx::query_as(
" &format!("
SELECT id, boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype SELECT id, boat_id, shipmaster, steering_person, shipmaster_only_steering, departure, arrival, destination, distance_in_km, comments, logtype
FROM logbook FROM logbook
WHERE arrival is not null WHERE arrival is not null AND arrival LIKE '{}-%'
ORDER BY departure DESC ORDER BY departure DESC
" ", year)
) )
.fetch_all(db) .fetch_all(db)
.await .await
@ -553,11 +553,11 @@ mod test {
assert_eq!( assert_eq!(
completed[0].logbook, completed[0].logbook,
Logbook::find_by_id(&pool, 3).await.unwrap() Logbook::find_by_id(&pool, 2).await.unwrap()
); );
assert_eq!( assert_eq!(
completed[1].logbook, completed[1].logbook,
Logbook::find_by_id(&pool, 2).await.unwrap() Logbook::find_by_id(&pool, 3).await.unwrap()
); );
} }

View File

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

View File

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

File diff suppressed because it is too large Load Diff