-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnotifications.rs
46 lines (41 loc) · 1.06 KB
/
notifications.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use super::*;
pub(crate) async fn get_notifications(
user: User,
AppState(db): AppState<Arc<Db>>,
) -> Result<impl IntoResponse> {
let mut notifications = db.get_notifications(&user.id()).await?;
notifications.sort_by(|a, b| b.review.timestamp.cmp(&a.review.timestamp));
Ok(Json(notifications))
}
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct UpdateNotificationbody {
course_id: String,
creator_id: String,
seen: bool,
}
pub(crate) async fn update_notification(
user: User,
AppState(db): AppState<Arc<Db>>,
body: Json<UpdateNotificationbody>,
) -> Result<impl IntoResponse> {
db.update_notification(
&user.id(),
&body.course_id,
&body.creator_id,
body.seen,
)
.await?;
Ok(())
}
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct DeleteNotificationbody {
course_id: String,
}
pub(crate) async fn delete_notification(
user: User,
AppState(db): AppState<Arc<Db>>,
body: Json<DeleteNotificationbody>,
) -> Result<impl IntoResponse> {
db.delete_notification(&user.id(), &body.course_id).await?;
Ok(())
}