diff --git a/src/main.rs b/src/main.rs index fbf7f860..2445a2ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,6 +67,8 @@ fn main() { routes::instance::configure, routes::instance::post_config, + routes::notifications::notifications, + routes::user::me, routes::user::details, routes::user::followers, diff --git a/src/models/notifications.rs b/src/models/notifications.rs index c35e4f04..70ffde89 100644 --- a/src/models/notifications.rs +++ b/src/models/notifications.rs @@ -1,8 +1,9 @@ use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods}; +use models::users::User; use schema::notifications; -#[derive(Queryable, Identifiable)] +#[derive(Queryable, Identifiable, Serialize)] pub struct Notification { pub id: i32, pub title: String, @@ -35,4 +36,10 @@ impl Notification { .expect("Couldn't load notification by ID") .into_iter().nth(0) } + + pub fn find_for_user(conn: &PgConnection, user: &User) -> Vec { + notifications::table.filter(notifications::user_id.eq(user.id)) + .load::(conn) + .expect("Couldn't load user notifications") + } } diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 2a72711b..60946b8a 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -5,6 +5,7 @@ pub mod blogs; pub mod comments; pub mod instance; pub mod likes; +pub mod notifications; pub mod posts; pub mod session; pub mod user; diff --git a/src/routes/notifications.rs b/src/routes/notifications.rs new file mode 100644 index 00000000..deb96267 --- /dev/null +++ b/src/routes/notifications.rs @@ -0,0 +1,13 @@ +use rocket_contrib::Template; + +use db_conn::DbConn; +use models::notifications::Notification; +use models::users::User; + +#[get("/notifications")] +fn notifications(conn: DbConn, user: User) -> Template { + Template::render("notifications/index", json!({ + "account": user, + "notifications": Notification::find_for_user(&*conn, &user) + })) +} diff --git a/templates/notifications/index.tera b/templates/notifications/index.tera new file mode 100644 index 00000000..3f0fc15d --- /dev/null +++ b/templates/notifications/index.tera @@ -0,0 +1,19 @@ +{% extends "base" %} + +{% block title %} +Notifications +{% endblock title %} + +{% block content %} +

Notifications

+
+ {% for notification in notifications %} +
+

{{ notification.title }}

+ {% if notification.content %} +

{{ notification.content }}

+ {% endif %} +
+ {% endfor %} +
+{% endblock content %}