(db: &DbConn, id: i32)
| 38 | } |
| 39 | |
| 40 | pub async fn delete_post(db: &DbConn, id: i32) -> Result<DeleteResult, DbErr> { |
| 41 | let post: post::ActiveModel = Post::find_by_id(id) |
| 42 | .one(db) |
| 43 | .await? |
| 44 | .ok_or(DbErr::Custom("Cannot find post.".to_owned())) |
| 45 | .map(Into::into)?; |
| 46 | |
| 47 | post.delete(db).await |
| 48 | } |
| 49 | |
| 50 | pub async fn delete_all_posts(db: &DbConn) -> Result<DeleteResult, DbErr> { |
| 51 | Post::delete_many().exec(db).await |