Plume/src/routes/notifications.rs

35 lines
1013 B
Rust
Raw Normal View History

2019-03-20 17:56:17 +01:00
use rocket::response::{Flash, Redirect};
use rocket_i18n::I18n;
2018-05-13 15:35:55 +02:00
use plume_common::utils;
use plume_models::{db_conn::DbConn, notifications::Notification, users::User};
2019-03-20 17:56:17 +01:00
use routes::{errors::ErrorPage, Page};
use template_utils::Ructe;
2018-06-04 21:57:03 +02:00
#[get("/notifications?<page>")]
2019-03-20 17:56:17 +01:00
pub fn notifications(
conn: DbConn,
user: User,
page: Option<Page>,
intl: I18n,
) -> Result<Ructe, ErrorPage> {
let page = page.unwrap_or_default();
Ok(render!(notifications::index(
&(&*conn, &intl.catalog, Some(user.clone())),
Notification::page_for_user(&*conn, &user, page.limits())?,
page.0,
Page::total(Notification::count_for_user(&*conn, &user)? as i32)
)))
2018-05-13 15:35:55 +02:00
}
2018-06-04 21:57:03 +02:00
#[get("/notifications?<page>", rank = 2)]
2019-03-20 17:56:17 +01:00
pub fn notifications_auth(i18n: I18n, page: Option<Page>) -> Flash<Redirect> {
utils::requires_login(
2019-03-20 17:56:17 +01:00
&i18n!(
i18n.catalog,
"To see your notifications, you need to be logged in"
2019-03-20 17:56:17 +01:00
),
uri!(notifications: page = page),
)
2018-06-04 21:57:03 +02:00
}