Replace body of unused db functions with unimplemented!()

This commit is contained in:
Felix Ableitner 2020-08-11 15:52:03 +02:00
parent 714b5173d5
commit b597a13c83
13 changed files with 45 additions and 134 deletions

View File

@ -34,9 +34,8 @@ impl Crud<ActivityForm> for Activity {
activity.find(activity_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
use crate::schema::activity::dsl::*;
diesel::delete(activity.find(activity_id)).execute(conn)
fn delete(_conn: &PgConnection, _activity_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {

View File

@ -23,8 +23,8 @@ impl Crud<CategoryForm> for Category {
category.find(category_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, category_id: i32) -> Result<usize, Error> {
diesel::delete(category.find(category_id)).execute(conn)
fn delete(_conn: &PgConnection, _category_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, new_category: &CategoryForm) -> Result<Self, Error> {

View File

@ -55,9 +55,8 @@ impl Crud<CommentForm> for Comment {
comment.find(comment_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
use crate::schema::comment::dsl::*;
diesel::delete(comment.find(comment_id)).execute(conn)
fn delete(_conn: &PgConnection, _comment_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
@ -172,11 +171,8 @@ pub struct CommentLikeForm {
}
impl Likeable<CommentLikeForm> for CommentLike {
fn read(conn: &PgConnection, comment_id_from: i32) -> Result<Vec<Self>, Error> {
use crate::schema::comment_like::dsl::*;
comment_like
.filter(comment_id.eq(comment_id_from))
.load::<Self>(conn)
fn read(_conn: &PgConnection, _comment_id_from: i32) -> Result<Vec<Self>, Error> {
unimplemented!()
}
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {

View File

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

View File

@ -41,9 +41,8 @@ impl Crud<ModRemovePostForm> for ModRemovePost {
mod_remove_post.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_remove_post::dsl::*;
diesel::delete(mod_remove_post.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
@ -85,9 +84,8 @@ impl Crud<ModLockPostForm> for ModLockPost {
mod_lock_post.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_lock_post::dsl::*;
diesel::delete(mod_lock_post.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
@ -129,9 +127,8 @@ impl Crud<ModStickyPostForm> for ModStickyPost {
mod_sticky_post.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_sticky_post::dsl::*;
diesel::delete(mod_sticky_post.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
@ -175,9 +172,8 @@ impl Crud<ModRemoveCommentForm> for ModRemoveComment {
mod_remove_comment.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_remove_comment::dsl::*;
diesel::delete(mod_remove_comment.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
@ -223,9 +219,8 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
mod_remove_community.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_remove_community::dsl::*;
diesel::delete(mod_remove_community.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
@ -277,9 +272,8 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
mod_ban_from_community.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_ban_from_community::dsl::*;
diesel::delete(mod_ban_from_community.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
@ -329,9 +323,8 @@ impl Crud<ModBanForm> for ModBan {
mod_ban.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_ban::dsl::*;
diesel::delete(mod_ban.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
@ -373,9 +366,8 @@ impl Crud<ModAddCommunityForm> for ModAddCommunity {
mod_add_community.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_add_community::dsl::*;
diesel::delete(mod_add_community.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
@ -417,9 +409,8 @@ impl Crud<ModAddForm> for ModAdd {
mod_add.find(from_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use crate::schema::mod_add::dsl::*;
diesel::delete(mod_add.find(from_id)).execute(conn)
fn delete(_conn: &PgConnection, _from_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {

View File

@ -28,8 +28,8 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
.find(password_reset_request_id)
.first::<Self>(conn)
}
fn delete(conn: &PgConnection, password_reset_request_id: i32) -> Result<usize, Error> {
diesel::delete(password_reset_request.find(password_reset_request_id)).execute(conn)
fn delete(_conn: &PgConnection, _password_reset_request_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> {
insert_into(password_reset_request)

View File

@ -1,9 +1,8 @@
use crate::{
naive_now,
schema::{post, post_like, post_read, post_saved},
schema::{post, post_like, post_saved},
Crud,
Likeable,
Readable,
Saveable,
};
use diesel::{dsl::*, result::Error, *};
@ -163,9 +162,8 @@ impl Crud<PostForm> for Post {
post.find(post_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> {
use crate::schema::post::dsl::*;
diesel::delete(post.find(post_id)).execute(conn)
fn delete(_conn: &PgConnection, _post_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
@ -201,11 +199,8 @@ pub struct PostLikeForm {
}
impl Likeable<PostLikeForm> for PostLike {
fn read(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> {
use crate::schema::post_like::dsl::*;
post_like
.filter(post_id.eq(post_id_from))
.load::<Self>(conn)
fn read(_conn: &PgConnection, _post_id_from: i32) -> Result<Vec<Self>, Error> {
unimplemented!()
}
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use crate::schema::post_like::dsl::*;
@ -259,41 +254,6 @@ impl Saveable<PostSavedForm> for PostSaved {
}
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Post)]
#[table_name = "post_read"]
pub struct PostRead {
pub id: i32,
pub post_id: i32,
pub user_id: i32,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "post_read"]
pub struct PostReadForm {
pub post_id: i32,
pub user_id: i32,
}
impl Readable<PostReadForm> for PostRead {
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
use crate::schema::post_read::dsl::*;
insert_into(post_read)
.values(post_read_form)
.get_result::<Self>(conn)
}
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
use crate::schema::post_read::dsl::*;
diesel::delete(
post_read
.filter(post_id.eq(post_read_form.post_id))
.filter(user_id.eq(post_read_form.user_id)),
)
.execute(conn)
}
}
#[cfg(test)]
mod tests {
use crate::{
@ -436,26 +396,10 @@ mod tests {
published: inserted_post_saved.published,
};
// Post Read
let post_read_form = PostReadForm {
post_id: inserted_post.id,
user_id: inserted_user.id,
};
let inserted_post_read = PostRead::mark_as_read(&conn, &post_read_form).unwrap();
let expected_post_read = PostRead {
id: inserted_post_read.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
published: inserted_post_read.published,
};
let read_post = Post::read(&conn, inserted_post.id).unwrap();
let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap();
let like_removed = PostLike::remove(&conn, &post_like_form).unwrap();
let saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap();
let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
@ -465,10 +409,8 @@ mod tests {
assert_eq!(expected_post, updated_post);
assert_eq!(expected_post_like, inserted_post_like);
assert_eq!(expected_post_saved, inserted_post_saved);
assert_eq!(expected_post_read, inserted_post_read);
assert_eq!(1, like_removed);
assert_eq!(1, saved_removed);
assert_eq!(1, read_removed);
assert_eq!(1, num_deleted);
}
}

View File

@ -37,9 +37,8 @@ impl Crud<PrivateMessageForm> for PrivateMessage {
private_message.find(private_message_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, private_message_id: i32) -> Result<usize, Error> {
use crate::schema::private_message::dsl::*;
diesel::delete(private_message.find(private_message_id)).execute(conn)
fn delete(_conn: &PgConnection, _private_message_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {

View File

@ -359,15 +359,6 @@ table! {
}
}
table! {
post_read (id) {
id -> Int4,
post_id -> Int4,
user_id -> Int4,
published -> Timestamp,
}
}
table! {
post_saved (id) {
id -> Int4,
@ -513,8 +504,6 @@ joinable!(post -> community (community_id));
joinable!(post -> user_ (creator_id));
joinable!(post_like -> post (post_id));
joinable!(post_like -> user_ (user_id));
joinable!(post_read -> post (post_id));
joinable!(post_read -> user_ (user_id));
joinable!(post_saved -> post (post_id));
joinable!(post_saved -> user_ (user_id));
joinable!(site -> user_ (creator_id));
@ -547,7 +536,6 @@ allow_tables_to_appear_in_same_query!(
post,
post_aggregates_fast,
post_like,
post_read,
post_saved,
private_message,
site,

View File

@ -39,9 +39,8 @@ impl Crud<SiteForm> for Site {
site.first::<Self>(conn)
}
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
use crate::schema::site::dsl::*;
diesel::delete(site.find(site_id)).execute(conn)
fn delete(_conn: &PgConnection, _site_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, new_site: &SiteForm) -> 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> {
diesel::delete(user_.find(user_id)).execute(conn)
fn delete(_conn: &PgConnection, _user_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
insert_into(user_).values(form).get_result::<Self>(conn)

View File

@ -28,9 +28,8 @@ impl Crud<UserMentionForm> for UserMention {
user_mention.find(user_mention_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, user_mention_id: i32) -> Result<usize, Error> {
use crate::schema::user_mention::dsl::*;
diesel::delete(user_mention.find(user_mention_id)).execute(conn)
fn delete(_conn: &PgConnection, _user_mention_id: i32) -> Result<usize, Error> {
unimplemented!()
}
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {

View File

@ -159,9 +159,8 @@ impl<'a> UserQueryBuilder<'a> {
}
impl UserView {
pub fn read(conn: &PgConnection, from_user_id: i32) -> Result<Self, Error> {
use super::user_view::user_fast::dsl::*;
user_fast.find(from_user_id).first::<Self>(conn)
pub fn read(_conn: &PgConnection, _from_user_id: i32) -> Result<Self, Error> {
unimplemented!()
}
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {