add: notifications for likes

TODO: notifications ui
This commit is contained in:
trisua 2025-03-29 23:51:13 -04:00
parent 6413ed09fb
commit 9dc75d7095
9 changed files with 292 additions and 27 deletions

View file

@ -0,0 +1,70 @@
use axum::{Extension, Json, extract::Path, response::IntoResponse};
use axum_extra::extract::CookieJar;
use tetratto_core::model::{ApiReturn, Error};
use crate::{State, get_user_from_token};
use super::UpdateNotificationRead;
pub async fn delete_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data.delete_notification(id, &user).await {
Ok(_) => Json(ApiReturn {
ok: true,
message: "Notification deleted".to_string(),
payload: (),
}),
Err(e) => return Json(e.into()),
}
}
pub async fn delete_all_request(
jar: CookieJar,
Extension(data): Extension<State>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data.delete_all_notifications(&user).await {
Ok(_) => Json(ApiReturn {
ok: true,
message: "Notifications deleted".to_string(),
payload: (),
}),
Err(e) => return Json(e.into()),
}
}
pub async fn update_read_status_request(
jar: CookieJar,
Extension(data): Extension<State>,
Path(id): Path<usize>,
Json(req): Json<UpdateNotificationRead>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data.update_notification_read(id, req.read, &user).await {
Ok(_) => Json(ApiReturn {
ok: true,
message: "Notification updated".to_string(),
payload: (),
}),
Err(e) => return Json(e.into()),
}
}