implement is_locked for trip_details

This commit is contained in:
2023-08-09 11:54:18 +02:00
parent 21c5609b31
commit bd4ee5954c
9 changed files with 150 additions and 47 deletions

View File

@ -23,6 +23,7 @@ pub struct PlannedEvent {
pub allow_guests: bool,
trip_type_id: Option<i64>,
always_show: bool,
is_locked: bool,
}
#[derive(Serialize)]
@ -49,7 +50,7 @@ impl PlannedEvent {
Self,
"
SELECT
planned_event.id, planned_event.name, planned_amount_cox, trip_details_id, planned_starting_time, max_people, day, notes, allow_guests, trip_type_id, always_show
planned_event.id, planned_event.name, planned_amount_cox, trip_details_id, planned_starting_time, max_people, day, notes, allow_guests, trip_type_id, always_show, is_locked
FROM planned_event
INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id
WHERE planned_event.id like ?
@ -77,7 +78,7 @@ WHERE planned_event.id like ?
let day = format!("{day}");
let events = sqlx::query_as!(
PlannedEvent,
"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
"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
WHERE day=?",
@ -108,7 +109,7 @@ WHERE day=?",
pub async fn all(db: &SqlitePool) -> Vec<PlannedEvent> {
sqlx::query_as!(
PlannedEvent,
"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
"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",
)
@ -195,6 +196,7 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
max_people: i32,
notes: Option<&str>,
always_show: bool,
is_locked: bool,
) {
sqlx::query!(
"UPDATE planned_event SET planned_amount_cox = ? WHERE id = ?",
@ -206,10 +208,11 @@ 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 = ?, always_show=? WHERE id = ?",
"UPDATE trip_details SET max_people = ?, notes = ?, always_show = ?, is_locked = ? WHERE id = ?",
max_people,
notes,
always_show,
is_locked,
self.trip_details_id
)
.execute(db)
@ -242,6 +245,12 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
write!(&mut buf, "{}", calendar).unwrap();
String::from_utf8(buf).unwrap()
}
pub async fn trip_details(&self, db: &SqlitePool) -> TripDetails {
TripDetails::find_by_id(db, self.trip_details_id)
.await
.unwrap() //ok, not null in db
}
}
#[cfg(test)]