fix ci; nicer explanation; subpages
All checks were successful
CI/CD Pipeline / test (push) Successful in 7m26s
CI/CD Pipeline / deploy-main (push) Successful in 4m6s

This commit is contained in:
2024-12-11 20:15:08 +01:00
parent 64ca9826ea
commit 80f7120085
7 changed files with 203 additions and 12 deletions

View File

@@ -630,14 +630,14 @@ mod test {
fn test_succ_create() {
let pool = testdb!();
assert_eq!(User::create(&pool, "new-user-name".into()).await, true);
User::create(&pool, "new-user-name".into()).await;
}
#[sqlx::test]
fn test_duplicate_name_create() {
let pool = testdb!();
assert_eq!(User::create(&pool, "admin".into()).await, false);
User::create(&pool, "admin".into()).await;
}
#[sqlx::test]

View File

@@ -1,7 +1,13 @@
use rocket::{get, http::ContentType, routes, Route, State};
use rocket::{get, http::ContentType, request::FlashMessage, routes, Route, State};
use sqlx::SqlitePool;
use crate::model::{event::Event, personal::cal::get_personal_cal, user::User};
use crate::model::{
event::Event,
personal::cal::get_personal_cal,
user::{User, UserWithDetails},
};
use rocket_dyn_templates::Template;
use tera::Context;
#[get("/cal")]
async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {
@@ -9,6 +15,19 @@ async fn cal(db: &State<SqlitePool>) -> (ContentType, String) {
(ContentType::Calendar, Event::get_ics_feed(db).await)
}
#[get("/kalender")]
async fn calinfo(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
let mut context = Context::new();
if let Some(msg) = flash {
context.insert("flash", &msg.into_inner());
}
context.insert("loggedin_user", &UserWithDetails::from_user(user, db).await);
Template::render("calinfo", context.into_json())
}
#[get("/cal/personal/<user_id>/<uuid>")]
async fn cal_registered(
db: &State<SqlitePool>,
@@ -27,7 +46,7 @@ async fn cal_registered(
}
pub fn routes() -> Vec<Route> {
routes![cal, cal_registered]
routes![cal, cal_registered, calinfo]
}
#[cfg(test)]

View File

@@ -11,17 +11,20 @@ use crate::model::{notification::Notification, user::User};
async fn mark_read(db: &State<SqlitePool>, user: User, notification_id: i64) -> Flash<Redirect> {
let Some(notification) = Notification::find_by_id(db, notification_id).await else {
return Flash::error(
Redirect::to("/"),
Redirect::to("/notifications"),
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")
Flash::success(
Redirect::to("/notifications"),
"Nachricht als gelesen markiert",
)
} else {
Flash::success(
Redirect::to("/"),
Redirect::to("/notifications"),
"Du kannst fremde Nachrichten nicht als gelesen markieren.",
)
}

View File

@@ -11,6 +11,7 @@ use tera::Context;
use crate::{
model::{
log::Log,
notification::Notification,
tripdetails::TripDetails,
triptype::TripType,
user::{User, UserWithDetails},
@@ -47,9 +48,28 @@ async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_
);
context.insert("loggedin_user", &UserWithDetails::from_user(user, db).await);
context.insert("days", &days);
Template::render("index", context.into_json())
}
#[get("/notifications")]
async fn notifications(
db: &State<SqlitePool>,
user: User,
flash: Option<FlashMessage<'_>>,
) -> Template {
let mut context = Context::new();
if let Some(msg) = flash {
context.insert("flash", &msg.into_inner());
}
context.insert("notifications", &Notification::for_user(db, &user).await);
context.insert("loggedin_user", &UserWithDetails::from_user(user, db).await);
Template::render("notifications", context.into_json())
}
#[get("/join/<trip_details_id>?<user_note>")]
async fn join(
db: &State<SqlitePool>,
@@ -215,7 +235,7 @@ async fn remove(db: &State<SqlitePool>, trip_details_id: i64, user: User) -> Fla
}
pub fn routes() -> Vec<Route> {
routes![index, join, remove, remove_guest]
routes![index, join, remove, remove_guest, notifications]
}
#[cfg(test)]