clean code with clippy
Some checks are pending
CI/CD Pipeline / test (push) Waiting to run
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions

This commit is contained in:
2024-05-22 00:13:23 +02:00
parent 6b911f242a
commit 40f97f18a9
11 changed files with 151 additions and 124 deletions

View File

@@ -98,6 +98,15 @@ FROM trip WHERE planned_event_id = ?
}
}
pub struct EventUpdate<'a> {
pub name: &'a str,
pub planned_amount_cox: i32,
pub max_people: i32,
pub notes: Option<&'a str>,
pub always_show: bool,
pub is_locked: bool,
}
impl PlannedEvent {
pub async fn find_by_id(db: &SqlitePool, id: i64) -> Option<Self> {
sqlx::query_as!(
@@ -207,20 +216,11 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
}
//TODO: create unit test
pub async fn update(
&self,
db: &SqlitePool,
name: &str,
planned_amount_cox: i32,
max_people: i32,
notes: Option<&str>,
always_show: bool,
is_locked: bool,
) {
pub async fn update(&self, db: &SqlitePool, update: &EventUpdate<'_>) {
sqlx::query!(
"UPDATE planned_event SET name = ?, planned_amount_cox = ? WHERE id = ?",
name,
planned_amount_cox,
update.name,
update.planned_amount_cox,
self.id
)
.execute(db)
@@ -229,10 +229,10 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
sqlx::query!(
"UPDATE trip_details SET max_people = ?, notes = ?, always_show = ?, is_locked = ? WHERE id = ?",
max_people,
notes,
always_show,
is_locked,
update.max_people,
update.notes,
update.always_show,
update.is_locked,
self.trip_details_id
)
.execute(db)
@@ -241,16 +241,18 @@ INNER JOIN trip_details ON planned_event.trip_details_id = trip_details.id",
}
pub async fn delete(&self, db: &SqlitePool) -> Result<(), String> {
if Registration::all_rower(db, self.trip_details_id)
if !Registration::all_rower(db, self.trip_details_id)
.await
.len()
> 0
.is_empty()
{
return Err(
"Event kann nicht gelöscht werden, weil mind. 1 Ruderer angemeldet ist.".into(),
);
}
if Registration::all_cox(db, self.trip_details_id).await.len() > 0 {
if !Registration::all_cox(db, self.trip_details_id)
.await
.is_empty()
{
return Err(
"Event kann nicht gelöscht werden, weil mind. 1 Steuerperson angemeldet ist."
.into(),
@@ -326,7 +328,7 @@ mod test {
let pool = testdb!();
let planned_event = PlannedEvent::find_by_id(&pool, 1).await.unwrap();
planned_event.delete(&pool).await;
planned_event.delete(&pool).await.unwrap();
let res =
PlannedEvent::get_for_day(&pool, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()).await;