mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-22 11:31:01 +00:00
Display notifications
This commit is contained in:
parent
726c2c7e82
commit
b91f567777
5 changed files with 43 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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<Notification> {
|
||||
notifications::table.filter(notifications::user_id.eq(user.id))
|
||||
.load::<Notification>(conn)
|
||||
.expect("Couldn't load user notifications")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
13
src/routes/notifications.rs
Normal file
13
src/routes/notifications.rs
Normal file
|
@ -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)
|
||||
}))
|
||||
}
|
19
templates/notifications/index.tera
Normal file
19
templates/notifications/index.tera
Normal file
|
@ -0,0 +1,19 @@
|
|||
{% extends "base" %}
|
||||
|
||||
{% block title %}
|
||||
Notifications
|
||||
{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Notifications</h1>
|
||||
<div>
|
||||
{% for notification in notifications %}
|
||||
<div>
|
||||
<h3><a href="{% if notification.link %}{{ notification.link }}{% else %}#{% endif %}">{{ notification.title }}</h3>
|
||||
{% if notification.content %}
|
||||
<p>{{ notification.content }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock content %}
|
Loading…
Reference in a new issue