forked from Ruderverein-Donau-Linz/rowt
push
This commit is contained in:
parent
7981751f18
commit
913d0ac78e
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1655,9 +1655,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.26"
|
||||
version = "0.3.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
||||
|
||||
[[package]]
|
||||
name = "polyval"
|
||||
|
@ -13,6 +13,7 @@
|
||||
- [] Allow sign-outs only >2h before event
|
||||
- [] add `always_show` to `planned_trips` (e.g. for wanderfahrten)
|
||||
- [] `planned_events` -> ICS feed to be [integrated](https://icscalendar.com/shortcode-overview/) in homepage calendar
|
||||
- [] Notification system (-> signal msgs?) e.g. if new event; somebody unregistered
|
||||
|
||||
# Nice to have
|
||||
## Frontend
|
||||
|
@ -2,7 +2,7 @@ use chrono::NaiveDate;
|
||||
use serde::Serialize;
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
|
||||
use super::{tripdetails::TripDetails, triptype::TripType};
|
||||
use super::{tripdetails::TripDetails, triptype::TripType, user::User};
|
||||
|
||||
#[derive(Serialize, Clone, FromRow)]
|
||||
pub struct PlannedEvent {
|
||||
@ -90,6 +90,7 @@ WHERE day=?",
|
||||
}
|
||||
|
||||
async fn get_all_cox(&self, db: &SqlitePool) -> Vec<Registration> {
|
||||
//TODO: switch to join
|
||||
sqlx::query_as!(
|
||||
Registration,
|
||||
"
|
||||
@ -107,6 +108,7 @@ FROM trip WHERE planned_event_id = ?
|
||||
}
|
||||
|
||||
async fn get_all_rower(&self, db: &SqlitePool) -> Vec<Registration> {
|
||||
//TODO: switch to join
|
||||
sqlx::query_as!(
|
||||
Registration,
|
||||
"
|
||||
@ -123,6 +125,23 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
|
||||
.unwrap() //Okay, as PlannedEvent can only be created with proper DB backing
|
||||
}
|
||||
|
||||
//TODO: add tests
|
||||
pub async fn is_rower_registered(&self, db: &SqlitePool, user: &User) -> bool {
|
||||
let is_rower = sqlx::query!(
|
||||
"SELECT count(*) as amount
|
||||
FROM user_trip
|
||||
WHERE trip_details_id =
|
||||
(SELECT trip_details_id FROM planned_event WHERE id = ?)
|
||||
AND user_id = ?",
|
||||
self.id,
|
||||
user.id
|
||||
)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.unwrap(); //Okay, bc planned_event can only be created with proper DB backing
|
||||
is_rower.amount > 0
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
db: &SqlitePool,
|
||||
name: String,
|
||||
|
@ -67,19 +67,7 @@ WHERE trip.id=?
|
||||
cox: &CoxUser,
|
||||
planned_event: &PlannedEvent,
|
||||
) -> Result<(), CoxHelpError> {
|
||||
let is_rower = sqlx::query!(
|
||||
"SELECT count(*) as amount
|
||||
FROM user_trip
|
||||
WHERE trip_details_id =
|
||||
(SELECT trip_details_id FROM planned_event WHERE id = ?)
|
||||
AND user_id = ?",
|
||||
planned_event.id,
|
||||
cox.id
|
||||
)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.unwrap(); //Okay, bc planned_event can only be created with proper DB backing
|
||||
if is_rower.amount > 0 {
|
||||
if planned_event.is_rower_registered(db, &cox).await {
|
||||
return Err(CoxHelpError::AlreadyRegisteredAsRower);
|
||||
}
|
||||
|
||||
@ -112,6 +100,7 @@ WHERE day=?
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap(); //TODO: fixme
|
||||
|
||||
let mut ret = Vec::new();
|
||||
for trip in trips {
|
||||
let mut trip_type = None;
|
||||
|
@ -63,14 +63,7 @@ WHERE id like ?
|
||||
.unwrap(); //TODO: fixme
|
||||
let amount_currently_registered = i64::from(amount_currently_registered.count);
|
||||
|
||||
let amount_allowed_to_register =
|
||||
sqlx::query!("SELECT max_people FROM trip_details WHERE id = ?", self.id)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.unwrap(); //Okay, TripDetails can only be created if self.id exists
|
||||
let amount_allowed_to_register = amount_allowed_to_register.max_people;
|
||||
|
||||
amount_currently_registered >= amount_allowed_to_register
|
||||
amount_currently_registered >= self.max_people
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ impl UserTrip {
|
||||
return Err(UserTripError::CantRegisterAtOwnEvent);
|
||||
}
|
||||
|
||||
//TODO: can probably move to trip.rs?
|
||||
//check if cox if planned_event
|
||||
let is_cox = sqlx::query!(
|
||||
"SELECT count(*) as amount
|
||||
|
@ -23,26 +23,30 @@ mod admin;
|
||||
mod auth;
|
||||
mod cox;
|
||||
|
||||
fn amount_days_to_show(is_cox: bool) -> i64 {
|
||||
if is_cox {
|
||||
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap();
|
||||
end_of_year
|
||||
.signed_duration_since(Local::now().date_naive())
|
||||
.num_days()
|
||||
+ 1
|
||||
} else {
|
||||
6
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
|
||||
let mut days = Vec::new();
|
||||
|
||||
let mut context = Context::new();
|
||||
|
||||
let mut show_next_n_days = 6;
|
||||
if user.is_cox {
|
||||
let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap();
|
||||
show_next_n_days = end_of_year
|
||||
.signed_duration_since(Local::now().date_naive())
|
||||
.num_days()
|
||||
+ 1;
|
||||
}
|
||||
|
||||
if user.is_cox || user.is_admin {
|
||||
let triptypes = TripType::all(db).await;
|
||||
context.insert("trip_types", &triptypes);
|
||||
}
|
||||
|
||||
let show_next_n_days = amount_days_to_show(user.is_cox);
|
||||
for i in 0..show_next_n_days {
|
||||
let date = (Local::now() + Duration::days(i)).date_naive();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user