Add some delete functions back in

This commit is contained in:
Felix Ableitner 2020-08-11 19:51:55 +02:00
parent 4ab97fad4d
commit afdbed30e5
4 changed files with 11 additions and 8 deletions

View File

@ -55,8 +55,9 @@ impl Crud<CommentForm> for Comment {
comment.find(comment_id).first::<Self>(conn)
}
fn delete(_conn: &PgConnection, _comment_id: i32) -> Result<usize, Error> {
unimplemented!()
fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
use crate::schema::comment::dsl::*;
diesel::delete(comment.find(comment_id)).execute(conn)
}
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {

View File

@ -60,8 +60,9 @@ impl Crud<CommunityForm> for Community {
community.find(community_id).first::<Self>(conn)
}
fn delete(_conn: &PgConnection, _community_id: i32) -> Result<usize, Error> {
unimplemented!()
fn delete(conn: &PgConnection, community_id: i32) -> Result<usize, Error> {
use crate::schema::community::dsl::*;
diesel::delete(community.find(community_id)).execute(conn)
}
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {

View File

@ -162,8 +162,9 @@ impl Crud<PostForm> for Post {
post.find(post_id).first::<Self>(conn)
}
fn delete(_conn: &PgConnection, _post_id: i32) -> Result<usize, Error> {
unimplemented!()
fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> {
use crate::schema::post::dsl::*;
diesel::delete(post.find(post_id)).execute(conn)
}
fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {

View File

@ -70,8 +70,8 @@ impl Crud<UserForm> for User_ {
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
user_.find(user_id).first::<Self>(conn)
}
fn delete(_conn: &PgConnection, _user_id: i32) -> Result<usize, Error> {
unimplemented!()
fn delete(conn: &PgConnection, user_id: i32) -> Result<usize, Error> {
diesel::delete(user_.find(user_id)).execute(conn)
}
fn create(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
insert_into(user_).values(form).get_result::<Self>(conn)