|
|
@ -15,7 +15,6 @@ use std::collections::HashMap; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(FromForm)] |
|
|
|
#[derive(FromForm)] |
|
|
|
pub struct CommentInput { |
|
|
|
pub struct CommentInput { |
|
|
|
pid: i32, |
|
|
|
|
|
|
|
#[field(validate = len(1..12289))] |
|
|
|
#[field(validate = len(1..12289))] |
|
|
|
text: String, |
|
|
|
text: String, |
|
|
|
use_title: Option<i8>, |
|
|
|
use_title: Option<i8>, |
|
|
@ -112,14 +111,20 @@ pub async fn get_comment(pid: i32, user: CurrentUser, db: Db, rconn: RdsConn) -> |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[post("/docomment", data = "<ci>")] |
|
|
|
#[post("/docomment")] |
|
|
|
|
|
|
|
pub async fn old_add_comment() -> ApiError { |
|
|
|
|
|
|
|
OldApi.into() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[post("/post/<pid>/comment", data = "<ci>")] |
|
|
|
pub async fn add_comment( |
|
|
|
pub async fn add_comment( |
|
|
|
|
|
|
|
pid: i32, |
|
|
|
ci: Form<CommentInput>, |
|
|
|
ci: Form<CommentInput>, |
|
|
|
user: CurrentUser, |
|
|
|
user: CurrentUser, |
|
|
|
db: Db, |
|
|
|
db: Db, |
|
|
|
rconn: RdsConn, |
|
|
|
rconn: RdsConn, |
|
|
|
) -> JsonApi { |
|
|
|
) -> JsonApi { |
|
|
|
let mut p = Post::get(&db, &rconn, ci.pid).await?; |
|
|
|
let mut p = Post::get(&db, &rconn, pid).await?; |
|
|
|
let c = Comment::create( |
|
|
|
let c = Comment::create( |
|
|
|
&db, |
|
|
|
&db, |
|
|
|
NewComment { |
|
|
|
NewComment { |
|
|
@ -132,7 +137,7 @@ pub async fn add_comment( |
|
|
|
}) |
|
|
|
}) |
|
|
|
.unwrap_or_default(), |
|
|
|
.unwrap_or_default(), |
|
|
|
is_tmp: user.id.is_none(), |
|
|
|
is_tmp: user.id.is_none(), |
|
|
|
post_id: ci.pid, |
|
|
|
post_id: pid, |
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
.await?; |
|
|
|
.await?; |
|
|
|