2018-06-04 21:57:03 +02:00
|
|
|
use rocket::response::{Redirect, Flash};
|
2018-05-13 15:35:55 +02:00
|
|
|
use rocket_contrib::Template;
|
|
|
|
|
2018-06-23 18:36:11 +02:00
|
|
|
use plume_common::utils;
|
|
|
|
use plume_models::{db_conn::DbConn, notifications::Notification, users::User};
|
2018-07-25 15:33:54 +02:00
|
|
|
use routes::Page;
|
2018-06-04 21:57:03 +02:00
|
|
|
|
2018-07-25 15:33:54 +02:00
|
|
|
#[get("/notifications?<page>")]
|
|
|
|
fn paginated_notifications(conn: DbConn, user: User, page: Page) -> Template {
|
2018-05-13 15:35:55 +02:00
|
|
|
Template::render("notifications/index", json!({
|
2018-09-03 15:59:02 +02:00
|
|
|
"account": user.to_json(&*conn),
|
2018-07-26 15:46:10 +02:00
|
|
|
"notifications": Notification::page_for_user(&*conn, &user, page.limits()).into_iter().map(|n| n.to_json(&*conn)).collect::<Vec<_>>(),
|
2018-07-25 15:33:54 +02:00
|
|
|
"page": page.page,
|
|
|
|
"n_pages": Page::total(Notification::find_for_user(&*conn, &user).len() as i32)
|
2018-05-13 15:35:55 +02:00
|
|
|
}))
|
|
|
|
}
|
2018-06-04 21:57:03 +02:00
|
|
|
|
2018-07-25 15:33:54 +02:00
|
|
|
#[get("/notifications")]
|
|
|
|
fn notifications(conn: DbConn, user: User) -> Template {
|
|
|
|
paginated_notifications(conn, user, Page::first())
|
|
|
|
}
|
|
|
|
|
2018-06-04 21:57:03 +02:00
|
|
|
#[get("/notifications", rank = 2)]
|
|
|
|
fn notifications_auth() -> Flash<Redirect>{
|
2018-09-08 01:11:27 +02:00
|
|
|
utils::requires_login(
|
|
|
|
"You need to be logged in order to see your notifications",
|
|
|
|
uri!(notifications).into()
|
|
|
|
)
|
2018-06-04 21:57:03 +02:00
|
|
|
}
|