diff --git a/src/model/boat.rs b/src/model/boat.rs index df3e9fd..2959b08 100644 --- a/src/model/boat.rs +++ b/src/model/boat.rs @@ -1,8 +1,8 @@ use std::ops::DerefMut; use chrono::NaiveDateTime; -use rocket::serde::{Deserialize, Serialize}; use rocket::FromForm; +use rocket::serde::{Deserialize, Serialize}; use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; use crate::model::boathouse::Boathouse; diff --git a/src/model/mail.rs b/src/model/mail.rs index 27b8742..c911566 100644 --- a/src/model/mail.rs +++ b/src/model/mail.rs @@ -1,9 +1,9 @@ use std::{error::Error, fs}; use lettre::{ - message::{header::ContentType, Attachment, MultiPart, SinglePart}, - transport::smtp::authentication::Credentials, Address, Message, SmtpTransport, Transport, + message::{Attachment, MultiPart, SinglePart, header::ContentType}, + transport::smtp::authentication::Credentials, }; use sqlx::{Sqlite, SqlitePool, Transaction}; diff --git a/src/model/mod.rs b/src/model/mod.rs index 6e531d1..3652105 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -5,13 +5,12 @@ use waterlevel::WaterlevelDay; use crate::AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD; -use self::{ +use self::{waterlevel::Waterlevel, weather::Weather}; +use boatreservation::{BoatReservation, BoatReservationWithDetails}; +use planned::{ event::{Event, EventWithDetails}, trip::{Trip, TripWithDetails}, - waterlevel::Waterlevel, - weather::Weather, }; -use boatreservation::{BoatReservation, BoatReservationWithDetails}; use std::collections::HashMap; pub mod activity; @@ -20,7 +19,6 @@ pub mod boatdamage; pub mod boathouse; pub mod boatreservation; pub mod distance; -pub mod event; pub mod family; pub mod location; pub mod log; @@ -29,16 +27,13 @@ pub mod logtype; pub mod mail; pub mod notification; pub mod personal; +pub mod planned; pub mod role; pub mod rower; pub mod stat; pub mod trailer; pub mod trailerreservation; -pub mod trip; -pub mod tripdetails; -pub mod triptype; pub mod user; -pub mod usertrip; pub mod waterlevel; pub mod weather; diff --git a/src/model/notification.rs b/src/model/notification.rs index db51693..cf7b893 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -5,7 +5,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; -use super::{role::Role, user::User, usertrip::UserTrip}; +use super::{planned::usertrip::UserTrip, role::Role, user::User}; #[derive(FromRow, Debug, Serialize, Deserialize, Clone)] pub struct Notification { @@ -226,12 +226,14 @@ ORDER BY read_at DESC, created_at DESC; mod test { use crate::{ model::{ - event::{Event, EventUpdate, Registration}, notification::Notification, - trip::Trip, - tripdetails::{TripDetails, TripDetailsToAdd}, + planned::{ + event::{Event, EventUpdate, Registration}, + trip::Trip, + tripdetails::{TripDetails, TripDetailsToAdd}, + usertrip::UserTrip, + }, user::{EventUser, SteeringUser, User}, - usertrip::UserTrip, }, testdb, }; diff --git a/src/model/personal/cal.rs b/src/model/personal/cal.rs index b4e8228..e14a14b 100644 --- a/src/model/personal/cal.rs +++ b/src/model/personal/cal.rs @@ -1,13 +1,16 @@ use std::io::Write; use ics::{ + ICalendar, components::Property, properties::{DtEnd, DtStart, Summary}, - ICalendar, }; use sqlx::SqlitePool; -use crate::model::{event::Event, trip::Trip, user::User}; +use crate::model::{ + planned::{event::Event, trip::Trip}, + user::User, +}; use chrono::{Duration, NaiveTime}; pub(crate) async fn get_personal_cal(db: &SqlitePool, user: &User) -> String { diff --git a/src/model/event.rs b/src/model/planned/event.rs similarity index 99% rename from src/model/event.rs rename to src/model/planned/event.rs index 23fb96c..07b0257 100644 --- a/src/model/event.rs +++ b/src/model/planned/event.rs @@ -5,12 +5,11 @@ use ics::ICalendar; use serde::Serialize; use sqlx::{FromRow, Row, SqlitePool}; -use super::{ +use super::{tripdetails::TripDetails, triptype::TripType}; +use crate::model::{ log::Log, notification::Notification, role::Role, - tripdetails::TripDetails, - triptype::TripType, user::{EventUser, User}, }; @@ -482,7 +481,7 @@ WHERE trip_details.id=? mod test { use crate::{ model::{ - tripdetails::TripDetails, + planned::tripdetails::TripDetails, user::{EventUser, User}, }, testdb, diff --git a/src/model/planned/mod.rs b/src/model/planned/mod.rs new file mode 100644 index 0000000..d46a287 --- /dev/null +++ b/src/model/planned/mod.rs @@ -0,0 +1,5 @@ +pub mod event; +pub mod trip; +pub mod tripdetails; +pub mod triptype; +pub mod usertrip; diff --git a/src/model/trip/create.rs b/src/model/planned/trip/create.rs similarity index 97% rename from src/model/trip/create.rs rename to src/model/planned/trip/create.rs index 7e5e034..46f8bf7 100644 --- a/src/model/trip/create.rs +++ b/src/model/planned/trip/create.rs @@ -1,8 +1,7 @@ use super::Trip; use crate::model::{ notification::Notification, - tripdetails::TripDetails, - triptype::TripType, + planned::{tripdetails::TripDetails, triptype::TripType}, user::{ErgoUser, SteeringUser, User}, }; use sqlx::SqlitePool; diff --git a/src/model/trip/mod.rs b/src/model/planned/trip/mod.rs similarity index 98% rename from src/model/trip/mod.rs rename to src/model/planned/trip/mod.rs index f6baf1d..9d4aecb 100644 --- a/src/model/trip/mod.rs +++ b/src/model/planned/trip/mod.rs @@ -6,13 +6,15 @@ mod create; use super::{ event::{Event, Registration}, - log::Log, - notification::Notification, tripdetails::TripDetails, triptype::TripType, - user::{SteeringUser, User}, usertrip::UserTrip, }; +use crate::model::{ + log::Log, + notification::Notification, + user::{SteeringUser, User}, +}; #[derive(Serialize, Clone, Debug)] pub struct Trip { @@ -411,12 +413,14 @@ pub enum TripUpdateError { mod test { use crate::{ model::{ - event::Event, notification::Notification, - trip::{self, TripDeleteError}, - tripdetails::TripDetails, + planned::{ + event::Event, + trip::{self, TripDeleteError}, + tripdetails::TripDetails, + usertrip::UserTrip, + }, user::{SteeringUser, User}, - usertrip::UserTrip, }, testdb, }; @@ -467,9 +471,11 @@ mod test { let last_notification = &Notification::for_user(&pool, &cox).await[0]; - assert!(last_notification - .message - .starts_with("cox2 hat eine Ausfahrt zur selben Zeit")); + assert!( + last_notification + .message + .starts_with("cox2 hat eine Ausfahrt zur selben Zeit") + ); } #[sqlx::test] diff --git a/src/model/tripdetails.rs b/src/model/planned/tripdetails.rs similarity index 98% rename from src/model/tripdetails.rs rename to src/model/planned/tripdetails.rs index e19a2b7..1908f6d 100644 --- a/src/model/tripdetails.rs +++ b/src/model/planned/tripdetails.rs @@ -1,11 +1,10 @@ -use crate::model::user::User; +use crate::model::{notification::Notification, user::User}; use chrono::{Local, NaiveDate}; use rocket::FromForm; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, SqlitePool}; use super::{ - notification::Notification, trip::{Trip, TripWithDetails}, triptype::TripType, }; @@ -303,7 +302,7 @@ pub(crate) enum Action { #[cfg(test)] mod test { - use crate::{model::tripdetails::TripDetailsToAdd, testdb}; + use crate::{model::planned::tripdetails::TripDetailsToAdd, testdb}; use super::TripDetails; use sqlx::SqlitePool; diff --git a/src/model/triptype.rs b/src/model/planned/triptype.rs similarity index 100% rename from src/model/triptype.rs rename to src/model/planned/triptype.rs diff --git a/src/model/usertrip.rs b/src/model/planned/usertrip.rs similarity index 98% rename from src/model/usertrip.rs rename to src/model/planned/usertrip.rs index c58f078..f4437f0 100644 --- a/src/model/usertrip.rs +++ b/src/model/planned/usertrip.rs @@ -2,12 +2,14 @@ use serde::{Deserialize, Serialize}; use sqlx::{FromRow, SqlitePool}; use super::{ - notification::Notification, trip::{Trip, TripWithDetails}, tripdetails::TripDetails, +}; +use crate::model::{ + notification::Notification, + planned::tripdetails::{Action, CoxAtTrip::Yes}, user::{SteeringUser, User}, }; -use crate::model::tripdetails::{Action, CoxAtTrip::Yes}; #[derive(FromRow, Debug, Serialize, Deserialize, Clone)] pub struct UserTrip { @@ -270,8 +272,10 @@ pub enum UserTripDeleteError { mod test { use crate::{ model::{ - event::Event, trip::Trip, tripdetails::TripDetails, user::SteeringUser, - usertrip::UserTripError, + planned::{ + event::Event, trip::Trip, tripdetails::TripDetails, usertrip::UserTripError, + }, + user::SteeringUser, }, testdb, }; diff --git a/src/model/user/fee.rs b/src/model/user/fee.rs index a1d07e4..6f6914c 100644 --- a/src/model/user/fee.rs +++ b/src/model/user/fee.rs @@ -1,8 +1,8 @@ use super::User; use crate::{ - model::family::Family, BOAT_STORAGE, DUAL_MEMBERSHIP, EINSCHREIBGEBUEHR, FAMILY_THREE_OR_MORE, - FAMILY_TWO, FOERDERND, REGULAR, RENNRUDERBEITRAG, SCHECKBUCH, STUDENT_OR_PUPIL, TRIAL_ROWING, - TRIAL_ROWING_REDUCED, UNTERSTUETZEND, + BOAT_STORAGE, DUAL_MEMBERSHIP, EINSCHREIBGEBUEHR, FAMILY_THREE_OR_MORE, FAMILY_TWO, FOERDERND, + REGULAR, RENNRUDERBEITRAG, SCHECKBUCH, STUDENT_OR_PUPIL, TRIAL_ROWING, TRIAL_ROWING_REDUCED, + UNTERSTUETZEND, model::family::Family, }; use chrono::{Datelike, Local, NaiveDate}; use serde::Serialize; diff --git a/src/model/user/foerdernd.rs b/src/model/user/foerdernd.rs index 1f254cb..f9187b1 100644 --- a/src/model/user/foerdernd.rs +++ b/src/model/user/foerdernd.rs @@ -1,7 +1,8 @@ -use super::{regular::ClubMember, ManageUserUser, User}; +use super::{ManageUserUser, User, regular::ClubMember}; use crate::{ + NonEmptyString, model::{activity::ActivityBuilder, mail::Mail, notification::Notification, role::Role}, - special_user, NonEmptyString, + special_user, }; use chrono::NaiveDate; use rocket::{async_trait, fs::TempFile}; diff --git a/src/model/user/mod.rs b/src/model/user/mod.rs index f555839..7f01ac1 100644 --- a/src/model/user/mod.rs +++ b/src/model/user/mod.rs @@ -1,29 +1,29 @@ use std::{fmt::Display, ops::DerefMut}; -use argon2::{password_hash::SaltString, Argon2, PasswordHasher}; +use argon2::{Argon2, PasswordHasher, password_hash::SaltString}; use chrono::{Datelike, Local, NaiveDate}; use log::info; use rocket::async_trait; use rocket::{ + Request, http::{Cookie, Status}, request::{FromRequest, Outcome}, time::{Duration, OffsetDateTime}, - Request, }; use serde::{Deserialize, Serialize}; use sqlx::{FromRow, Sqlite, SqlitePool, Transaction}; use super::activity::{ActivityBuilder, ReasonAuth}; use super::{ + Day, log::Log, logbook::Logbook, mail::Mail, notification::Notification, personal::{equatorprice, rowingbadge}, + planned::tripdetails::TripDetails, role::Role, stat::Stat, - tripdetails::TripDetails, - Day, }; use crate::AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD; use scheckbuch::ScheckbuchUser; @@ -502,7 +502,7 @@ ASKÖ Ruderverein Donau Linz", self.name), .save(db) .await; return Err(LoginError::InvalidAuthenticationCombo); //User existed sometime ago; has - //been deleted + //been deleted } if let Some(user_pw) = user.pw.as_ref() { @@ -605,9 +605,9 @@ ASKÖ Ruderverein Donau Linz", self.name), pub(crate) async fn amount_days_to_show(&self, db: &SqlitePool) -> i64 { if self.allowed_to_steer(db).await { let end_of_year = NaiveDate::from_ymd_opt(Local::now().year(), 12, 31).unwrap(); //Ok, - //december - //has 31 - //days + //december + //has 31 + //days let days_left_in_year = end_of_year .signed_duration_since(Local::now().date_naive()) .num_days() @@ -616,9 +616,9 @@ ASKÖ Ruderverein Donau Linz", self.name), if days_left_in_year <= 31 { let end_of_next_year = NaiveDate::from_ymd_opt(Local::now().year() + 1, 12, 31).unwrap(); //Ok, - //december - //has 31 - //days + //december + //has 31 + //days end_of_next_year .signed_duration_since(Local::now().date_naive()) .num_days() @@ -850,8 +850,8 @@ special_user!(SteeringUser, +"cox", +"Bootsführer"); special_user!(AdminUser, +"admin"); special_user!(AllowedForPlannedTripsUser, +"Donau Linz", +"scheckbuch", +"Förderndes Mitglied"); special_user!(DonauLinzUser, +"Donau Linz", -"Unterstützend", -"Förderndes Mitglied"); // TODO: - // remove -> - // RegularUser +// remove -> +// RegularUser special_user!(SchnupperBetreuerUser, +"schnupper-betreuer"); special_user!(VorstandUser, +"admin", +"Vorstand"); special_user!(EventUser, +"manage_events"); @@ -965,17 +965,21 @@ mod test { #[sqlx::test] fn wrong_pw() { let pool = testdb!(); - assert!(User::login(&pool, "admin".into(), "admi".into()) - .await - .is_err()); + assert!( + User::login(&pool, "admin".into(), "admi".into()) + .await + .is_err() + ); } #[sqlx::test] fn wrong_username() { let pool = testdb!(); - assert!(User::login(&pool, "admi".into(), "admin".into()) - .await - .is_err()); + assert!( + User::login(&pool, "admi".into(), "admin".into()) + .await + .is_err() + ); } #[sqlx::test] @@ -995,9 +999,11 @@ mod test { let pool = testdb!(); let user = User::find_by_id(&pool, 1).await.unwrap(); - assert!(User::login(&pool, "admin".into(), "abc".into()) - .await - .is_err()); + assert!( + User::login(&pool, "admin".into(), "abc".into()) + .await + .is_err() + ); user.update_pw(&pool, "abc".into()).await; diff --git a/src/model/user/regular.rs b/src/model/user/regular.rs index 5b19333..a9741e6 100644 --- a/src/model/user/regular.rs +++ b/src/model/user/regular.rs @@ -1,7 +1,8 @@ use super::{ManageUserUser, User}; use crate::{ + NonEmptyString, model::{activity::ActivityBuilder, mail::Mail, notification::Notification, role::Role}, - special_user, NonEmptyString, + special_user, }; use chrono::NaiveDate; use rocket::{async_trait, fs::TempFile, tokio::io::AsyncReadExt}; diff --git a/src/model/user/scheckbuch.rs b/src/model/user/scheckbuch.rs index 0975973..9466e0f 100644 --- a/src/model/user/scheckbuch.rs +++ b/src/model/user/scheckbuch.rs @@ -2,12 +2,13 @@ use super::foerdernd::FoerderndUser; use super::regular::RegularUser; use super::unterstuetzend::UnterstuetzendUser; use super::{ManageUserUser, User}; +use crate::NonEmptyString; use crate::model::activity::ActivityBuilder; use crate::model::role::Role; -use crate::NonEmptyString; use crate::{ + SCHECKBUCH, model::{mail::Mail, notification::Notification}, - special_user, SCHECKBUCH, + special_user, }; use chrono::NaiveDate; use rocket::async_trait; diff --git a/src/model/user/schnupperant.rs b/src/model/user/schnupperant.rs index 650c849..4da362c 100644 --- a/src/model/user/schnupperant.rs +++ b/src/model/user/schnupperant.rs @@ -4,9 +4,9 @@ use super::scheckbuch::ScheckbuchUser; use super::schnupperinterest::SchnupperInterestUser; use super::unterstuetzend::UnterstuetzendUser; use super::{ManageUserUser, User}; +use crate::NonEmptyString; use crate::model::activity::ActivityBuilder; use crate::model::role::Role; -use crate::NonEmptyString; use crate::{ model::{mail::Mail, notification::Notification}, special_user, diff --git a/src/model/user/schnupperinterest.rs b/src/model/user/schnupperinterest.rs index 17f5703..7ed7e7e 100644 --- a/src/model/user/schnupperinterest.rs +++ b/src/model/user/schnupperinterest.rs @@ -1,9 +1,9 @@ use super::scheckbuch::ScheckbuchUser; use super::schnupperant::SchnupperantUser; use super::{ManageUserUser, User}; +use crate::NonEmptyString; use crate::model::activity::ActivityBuilder; use crate::model::role::Role; -use crate::NonEmptyString; use crate::{model::notification::Notification, special_user}; use rocket::async_trait; use sqlx::SqlitePool; diff --git a/src/model/user/unterstuetzend.rs b/src/model/user/unterstuetzend.rs index a38c13c..2a9ba62 100644 --- a/src/model/user/unterstuetzend.rs +++ b/src/model/user/unterstuetzend.rs @@ -1,7 +1,8 @@ -use super::{regular::ClubMember, ManageUserUser, User}; +use super::{ManageUserUser, User, regular::ClubMember}; use crate::{ + NonEmptyString, model::{activity::ActivityBuilder, mail::Mail, notification::Notification, role::Role}, - special_user, NonEmptyString, + special_user, }; use chrono::NaiveDate; use rocket::{async_trait, fs::TempFile}; diff --git a/src/tera/admin/event.rs b/src/tera/admin/event.rs index 26e7112..7574646 100644 --- a/src/tera/admin/event.rs +++ b/src/tera/admin/event.rs @@ -9,8 +9,10 @@ use serde::Serialize; use sqlx::SqlitePool; use crate::model::{ - event::{self, Event}, - tripdetails::{TripDetails, TripDetailsToAdd}, + planned::{ + event::{self, Event}, + tripdetails::{TripDetails, TripDetailsToAdd}, + }, user::EventUser, }; diff --git a/src/tera/cox.rs b/src/tera/cox.rs index 6f03e280..7f98c88 100644 --- a/src/tera/cox.rs +++ b/src/tera/cox.rs @@ -1,16 +1,19 @@ use rocket::{ + FromForm, Route, State, form::Form, get, post, response::{Flash, Redirect}, - routes, FromForm, Route, State, + routes, }; use sqlx::SqlitePool; use crate::model::{ - event::Event, log::Log, - trip::{self, CoxHelpError, Trip, TripDeleteError, TripHelpDeleteError, TripUpdateError}, - tripdetails::{TripDetails, TripDetailsToAdd}, + planned::{ + event::Event, + trip::{self, CoxHelpError, Trip, TripDeleteError, TripHelpDeleteError, TripUpdateError}, + tripdetails::{TripDetails, TripDetailsToAdd}, + }, user::{AllowedToUpdateTripToAlwaysBeShownUser, ErgoUser, SteeringUser, User}, }; @@ -22,7 +25,7 @@ async fn create_ergo( ) -> Flash { let trip_details_id = TripDetails::create(db, data.into_inner()).await; let trip_details = TripDetails::find_by_id(db, trip_details_id).await.unwrap(); //Okay, bc just - //created + //created Trip::new_own_ergo(db, &cox, trip_details).await; //TODO: fix Flash::success(Redirect::to("/planned"), "Ausfahrt erfolgreich erstellt.") @@ -37,7 +40,7 @@ async fn create( ) -> Flash { let trip_details_id = TripDetails::create(db, data.into_inner()).await; let trip_details = TripDetails::find_by_id(db, trip_details_id).await.unwrap(); //Okay, bc just - //created + //created Trip::new_own(db, &cox, trip_details).await; //TODO: fix Flash::success(Redirect::to("/planned"), "Ausfahrt erfolgreich erstellt.") @@ -216,7 +219,7 @@ mod test { }; use sqlx::SqlitePool; - use crate::{model::trip::Trip, testdb}; + use crate::{model::planned::trip::Trip, testdb}; #[sqlx::test] fn test_trip_create() { diff --git a/src/tera/log.rs b/src/tera/log.rs index feed1c3..275c940 100644 --- a/src/tera/log.rs +++ b/src/tera/log.rs @@ -1,6 +1,7 @@ use std::net::IpAddr; use rocket::{ + Request, Route, State, form::Form, get, http::{Cookie, CookieJar}, @@ -9,9 +10,8 @@ use rocket::{ response::{Flash, Redirect}, routes, time::{Duration, OffsetDateTime}, - Request, Route, State, }; -use rocket_dyn_templates::{context, Template}; +use rocket_dyn_templates::{Template, context}; use sqlx::SqlitePool; use tera::Context; @@ -26,7 +26,7 @@ use crate::{ LogbookCreateError, LogbookDeleteError, LogbookUpdateError, }, logtype::LogType, - trip::Trip, + planned::trip::Trip, user::{DonauLinzUser, User, UserWithDetails, VorstandUser}, }, tera::Config, @@ -606,7 +606,7 @@ mod test { use sqlx::SqlitePool; use crate::model::logbook::Logbook; - use crate::tera::{log::Boat, User}; + use crate::tera::{User, log::Boat}; use crate::testdb; #[sqlx::test] diff --git a/src/tera/misc.rs b/src/tera/misc.rs index 52a2b5e..53fddc4 100644 --- a/src/tera/misc.rs +++ b/src/tera/misc.rs @@ -1,7 +1,7 @@ use rocket::{Route, State, get, http::ContentType, routes}; use sqlx::SqlitePool; -use crate::model::{event::Event, personal::cal::get_personal_cal, user::User}; +use crate::model::{personal::cal::get_personal_cal, planned::event::Event, user::User}; #[get("/cal")] async fn cal(db: &State) -> (ContentType, String) { diff --git a/src/tera/planned.rs b/src/tera/planned.rs index 54d6aad..36da762 100644 --- a/src/tera/planned.rs +++ b/src/tera/planned.rs @@ -12,10 +12,12 @@ use crate::{ AMOUNT_DAYS_TO_SHOW_TRIPS_AHEAD, model::{ log::Log, - tripdetails::TripDetails, - triptype::TripType, + planned::{ + tripdetails::TripDetails, + triptype::TripType, + usertrip::{UserTrip, UserTripDeleteError, UserTripError}, + }, user::{AllowedForPlannedTripsUser, User, UserWithDetails}, - usertrip::{UserTrip, UserTripDeleteError, UserTripError}, }, };