rename planned_event to event
This commit is contained in:
@ -3,7 +3,7 @@ use std::io::Write;
|
||||
use chrono::NaiveDate;
|
||||
use ics::{
|
||||
properties::{DtStart, Summary},
|
||||
Event, ICalendar,
|
||||
ICalendar,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use sqlx::{FromRow, Row, SqlitePool};
|
||||
@ -11,7 +11,7 @@ use sqlx::{FromRow, Row, SqlitePool};
|
||||
use super::{notification::Notification, tripdetails::TripDetails, triptype::TripType, user::User};
|
||||
|
||||
#[derive(Serialize, Clone, FromRow, Debug, PartialEq)]
|
||||
pub struct PlannedEvent {
|
||||
pub struct Event {
|
||||
pub id: i64,
|
||||
pub name: String,
|
||||
planned_amount_cox: i64,
|
||||
@ -27,9 +27,9 @@ pub struct PlannedEvent {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct PlannedEventWithUserAndTriptype {
|
||||
pub struct EventWithUserAndTriptype {
|
||||
#[serde(flatten)]
|
||||
pub planned_event: PlannedEvent,
|
||||
pub event: Event,
|
||||
trip_type: Option<TripType>,
|
||||
cox_needed: bool,
|
||||
cox: Vec<Registration>,
|
||||
@ -94,7 +94,7 @@ FROM trip WHERE planned_event_id = ?
|
||||
is_guest: false,
|
||||
is_real_guest: false,
|
||||
})
|
||||
.collect() //Okay, as PlannedEvent can only be created with proper DB backing
|
||||
.collect() //Okay, as Event can only be created with proper DB backing
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ pub struct EventUpdate<'a> {
|
||||
pub is_locked: bool,
|
||||
}
|
||||
|
||||
impl PlannedEvent {
|
||||
impl Event {
|
||||
pub async fn find_by_id(db: &SqlitePool, id: i64) -> Option<Self> {
|
||||
sqlx::query_as!(
|
||||
Self,
|
||||
@ -128,19 +128,16 @@ WHERE planned_event.id like ?
|
||||
pub async fn get_pinned_for_day(
|
||||
db: &SqlitePool,
|
||||
day: NaiveDate,
|
||||
) -> Vec<PlannedEventWithUserAndTriptype> {
|
||||
) -> Vec<EventWithUserAndTriptype> {
|
||||
let mut events = Self::get_for_day(db, day).await;
|
||||
events.retain(|e| e.planned_event.always_show);
|
||||
events.retain(|e| e.event.always_show);
|
||||
events
|
||||
}
|
||||
|
||||
pub async fn get_for_day(
|
||||
db: &SqlitePool,
|
||||
day: NaiveDate,
|
||||
) -> Vec<PlannedEventWithUserAndTriptype> {
|
||||
pub async fn get_for_day(db: &SqlitePool, day: NaiveDate) -> Vec<EventWithUserAndTriptype> {
|
||||
let day = format!("{day}");
|
||||
let events = sqlx::query_as!(
|
||||
PlannedEvent,
|
||||
Event,
|
||||
"SELECT planned_event.id, planned_event.name, planned_amount_cox, trip_details_id, planned_starting_time, always_show, max_people, day, notes, allow_guests, trip_type_id, is_locked
|
||||
FROM planned_event
|
||||
INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id
|
||||
@ -158,20 +155,20 @@ WHERE day=?",
|
||||
if let Some(trip_type_id) = event.trip_type_id {
|
||||
trip_type = TripType::find_by_id(db, trip_type_id).await;
|
||||
}
|
||||
ret.push(PlannedEventWithUserAndTriptype {
|
||||
ret.push(EventWithUserAndTriptype {
|
||||
cox_needed: event.planned_amount_cox > cox.len() as i64,
|
||||
cox,
|
||||
rower: Registration::all_rower(db, event.trip_details_id).await,
|
||||
planned_event: event,
|
||||
event: event,
|
||||
trip_type,
|
||||
});
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub async fn all(db: &SqlitePool) -> Vec<PlannedEvent> {
|
||||
pub async fn all(db: &SqlitePool) -> Vec<Event> {
|
||||
sqlx::query_as!(
|
||||
PlannedEvent,
|
||||
Event,
|
||||
"SELECT planned_event.id, planned_event.name, planned_amount_cox, trip_details_id, planned_starting_time, always_show, max_people, day, notes, allow_guests, trip_type_id, is_locked
|
||||
FROM planned_event
|
||||
INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
@ -328,7 +325,7 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
sqlx::query!("DELETE FROM planned_event WHERE id = ?", self.id)
|
||||
.execute(db)
|
||||
.await
|
||||
.unwrap(); //Okay, as PlannedEvent can only be created with proper DB backing
|
||||
.unwrap(); //Okay, as Event can only be created with proper DB backing
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -336,9 +333,10 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
pub async fn get_ics_feed(db: &SqlitePool) -> String {
|
||||
let mut calendar = ICalendar::new("2.0", "ics-rs");
|
||||
|
||||
let events = PlannedEvent::all(db).await;
|
||||
let events = Event::all(db).await;
|
||||
for event in events {
|
||||
let mut vevent = Event::new(format!("{}@rudernlinz.at", event.id), "19900101T180000");
|
||||
let mut vevent =
|
||||
ics::Event::new(format!("{}@rudernlinz.at", event.id), "19900101T180000");
|
||||
vevent.push(DtStart::new(format!(
|
||||
"{}T{}00",
|
||||
event.day.replace('-', ""),
|
||||
@ -363,7 +361,7 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
|
||||
mod test {
|
||||
use crate::{model::tripdetails::TripDetails, testdb};
|
||||
|
||||
use super::PlannedEvent;
|
||||
use super::Event;
|
||||
use chrono::NaiveDate;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
@ -371,8 +369,7 @@ mod test {
|
||||
fn test_get_day() {
|
||||
let pool = testdb!();
|
||||
|
||||
let res =
|
||||
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
let res = Event::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
assert_eq!(res.len(), 1);
|
||||
}
|
||||
|
||||
@ -382,22 +379,20 @@ mod test {
|
||||
|
||||
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
|
||||
|
||||
PlannedEvent::create(&pool, "new-event".into(), 2, trip_details).await;
|
||||
Event::create(&pool, "new-event".into(), 2, trip_details).await;
|
||||
|
||||
let res =
|
||||
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
let res = Event::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
assert_eq!(res.len(), 2);
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
fn test_delete() {
|
||||
let pool = testdb!();
|
||||
let planned_event = PlannedEvent::find_by_id(&pool, 1).await.unwrap();
|
||||
let planned_event = Event::find_by_id(&pool, 1).await.unwrap();
|
||||
|
||||
planned_event.delete(&pool).await.unwrap();
|
||||
|
||||
let res =
|
||||
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
let res = Event::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;
|
||||
assert_eq!(res.len(), 0);
|
||||
}
|
||||
|
||||
@ -405,7 +400,7 @@ mod test {
|
||||
fn test_ics() {
|
||||
let pool = testdb!();
|
||||
|
||||
let actual = PlannedEvent::get_ics_feed(&pool).await;
|
||||
let actual = Event::get_ics_feed(&pool).await;
|
||||
assert_eq!("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ics-rs\r\nBEGIN:VEVENT\r\nUID:1@rudernlinz.at\r\nDTSTAMP:19900101T180000\r\nDTSTART:19700101T100000\r\nSUMMARY:test-planned-event\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", actual);
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ use serde::Serialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use self::{
|
||||
planned_event::{PlannedEvent, PlannedEventWithUserAndTriptype},
|
||||
event::{Event, EventWithUserAndTriptype},
|
||||
trip::{Trip, TripWithUserAndType},
|
||||
waterlevel::Waterlevel,
|
||||
weather::Weather,
|
||||
@ -13,6 +13,7 @@ pub mod boat;
|
||||
pub mod boatdamage;
|
||||
pub mod boathouse;
|
||||
pub mod boatreservation;
|
||||
pub mod event;
|
||||
pub mod family;
|
||||
pub mod location;
|
||||
pub mod log;
|
||||
@ -20,7 +21,6 @@ pub mod logbook;
|
||||
pub mod logtype;
|
||||
pub mod mail;
|
||||
pub mod notification;
|
||||
pub mod planned_event;
|
||||
pub mod role;
|
||||
pub mod rower;
|
||||
pub mod stat;
|
||||
@ -35,7 +35,7 @@ pub mod weather;
|
||||
#[derive(Serialize, Debug)]
|
||||
pub struct Day {
|
||||
day: NaiveDate,
|
||||
planned_events: Vec<PlannedEventWithUserAndTriptype>,
|
||||
events: Vec<EventWithUserAndTriptype>,
|
||||
trips: Vec<TripWithUserAndType>,
|
||||
is_pinned: bool,
|
||||
max_waterlevel: Option<i64>,
|
||||
@ -47,7 +47,7 @@ impl Day {
|
||||
if is_pinned {
|
||||
Self {
|
||||
day,
|
||||
planned_events: PlannedEvent::get_pinned_for_day(db, day).await,
|
||||
events: Event::get_pinned_for_day(db, day).await,
|
||||
trips: Trip::get_pinned_for_day(db, day).await,
|
||||
is_pinned,
|
||||
max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await,
|
||||
@ -56,7 +56,7 @@ impl Day {
|
||||
} else {
|
||||
Self {
|
||||
day,
|
||||
planned_events: PlannedEvent::get_for_day(db, day).await,
|
||||
events: Event::get_for_day(db, day).await,
|
||||
trips: Trip::get_for_day(db, day).await,
|
||||
is_pinned,
|
||||
max_waterlevel: Waterlevel::max_waterlevel_for_day(db, day).await,
|
||||
@ -67,7 +67,7 @@ impl Day {
|
||||
pub async fn new_guest(db: &SqlitePool, day: NaiveDate, is_pinned: bool) -> Self {
|
||||
let mut day = Self::new(db, day, is_pinned).await;
|
||||
|
||||
day.planned_events.retain(|e| e.planned_event.allow_guests);
|
||||
day.events.retain(|e| e.event.allow_guests);
|
||||
day.trips.retain(|t| t.trip.allow_guests);
|
||||
|
||||
day
|
||||
|
@ -3,8 +3,8 @@ use serde::Serialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use super::{
|
||||
event::{Event, Registration},
|
||||
notification::Notification,
|
||||
planned_event::{PlannedEvent, Registration},
|
||||
tripdetails::TripDetails,
|
||||
triptype::TripType,
|
||||
user::{CoxUser, User},
|
||||
@ -133,28 +133,28 @@ WHERE trip.id=?
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Cox decides to help in a planned event.
|
||||
/// Cox decides to help in a event.
|
||||
pub async fn new_join(
|
||||
db: &SqlitePool,
|
||||
cox: &CoxUser,
|
||||
planned_event: &PlannedEvent,
|
||||
event: &Event,
|
||||
) -> Result<(), CoxHelpError> {
|
||||
if planned_event.is_rower_registered(db, cox).await {
|
||||
if event.is_rower_registered(db, cox).await {
|
||||
return Err(CoxHelpError::AlreadyRegisteredAsRower);
|
||||
}
|
||||
|
||||
if planned_event.trip_details(db).await.is_locked {
|
||||
if event.trip_details(db).await.is_locked {
|
||||
return Err(CoxHelpError::DetailsLocked);
|
||||
}
|
||||
|
||||
if planned_event.max_people == 0 {
|
||||
if event.max_people == 0 {
|
||||
return Err(CoxHelpError::CanceledEvent);
|
||||
}
|
||||
|
||||
match sqlx::query!(
|
||||
"INSERT INTO trip (cox_id, planned_event_id) VALUES(?, ?)",
|
||||
cox.id,
|
||||
planned_event.id
|
||||
event.id
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
@ -281,16 +281,16 @@ WHERE day=?
|
||||
pub async fn delete_by_planned_event(
|
||||
db: &SqlitePool,
|
||||
cox: &CoxUser,
|
||||
planned_event: &PlannedEvent,
|
||||
event: &Event,
|
||||
) -> Result<(), TripHelpDeleteError> {
|
||||
if planned_event.trip_details(db).await.is_locked {
|
||||
if event.trip_details(db).await.is_locked {
|
||||
return Err(TripHelpDeleteError::DetailsLocked);
|
||||
}
|
||||
|
||||
let affected_rows = sqlx::query!(
|
||||
"DELETE FROM trip WHERE cox_id = ? AND planned_event_id = ?",
|
||||
cox.id,
|
||||
planned_event.id
|
||||
event.id
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
@ -374,7 +374,7 @@ pub enum TripUpdateError {
|
||||
mod test {
|
||||
use crate::{
|
||||
model::{
|
||||
planned_event::PlannedEvent,
|
||||
event::Event,
|
||||
trip::{self, TripDeleteError},
|
||||
tripdetails::TripDetails,
|
||||
user::{CoxUser, User},
|
||||
@ -425,7 +425,7 @@ mod test {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let planned_event = PlannedEvent::find_by_id(&pool, 1).await.unwrap();
|
||||
let planned_event = Event::find_by_id(&pool, 1).await.unwrap();
|
||||
|
||||
assert!(Trip::new_join(&pool, &cox, &planned_event).await.is_ok());
|
||||
}
|
||||
@ -441,7 +441,7 @@ mod test {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let planned_event = PlannedEvent::find_by_id(&pool, 1).await.unwrap();
|
||||
let planned_event = Event::find_by_id(&pool, 1).await.unwrap();
|
||||
|
||||
Trip::new_join(&pool, &cox, &planned_event).await.unwrap();
|
||||
assert!(Trip::new_join(&pool, &cox, &planned_event).await.is_err());
|
||||
@ -542,7 +542,7 @@ mod test {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let planned_event = PlannedEvent::find_by_id(&pool, 1).await.unwrap();
|
||||
let planned_event = Event::find_by_id(&pool, 1).await.unwrap();
|
||||
|
||||
Trip::new_join(&pool, &cox, &planned_event).await.unwrap();
|
||||
|
||||
|
@ -823,7 +823,7 @@ ORDER BY last_access DESC
|
||||
for date in TripDetails::pinned_days(db, self.amount_days_to_show(db).await - 1).await {
|
||||
if self.has_role(db, "scheckbuch").await {
|
||||
let day = Day::new_guest(db, date, true).await;
|
||||
if !day.planned_events.is_empty() {
|
||||
if !day.events.is_empty() {
|
||||
days.push(day);
|
||||
}
|
||||
} else {
|
||||
@ -1124,15 +1124,15 @@ impl<'r> FromRequest<'r> for VorstandUser {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct PlannedEventUser(pub(crate) User);
|
||||
pub struct EventUser(pub(crate) User);
|
||||
|
||||
impl From<PlannedEventUser> for User {
|
||||
fn from(val: PlannedEventUser) -> Self {
|
||||
impl From<EventUser> for User {
|
||||
fn from(val: EventUser) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for PlannedEventUser {
|
||||
impl Deref for EventUser {
|
||||
type Target = User;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -1183,7 +1183,7 @@ impl UserWithMembershipPdf {
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'r> FromRequest<'r> for PlannedEventUser {
|
||||
impl<'r> FromRequest<'r> for EventUser {
|
||||
type Error = LoginError;
|
||||
|
||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||
@ -1191,7 +1191,7 @@ impl<'r> FromRequest<'r> for PlannedEventUser {
|
||||
match User::from_request(req).await {
|
||||
Outcome::Success(user) => {
|
||||
if user.has_role(db, "planned_event").await {
|
||||
Outcome::Success(PlannedEventUser(user))
|
||||
Outcome::Success(EventUser(user))
|
||||
} else {
|
||||
Outcome::Error((Status::Forbidden, LoginError::NotACox))
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ pub enum UserTripDeleteError {
|
||||
mod test {
|
||||
use crate::{
|
||||
model::{
|
||||
planned_event::PlannedEvent, trip::Trip, tripdetails::TripDetails, user::CoxUser,
|
||||
event::Event, trip::Trip, tripdetails::TripDetails, user::CoxUser,
|
||||
usertrip::UserTripError,
|
||||
},
|
||||
testdb,
|
||||
@ -240,8 +240,8 @@ mod test {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let planned_event = PlannedEvent::find_by_id(&pool, 1).await.unwrap();
|
||||
Trip::new_join(&pool, &cox, &planned_event).await.unwrap();
|
||||
let event = Event::find_by_id(&pool, 1).await.unwrap();
|
||||
Trip::new_join(&pool, &cox, &event).await.unwrap();
|
||||
|
||||
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
|
||||
let result = UserTrip::create(&pool, &cox, &trip_details, None)
|
||||
|
Reference in New Issue
Block a user