feat: can delete article in admin panel.
This commit is contained in:
parent
62162ea503
commit
74779d9d88
@ -66,6 +66,7 @@ fn main() {
|
||||
admin::admin_index,
|
||||
admin::article_edit,
|
||||
admin::save_article,
|
||||
admin::delete_article,
|
||||
admin::article_creation,
|
||||
admin::change_password,
|
||||
admin::change_setting
|
||||
|
@ -55,7 +55,6 @@ pub fn admin_index(admin: Admin, conn: DbConn, flash: Option<FlashMessage>) -> T
|
||||
|
||||
let articles = Article::load_all(true, &conn);
|
||||
|
||||
println!("{:?}", flash);
|
||||
context.insert("admin", &admin);
|
||||
context.insert("articles", &articles);
|
||||
context.insert("flash", &SerializeFlashMessage::from(&flash));
|
||||
@ -111,6 +110,12 @@ pub fn save_article(admin: Admin, conn: DbConn, article: Form<ArticleEditForm>)
|
||||
|
||||
Ok(Flash::new(Redirect::to("/admin"), "success", "created"))
|
||||
}
|
||||
#[delete("/article/<article_id>")]
|
||||
pub fn delete_article(admin: Admin, conn:DbConn, article_id: i32) -> Flash<Redirect> {
|
||||
use crate::schema::articles;
|
||||
diesel::delete(articles::table.filter(articles::id.eq(article_id))).execute(&*conn);
|
||||
Flash::new(Redirect::to("/admin"), "success", "deleted")
|
||||
}
|
||||
|
||||
#[post("/password", data = "<password_form>")]
|
||||
pub fn change_password(admin: Admin, conn: DbConn, password_form: Form<NewPasswordForm>) -> Flash<Redirect> {
|
||||
|
@ -22,7 +22,7 @@
|
||||
<td>{{ article.title }}</td>
|
||||
<td>{{ article.url }}</td>
|
||||
<td>{{ article.publish_at }}</td>
|
||||
<td><a href="/admin/article/{{ article.id }}">EDIT</a></td>
|
||||
<td><a href="/admin/article/{{ article.id }}">EDIT</a> <form action="/admin/article/{{ article.id }}" method="POST"> <input type="hidden" name="_method" value="DELETE"> <button>DELETE</button></form></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user