2019-03-20 17:56:17 +01:00
|
|
|
use rocket::response::{Flash, Redirect};
|
2018-12-06 18:54:16 +01:00
|
|
|
use rocket_i18n::I18n;
|
2018-05-13 15:35:55 +02:00
|
|
|
|
2018-06-23 18:36:11 +02:00
|
|
|
use plume_common::utils;
|
2019-04-30 12:04:25 +02:00
|
|
|
use plume_models::{notifications::Notification, users::User, PlumeRocket};
|
2019-03-20 17:56:17 +01:00
|
|
|
use routes::{errors::ErrorPage, Page};
|
2019-04-30 12:04:25 +02:00
|
|
|
use template_utils::{IntoContext, Ructe};
|
2018-06-04 21:57:03 +02:00
|
|
|
|
2018-07-25 15:33:54 +02:00
|
|
|
#[get("/notifications?<page>")]
|
2019-03-20 17:56:17 +01:00
|
|
|
pub fn notifications(
|
|
|
|
user: User,
|
|
|
|
page: Option<Page>,
|
2019-04-30 12:04:25 +02:00
|
|
|
rockets: PlumeRocket,
|
2019-03-20 17:56:17 +01:00
|
|
|
) -> Result<Ructe, ErrorPage> {
|
2018-12-13 22:20:19 +01:00
|
|
|
let page = page.unwrap_or_default();
|
2018-12-29 09:36:07 +01:00
|
|
|
Ok(render!(notifications::index(
|
2019-04-30 12:04:25 +02:00
|
|
|
&rockets.to_context(),
|
|
|
|
Notification::page_for_user(&*rockets.conn, &user, page.limits())?,
|
2018-12-06 18:54:16 +01:00
|
|
|
page.0,
|
2019-04-30 12:04:25 +02:00
|
|
|
Page::total(Notification::count_for_user(&*rockets.conn, &user)? as i32)
|
2018-12-29 09:36:07 +01:00
|
|
|
)))
|
2018-05-13 15:35:55 +02:00
|
|
|
}
|
2018-06-04 21:57:03 +02:00
|
|
|
|
2018-12-13 22:20:19 +01: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> {
|
2018-09-08 01:11:27 +02:00
|
|
|
utils::requires_login(
|
2019-03-20 17:56:17 +01:00
|
|
|
&i18n!(
|
|
|
|
i18n.catalog,
|
2019-04-01 20:09:29 +02:00
|
|
|
"To see your notifications, you need to be logged in"
|
2019-03-20 17:56:17 +01:00
|
|
|
),
|
|
|
|
uri!(notifications: page = page),
|
2018-09-08 01:11:27 +02:00
|
|
|
)
|
2018-06-04 21:57:03 +02:00
|
|
|
}
|