diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index 60a22a2ef..92cf994e4 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use lemmy_api_common::{ build_response::{build_comment_response, send_local_notifs}, comment::{CommentResponse, DeleteComment}, @@ -8,6 +8,7 @@ use lemmy_api_common::{ utils::check_community_user_action, }; use lemmy_db_schema::{ + newtypes::CommentId, source::comment::{Comment, CommentUpdateForm}, traits::Crud, }; @@ -19,8 +20,9 @@ pub async fn delete_comment( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { - let comment_id = data.comment_id; + let comment_id = path.into_inner(); let orig_comment = CommentView::read( &mut context.pool(), comment_id, @@ -67,7 +69,6 @@ pub async fn delete_comment( Some(&local_user_view), ) .await?; - let updated_comment_id = updated_comment.id; ActivityChannel::submit_activity( SendActivityData::DeleteComment( @@ -79,12 +80,6 @@ pub async fn delete_comment( )?; Ok(Json( - build_comment_response( - &context, - updated_comment_id, - Some(local_user_view), - recipient_ids, - ) - .await?, + build_comment_response(&context, comment_id, Some(local_user_view), recipient_ids).await?, )) } diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index 39852081f..ece8514fc 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -1,25 +1,24 @@ -use actix_web::web::{Data, Json, Query}; +use actix_web::web::{Data, Json, Path}; use lemmy_api_common::{ - build_response::build_comment_response, - comment::{CommentResponse, GetComment}, - context::LemmyContext, + build_response::build_comment_response, comment::CommentResponse, context::LemmyContext, utils::check_private_instance, }; -use lemmy_db_schema::source::local_site::LocalSite; +use lemmy_db_schema::{newtypes::CommentId, source::local_site::LocalSite}; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::LemmyResult; #[tracing::instrument(skip(context))] pub async fn get_comment( - data: Query, context: Data, local_user_view: Option, + path: Path, ) -> LemmyResult> { + let id = path.into_inner(); let local_site = LocalSite::read(&mut context.pool()).await?; check_private_instance(&local_user_view, &local_site)?; Ok(Json( - build_comment_response(&context, data.id, local_user_view, vec![]).await?, + build_comment_response(&context, id, local_user_view, vec![]).await?, )) } diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index 1af026204..bd07f4c94 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -1,5 +1,5 @@ use activitypub_federation::config::Data; -use actix_web::web::Json; +use actix_web::web::{Json, Path}; use chrono::Utc; use lemmy_api_common::{ build_response::{build_comment_response, send_local_notifs}, @@ -7,14 +7,12 @@ use lemmy_api_common::{ context::LemmyContext, send_activity::{ActivityChannel, SendActivityData}, utils::{ - check_community_user_action, - get_url_blocklist, - local_site_to_slur_regex, - process_markdown_opt, + check_community_user_action, get_url_blocklist, local_site_to_slur_regex, process_markdown_opt, }, }; use lemmy_db_schema::{ impls::actor_language::validate_post_language, + newtypes::CommentId, source::{ comment::{Comment, CommentUpdateForm}, local_site::LocalSite, @@ -32,10 +30,11 @@ pub async fn update_comment( data: Json, context: Data, local_user_view: LocalUserView, + path: Path, ) -> LemmyResult> { + let comment_id = path.into_inner(); let local_site = LocalSite::read(&mut context.pool()).await?; - let comment_id = data.comment_id; let orig_comment = CommentView::read( &mut context.pool(), comment_id, @@ -70,7 +69,6 @@ pub async fn update_comment( is_valid_body_field(content, false)?; } - let comment_id = data.comment_id; let form = CommentUpdateForm { content, language_id: Some(language_id), diff --git a/src/api_routes_v4.rs b/src/api_routes_v4.rs index 3e634a35f..acf00097a 100644 --- a/src/api_routes_v4.rs +++ b/src/api_routes_v4.rs @@ -225,27 +225,36 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) { ) // Comment .service( - // Handle POST to /comment separately to add the comment() rate limitter - resource("/comment") - .guard(guard::Post()) - .wrap(rate_limit.comment()) - .route(post().to(create_comment)), - ) - .service( - scope("/comment") - .route("", get().to(get_comment)) - .route("", put().to(update_comment)) - .route("/delete", post().to(delete_comment)) - .route("/remove", post().to(remove_comment)) - .route("/mark_as_read", post().to(mark_reply_as_read)) - .route("/distinguish", post().to(distinguish_comment)) - .route("/like", post().to(like_comment)) - .route("/like/list", get().to(list_comment_likes)) - .route("/save", put().to(save_comment)) - .route("/list", get().to(list_comments)) - .route("/report", post().to(create_comment_report)) - .route("/report/resolve", put().to(resolve_comment_report)) - .route("/report/list", get().to(list_comment_reports)), + scope("/comments") + .route("", get().to(list_comments)) + .service( + // Handle POST to /comment separately to add the comment() rate limitter + resource("") + .guard(guard::Post()) + .wrap(rate_limit.comment()) + .route(post().to(create_comment)), + ) + .service( + scope("/{comment_id}") + .route("", get().to(get_comment)) + .route("", put().to(update_comment)) + .route("", delete().to(delete_comment)) + .route("/remove", post().to(remove_comment)) + .route("/mark-as-read", post().to(mark_reply_as_read)) + .route("/distinguish", post().to(distinguish_comment)) + .route("/save", put().to(save_comment)) + .service( + resource("/likes") + .route(get().to(list_comment_likes)) + .route(post().to(like_comment)), + ) + .service( + scope("/reports") + .route("", get().to(list_comment_reports)) + .route("", post().to(create_comment_report)) + .service(scope("/{report_id}").route("", delete().to(resolve_comment_report))), + ), + ), ) // Private Message .service(