move always_show to tripdetails
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use chrono::NaiveDate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
|
||||
@ -10,6 +11,7 @@ pub struct TripDetails {
|
||||
notes: Option<String>,
|
||||
pub allow_guests: bool,
|
||||
trip_type_id: Option<i64>,
|
||||
always_show: bool,
|
||||
}
|
||||
|
||||
impl TripDetails {
|
||||
@ -17,7 +19,7 @@ impl TripDetails {
|
||||
sqlx::query_as!(
|
||||
TripDetails,
|
||||
"
|
||||
SELECT id, planned_starting_time, max_people, day, notes, allow_guests, trip_type_id
|
||||
SELECT id, planned_starting_time, max_people, day, notes, allow_guests, trip_type_id, always_show
|
||||
FROM trip_details
|
||||
WHERE id like ?
|
||||
",
|
||||
@ -37,15 +39,17 @@ WHERE id like ?
|
||||
notes: Option<&str>,
|
||||
allow_guests: bool,
|
||||
trip_type_id: Option<i64>,
|
||||
always_show: bool,
|
||||
) -> i64 {
|
||||
let query = sqlx::query!(
|
||||
"INSERT INTO trip_details(planned_starting_time, max_people, day, notes, allow_guests, trip_type_id) VALUES(?, ?, ?, ?, ?, ?)" ,
|
||||
"INSERT INTO trip_details(planned_starting_time, max_people, day, notes, allow_guests, trip_type_id, always_show) VALUES(?, ?, ?, ?, ?, ?, ?)" ,
|
||||
planned_starting_time,
|
||||
max_people,
|
||||
day,
|
||||
notes,
|
||||
allow_guests,
|
||||
trip_type_id
|
||||
trip_type_id,
|
||||
always_show
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
@ -65,6 +69,20 @@ WHERE id like ?
|
||||
|
||||
amount_currently_registered >= self.max_people
|
||||
}
|
||||
|
||||
pub async fn pinned_days(db: &SqlitePool, amount_days_to_skip: i64) -> Vec<NaiveDate> {
|
||||
let query = format!(
|
||||
"SELECT DISTINCT day
|
||||
FROM trip_details
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -100,7 +118,8 @@ mod test {
|
||||
"1970-01-01".into(),
|
||||
None,
|
||||
false,
|
||||
None
|
||||
None,
|
||||
false
|
||||
)
|
||||
.await,
|
||||
3,
|
||||
@ -113,7 +132,8 @@ mod test {
|
||||
"1970-01-01".into(),
|
||||
None,
|
||||
false,
|
||||
None
|
||||
None,
|
||||
false
|
||||
)
|
||||
.await,
|
||||
4,
|
||||
|
Reference in New Issue
Block a user