forked from Ruderverein-Donau-Linz/rowt
clean db
This commit is contained in:
@ -12,8 +12,8 @@ pub struct Logbook {
|
||||
pub shipmaster: i64,
|
||||
#[serde(default = "bool::default")]
|
||||
pub shipmaster_only_steering: bool,
|
||||
pub departure: String, //TODO: Switch to chrono::nativedatetime
|
||||
pub arrival: Option<String>, //TODO: Switch to chrono::nativedatetime
|
||||
pub departure: NaiveDateTime,
|
||||
pub arrival: Option<NaiveDateTime>,
|
||||
pub destination: Option<String>,
|
||||
pub distance_in_km: Option<i64>,
|
||||
pub comments: Option<String>,
|
||||
@ -114,7 +114,8 @@ ORDER BY departure DESC
|
||||
boat_id: row.boat_id,
|
||||
shipmaster: row.shipmaster,
|
||||
shipmaster_only_steering: row.shipmaster_only_steering,
|
||||
departure: row.departure.unwrap(),
|
||||
departure: NaiveDateTime::parse_from_str(&row.departure.unwrap(), "%Y-%m-%d %H:%M")
|
||||
.unwrap(),
|
||||
arrival: row.arrival,
|
||||
destination: row.destination,
|
||||
distance_in_km: row.distance_in_km,
|
||||
@ -125,12 +126,7 @@ ORDER BY departure DESC
|
||||
|
||||
let mut ret = Vec::new();
|
||||
for log in logs {
|
||||
let date_time_naive =
|
||||
NaiveDateTime::parse_from_str(&log.departure, "%Y-%m-%d %H:%M").unwrap();
|
||||
let date_time = Local
|
||||
.from_local_datetime(&date_time_naive)
|
||||
.single()
|
||||
.unwrap();
|
||||
let date_time = Local.from_local_datetime(&log.departure).single().unwrap();
|
||||
|
||||
ret.push(LogbookWithBoatAndRowers {
|
||||
rowers: Rower::for_log(db, &log).await,
|
||||
@ -313,12 +309,12 @@ ORDER BY departure DESC
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// pub async fn delete(&self, db: &SqlitePool) {
|
||||
// sqlx::query!("DELETE FROM boat WHERE id=?", self.id)
|
||||
// .execute(db)
|
||||
// .await
|
||||
// .unwrap(); //Okay, because we can only create a User of a valid id
|
||||
// }
|
||||
pub async fn delete(&self, db: &SqlitePool) {
|
||||
sqlx::query!("DELETE FROM logbook WHERE id=?", self.id)
|
||||
.execute(db)
|
||||
.await
|
||||
.unwrap(); //Okay, because we can only create a Logbook of a valid id
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -205,6 +205,28 @@ async fn home(
|
||||
home_logbook(db, data, logbook_id, &adminuser.user).await
|
||||
}
|
||||
|
||||
#[get("/<logbook_id>/delete")]
|
||||
async fn delete(
|
||||
db: &State<SqlitePool>,
|
||||
flash: Option<FlashMessage<'_>>,
|
||||
logbook_id: i32,
|
||||
_adminuser: AdminUser,
|
||||
) -> Flash<Redirect> {
|
||||
let logbook = Logbook::find_by_id(db, logbook_id).await;
|
||||
if let Some(logbook) = logbook {
|
||||
logbook.delete(db).await;
|
||||
Flash::success(
|
||||
Redirect::to("/log"),
|
||||
format!("Logbook with ID {} successfully deleted!", logbook_id),
|
||||
)
|
||||
} else {
|
||||
Flash::error(
|
||||
Redirect::to("/log"),
|
||||
format!("Logbook with ID {} could not be found!", logbook_id),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![
|
||||
index,
|
||||
@ -215,7 +237,8 @@ pub fn routes() -> Vec<Route> {
|
||||
home_kiosk,
|
||||
new_kiosk,
|
||||
show,
|
||||
show_kiosk
|
||||
show_kiosk,
|
||||
delete
|
||||
]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user