forked from Ruderverein-Donau-Linz/rowt
57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use sqlx::{FromRow, SqlitePool};
|
|
|
|
#[derive(FromRow, Debug, Serialize, Deserialize)]
|
|
pub struct TripDetails {
|
|
pub id: i64,
|
|
planned_starting_time: String,
|
|
max_people: i32,
|
|
day: String,
|
|
notes: Option<String>,
|
|
}
|
|
|
|
impl TripDetails {
|
|
/// Creates a new entry in `trip_details` and returns its id.
|
|
pub async fn create(
|
|
db: &SqlitePool,
|
|
planned_starting_time: String,
|
|
max_people: i32,
|
|
day: String,
|
|
notes: Option<String>,
|
|
) -> i64 {
|
|
let query = sqlx::query!(
|
|
"INSERT INTO trip_details(planned_starting_time, max_people, day, notes) VALUES(?, ?, ?, ?)" ,
|
|
planned_starting_time,
|
|
max_people,
|
|
day,
|
|
notes
|
|
)
|
|
.execute(db)
|
|
.await
|
|
.unwrap(); //TODO: fixme
|
|
query.last_insert_rowid()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use crate::testdb;
|
|
|
|
use super::TripDetails;
|
|
use sqlx::SqlitePool;
|
|
|
|
#[sqlx::test]
|
|
fn test() {
|
|
let pool = testdb!();
|
|
|
|
assert_eq!(
|
|
TripDetails::create(&pool, "10:00".into(), 2, "1970-01-01".into(), None).await,
|
|
1,
|
|
);
|
|
assert_eq!(
|
|
TripDetails::create(&pool, "10:00".into(), 2, "1970-01-01".into(), None).await,
|
|
2,
|
|
);
|
|
}
|
|
}
|