use rocket::{ get, response::{Flash, Redirect}, routes, Route, State, }; use sqlx::SqlitePool; use crate::model::{notification::Notification, user::User}; #[get("//read")] async fn mark_read(db: &State, user: User, notification_id: i64) -> Flash { let Some(notification) = Notification::find_by_id(db, notification_id).await else { return Flash::error( Redirect::to("/"), format!("Nachricht mit ID {notification_id} nicht gefunden."), ); }; if notification.user_id == user.id { notification.mark_read(db).await; Flash::success(Redirect::to("/"), "Nachricht als gelesen markiert") } else { Flash::success( Redirect::to("/"), "Du kannst fremde Nachrichten nicht als gelesen markieren.", ) } } pub fn routes() -> Vec { routes![mark_read] }