|
|
|
@ -505,7 +505,7 @@ impl GistDatabase for Database {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Create new comment
|
|
|
|
|
async fn new_comment(&self, comment: &CreateGistComment) -> DBResult<()> {
|
|
|
|
|
async fn new_comment(&self, comment: &CreateGistComment) -> DBResult<i64> {
|
|
|
|
|
let now = OffsetDateTime::now_utc();
|
|
|
|
|
sqlx::query!(
|
|
|
|
|
"INSERT INTO gists_comments (owner_id, gist_id, comment, created)
|
|
|
|
@ -523,7 +523,43 @@ impl GistDatabase for Database {
|
|
|
|
|
.execute(&self.pool)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(map_register_err)?;
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
|
|
struct ID {
|
|
|
|
|
id: Option<i32>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let res = sqlx::query_as!(
|
|
|
|
|
ID,
|
|
|
|
|
"
|
|
|
|
|
SELECT
|
|
|
|
|
ID
|
|
|
|
|
FROM
|
|
|
|
|
gists_comments_view
|
|
|
|
|
WHERE
|
|
|
|
|
owner = $1
|
|
|
|
|
AND
|
|
|
|
|
gist_public_id = $2
|
|
|
|
|
AND
|
|
|
|
|
created = $3
|
|
|
|
|
AND
|
|
|
|
|
comment = $4;
|
|
|
|
|
",
|
|
|
|
|
comment.owner,
|
|
|
|
|
comment.gist_public_id,
|
|
|
|
|
&now,
|
|
|
|
|
comment.comment,
|
|
|
|
|
)
|
|
|
|
|
.fetch_one(&self.pool)
|
|
|
|
|
.await
|
|
|
|
|
.map_err(|e| match e {
|
|
|
|
|
Error::RowNotFound => DBError::CommentNotFound,
|
|
|
|
|
e => DBError::DBError(Box::new(e)),
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
match res.id {
|
|
|
|
|
None => Err(DBError::CommentNotFound),
|
|
|
|
|
Some(id) => Ok(id as i64),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// Get comments on a gist
|
|
|
|
|
async fn get_comments_on_gist(&self, public_id: &str) -> DBResult<Vec<GistComment>> {
|
|
|
|
|