move always_show to tripdetails

This commit is contained in:
2023-07-23 19:45:48 +02:00
parent 61961b24e2
commit c32c8bb643
12 changed files with 84 additions and 52 deletions

View File

@ -21,8 +21,8 @@ pub struct PlannedEvent {
pub day: String,
notes: Option<String>,
pub allow_guests: bool,
always_show: bool,
trip_type_id: Option<i64>,
always_show: bool,
}
#[derive(Serialize)]
@ -105,21 +105,6 @@ WHERE day=?",
ret
}
pub async fn pinned_days(db: &SqlitePool, amount_days_to_skip: i64) -> Vec<NaiveDate> {
let query = format!(
"SELECT DISTINCT day
FROM planned_event
INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id
WHERE always_show=true AND day > datetime('now' , '+{} days')
ORDER BY day;",
amount_days_to_skip
);
let days: Vec<String> = sqlx::query_scalar(&query).fetch_all(db).await.unwrap();
days.into_iter()
.map(|a| NaiveDate::parse_from_str(&a, "%Y-%m-%d").unwrap())
.collect()
}
pub async fn all(db: &SqlitePool) -> Vec<PlannedEvent> {
sqlx::query_as!(
PlannedEvent,
@ -189,15 +174,13 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
db: &SqlitePool,
name: &str,
planned_amount_cox: i32,
always_show: bool,
trip_details: TripDetails,
) {
sqlx::query!(
"INSERT INTO planned_event(name, planned_amount_cox, trip_details_id, always_show) VALUES(?, ?, ?, ?)",
"INSERT INTO planned_event(name, planned_amount_cox, trip_details_id) VALUES(?, ?, ?)",
name,
planned_amount_cox,
trip_details.id,
always_show
)
.execute(db)
.await
@ -214,9 +197,8 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
always_show: bool,
) {
sqlx::query!(
"UPDATE planned_event SET planned_amount_cox = ?, always_show=? WHERE id = ?",
"UPDATE planned_event SET planned_amount_cox = ? WHERE id = ?",
planned_amount_cox,
always_show,
self.id
)
.execute(db)
@ -224,9 +206,10 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
.unwrap(); //Okay, as planned_event can only be created with proper DB backing
sqlx::query!(
"UPDATE trip_details SET max_people = ?, notes = ? WHERE id = ?",
"UPDATE trip_details SET max_people = ?, notes = ?, always_show=? WHERE id = ?",
max_people,
notes,
always_show,
self.trip_details_id
)
.execute(db)
@ -284,7 +267,7 @@ mod test {
let trip_details = TripDetails::find_by_id(&pool, 1).await.unwrap();
PlannedEvent::create(&pool, "new-event".into(), 2, false, trip_details).await;
PlannedEvent::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;