You've already forked AstralRinth
forked from didirus/AstralRinth
Register notification routes, add action method for notifications, and fix auto-featuring versions
This commit is contained in:
@@ -10,7 +10,7 @@ pub struct NotificationBuilder {
|
||||
|
||||
pub struct NotificationActionBuilder {
|
||||
pub title: String,
|
||||
pub action_route: String,
|
||||
pub action_route: (String, String),
|
||||
}
|
||||
|
||||
pub struct Notification {
|
||||
@@ -28,6 +28,7 @@ pub struct NotificationAction {
|
||||
pub id: NotificationActionId,
|
||||
pub notification_id: NotificationId,
|
||||
pub title: String,
|
||||
pub action_route_method: String,
|
||||
pub action_route: String,
|
||||
}
|
||||
|
||||
@@ -55,7 +56,8 @@ impl NotificationBuilder {
|
||||
id: NotificationActionId(0),
|
||||
notification_id: id,
|
||||
title: action.title.clone(),
|
||||
action_route: action.action_route.clone(),
|
||||
action_route_method: action.action_route.0.clone(),
|
||||
action_route: action.action_route.1.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,7 +119,7 @@ impl Notification {
|
||||
let result = sqlx::query!(
|
||||
"
|
||||
SELECT n.user_id, n.title, n.text, n.link, n.created, n.read,
|
||||
STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route, ' ,') actions
|
||||
STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route || ', ' || na.action_route_method, ' ,') actions
|
||||
FROM notifications n
|
||||
LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id
|
||||
WHERE n.id = $1
|
||||
@@ -139,6 +141,7 @@ impl Notification {
|
||||
id: NotificationActionId(action[0].parse().unwrap_or(0)),
|
||||
notification_id: id,
|
||||
title: action[1].to_string(),
|
||||
action_route_method: action[3].to_string(),
|
||||
action_route: action[2].to_string(),
|
||||
});
|
||||
}
|
||||
@@ -172,7 +175,7 @@ impl Notification {
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT n.id, n.user_id, n.title, n.text, n.link, n.created, n.read,
|
||||
STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route, ' ,') actions
|
||||
STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route || ', ' || na.action_route_method, ' ,') actions
|
||||
FROM notifications n
|
||||
LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id
|
||||
WHERE n.id IN (SELECT * FROM UNNEST($1::bigint[]))
|
||||
@@ -194,6 +197,7 @@ impl Notification {
|
||||
id: NotificationActionId(action[0].parse().unwrap_or(0)),
|
||||
notification_id: id,
|
||||
title: action[1].to_string(),
|
||||
action_route_method: action[3].to_string(),
|
||||
action_route: action[2].to_string(),
|
||||
});
|
||||
}
|
||||
@@ -227,7 +231,7 @@ impl Notification {
|
||||
sqlx::query!(
|
||||
"
|
||||
SELECT n.id, n.user_id, n.title, n.text, n.link, n.created, n.read,
|
||||
STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route, ' ,') actions
|
||||
STRING_AGG(DISTINCT na.id || ', ' || na.title || ', ' || na.action_route || ', ' || na.action_route_method, ' ,') actions
|
||||
FROM notifications n
|
||||
LEFT OUTER JOIN notifications_actions na on n.id = na.notification_id
|
||||
WHERE n.user_id = $1
|
||||
@@ -249,6 +253,7 @@ impl Notification {
|
||||
id: NotificationActionId(action[0].parse().unwrap_or(0)),
|
||||
notification_id: id,
|
||||
title: action[1].to_string(),
|
||||
action_route_method: action[3].to_string(),
|
||||
action_route: action[2].to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -307,7 +307,8 @@ async fn main() -> std::io::Result<()> {
|
||||
.configure(routes::teams_config)
|
||||
.configure(routes::users_config)
|
||||
.configure(routes::moderation_config)
|
||||
.configure(routes::reports_config),
|
||||
.configure(routes::reports_config)
|
||||
.configure(routes::notifications_config),
|
||||
)
|
||||
.default_service(web::get().to(routes::not_found))
|
||||
})
|
||||
|
||||
@@ -23,5 +23,6 @@ pub struct Notification {
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct NotificationAction {
|
||||
pub title: String,
|
||||
pub action_route: String,
|
||||
/// The route to call when this notification action is called. Formatted HTTP Method, route
|
||||
pub action_route: (String, String),
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ pub fn mods_config(cfg: &mut web::ServiceConfig) {
|
||||
.service(mods::mod_delete)
|
||||
.service(mods::mod_edit)
|
||||
.service(mods::mod_icon_edit)
|
||||
.service(mods::mod_follow)
|
||||
.service(mods::mod_unfollow)
|
||||
.service(web::scope("{mod_id}").service(versions::version_list)),
|
||||
);
|
||||
}
|
||||
@@ -66,7 +68,8 @@ pub fn users_config(cfg: &mut web::ServiceConfig) {
|
||||
.service(users::mods_list)
|
||||
.service(users::user_delete)
|
||||
.service(users::user_edit)
|
||||
.service(users::user_icon_edit),
|
||||
.service(users::user_icon_edit)
|
||||
.service(users::user_follows),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +84,16 @@ pub fn teams_config(cfg: &mut web::ServiceConfig) {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn notifications_config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(notifications::notifications_get);
|
||||
|
||||
cfg.service(
|
||||
web::scope("notification")
|
||||
.service(notifications::notification_get)
|
||||
.service(notifications::notification_delete),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn moderation_config(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::scope("moderation").service(moderation::mods));
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ pub fn convert_notification(
|
||||
.into_iter()
|
||||
.map(|x| NotificationAction {
|
||||
title: x.title,
|
||||
action_route: x.action_route,
|
||||
action_route: (x.action_route_method, x.action_route),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
|
||||
@@ -220,11 +220,14 @@ pub async fn add_team_member(
|
||||
actions: vec![
|
||||
NotificationActionBuilder {
|
||||
title: "Accept".to_string(),
|
||||
action_route: format!("team/{}/join", team),
|
||||
action_route: ("POST".to_string(), format!("team/{}/join", team)),
|
||||
},
|
||||
NotificationActionBuilder {
|
||||
title: "Deny".to_string(),
|
||||
action_route: format!("team/{}/members/{}", team, new_member.user_id),
|
||||
action_route: (
|
||||
"DELETE".to_string(),
|
||||
format!("team/{}/members/{}", team, new_member.user_id),
|
||||
),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -81,6 +81,12 @@ pub async fn version_list(
|
||||
.map(|version| response.push(convert_version(version.clone())))
|
||||
.unwrap_or(());
|
||||
});
|
||||
|
||||
if response.is_empty() {
|
||||
versions
|
||||
.into_iter()
|
||||
.for_each(|version| response.push(convert_version(version.clone())));
|
||||
}
|
||||
}
|
||||
|
||||
response.sort_by(|a, b| b.date_published.cmp(&a.date_published));
|
||||
|
||||
Reference in New Issue
Block a user