39 lines
965 B
Rust
39 lines
965 B
Rust
use serde::{Deserialize, Serialize};
|
|
use sqlx::{FromRow, Sqlite, SqlitePool, Transaction};
|
|
|
|
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()
|
|
}
|
|
|
|
pub async fn create(db: &mut Transaction<'_, Sqlite>, logbook_id: i64, rower_id: i64) {
|
|
let _ = sqlx::query!(
|
|
"INSERT INTO rower(logbook_id, rower_id) VALUES (?,?)",
|
|
logbook_id,
|
|
rower_id
|
|
)
|
|
.execute(db)
|
|
.await
|
|
.unwrap();
|
|
}
|
|
}
|