rowt/src/model/rower.rs

39 lines
965 B
Rust
Raw Normal View History

2023-07-24 13:01:39 +02:00
use serde::{Deserialize, Serialize};
2023-07-25 13:22:11 +02:00
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
2023-07-24 13:01:39 +02:00
use super::{logbook::Logbook, user::User};
#[derive(FromRow, Debug, Serialize, Deserialize)]
pub struct Rower {
pub logbook_id: i64,
pub rower_id: i64,
}
impl Rower {
pub async fn for_log(db: &SqlitePool, log: &Logbook) -> Vec<User> {
sqlx::query_as!(
User,
"
SELECT id, name, pw, is_cox, is_admin, is_guest, deleted, last_access
FROM user
WHERE id in (SELECT rower_id FROM rower WHERE logbook_id=?)
",
log.id
)
.fetch_all(db)
.await
.unwrap()
}
2023-07-25 13:22:11 +02:00
pub async fn create(db: &mut Transaction<'_, Sqlite>, logbook_id: i64, rower_id: i64) {
2023-07-24 13:01:39 +02:00
let _ = sqlx::query!(
"INSERT INTO rower(logbook_id, rower_id) VALUES (?,?)",
logbook_id,
rower_id
)
.execute(db)
.await
.unwrap();
}
}