disable rowers in logbook if they are on water
This commit is contained in:
@ -28,6 +28,22 @@ pub struct User {
|
||||
pub last_access: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct UserWithWaterStatus {
|
||||
#[serde(flatten)]
|
||||
pub user: User,
|
||||
pub on_water: bool,
|
||||
}
|
||||
|
||||
impl UserWithWaterStatus {
|
||||
pub async fn from_user(user: User, db: &SqlitePool) -> Self {
|
||||
Self {
|
||||
on_water: user.on_water(db).await,
|
||||
user,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for User {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
|
@ -17,7 +17,7 @@ use crate::model::{
|
||||
boat::Boat,
|
||||
logbook::{LogToAdd, LogToFinalize, Logbook, LogbookCreateError, LogbookUpdateError},
|
||||
logtype::LogType,
|
||||
user::{AdminUser, User},
|
||||
user::{AdminUser, User, UserWithWaterStatus},
|
||||
};
|
||||
|
||||
pub struct KioskCookie(String);
|
||||
@ -41,8 +41,21 @@ async fn index(
|
||||
adminuser: AdminUser,
|
||||
) -> Template {
|
||||
let boats = Boat::all(db).await;
|
||||
let coxes = User::cox(db).await;
|
||||
let users = User::all(db).await;
|
||||
|
||||
let coxes: Vec<UserWithWaterStatus> = futures::future::join_all(
|
||||
User::cox(db)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|user| UserWithWaterStatus::from_user(user, db)),
|
||||
)
|
||||
.await;
|
||||
let users: Vec<UserWithWaterStatus> = futures::future::join_all(
|
||||
User::all(db)
|
||||
.await
|
||||
.into_iter()
|
||||
.map(|user| UserWithWaterStatus::from_user(user, db)),
|
||||
)
|
||||
.await;
|
||||
let logtypes = LogType::all(db).await;
|
||||
let distances = Logbook::distances(db).await;
|
||||
|
||||
|
Reference in New Issue
Block a user