Delete post fix, proper cascading on comments
This commit is contained in:
parent
61ab9e072e
commit
d2eac68638
2 changed files with 10 additions and 3 deletions
|
@ -6,9 +6,9 @@ CREATE TABLE IF NOT EXISTS comments (
|
|||
content TEXT NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (parent_post_id) REFERENCES posts (id),
|
||||
FOREIGN KEY (parent_post_id) REFERENCES posts (id) ON DELETE CASCADE,
|
||||
-- FOREIGN KEY (parent_comment_id) REFERENCES comments (id),
|
||||
FOREIGN KEY (author_user_id) REFERENCES users (id)
|
||||
FOREIGN KEY (author_user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Create a function to set created_at and updated_at on INSERT
|
||||
|
|
|
@ -153,7 +153,14 @@ pub async fn delete_post(
|
|||
.await;
|
||||
|
||||
match q {
|
||||
Ok(_) => Ok(HttpResponse::Ok().json("Deleted")),
|
||||
Ok(q) => {
|
||||
// Does this include cascading deletes?
|
||||
if q.rows_affected() == 1 {
|
||||
Ok(HttpResponse::Ok().json("Deleted"))
|
||||
} else {
|
||||
Ok(HttpResponse::Forbidden().json("Forbidden"))
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
info!("Error deleting post: {}", e);
|
||||
Ok(HttpResponse::InternalServerError().json("Error"))
|
||||
|
|
Loading…
Reference in a new issue