push
This commit is contained in:
@ -2,7 +2,7 @@ use chrono::NaiveDate;
|
||||
use serde::Serialize;
|
||||
use sqlx::{FromRow, SqlitePool};
|
||||
|
||||
use super::{tripdetails::TripDetails, triptype::TripType};
|
||||
use super::{tripdetails::TripDetails, triptype::TripType, user::User};
|
||||
|
||||
#[derive(Serialize, Clone, FromRow)]
|
||||
pub struct PlannedEvent {
|
||||
@ -90,6 +90,7 @@ WHERE day=?",
|
||||
}
|
||||
|
||||
async fn get_all_cox(&self, db: &SqlitePool) -> Vec<Registration> {
|
||||
//TODO: switch to join
|
||||
sqlx::query_as!(
|
||||
Registration,
|
||||
"
|
||||
@ -107,6 +108,7 @@ FROM trip WHERE planned_event_id = ?
|
||||
}
|
||||
|
||||
async fn get_all_rower(&self, db: &SqlitePool) -> Vec<Registration> {
|
||||
//TODO: switch to join
|
||||
sqlx::query_as!(
|
||||
Registration,
|
||||
"
|
||||
@ -123,6 +125,23 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
|
||||
.unwrap() //Okay, as PlannedEvent can only be created with proper DB backing
|
||||
}
|
||||
|
||||
//TODO: add tests
|
||||
pub async fn is_rower_registered(&self, db: &SqlitePool, user: &User) -> bool {
|
||||
let is_rower = sqlx::query!(
|
||||
"SELECT count(*) as amount
|
||||
FROM user_trip
|
||||
WHERE trip_details_id =
|
||||
(SELECT trip_details_id FROM planned_event WHERE id = ?)
|
||||
AND user_id = ?",
|
||||
self.id,
|
||||
user.id
|
||||
)
|
||||
.fetch_one(db)
|
||||
.await
|
||||
.unwrap(); //Okay, bc planned_event can only be created with proper DB backing
|
||||
is_rower.amount > 0
|
||||
}
|
||||
|
||||
pub async fn create(
|
||||
db: &SqlitePool,
|
||||
name: String,
|
||||
|
Reference in New Issue
Block a user