Using Rust 2018 now.

- Fixes #170
This commit is contained in:
Dessalines 2019-06-03 10:47:12 -07:00
parent f59557e7ec
commit 7b7d85dc53
12 changed files with 106 additions and 105 deletions

View File

@ -2,6 +2,7 @@
name = "lemmy_server" name = "lemmy_server"
version = "0.0.1" version = "0.0.1"
authors = ["Dessalines <happydooby@gmail.com>"] authors = ["Dessalines <happydooby@gmail.com>"]
edition = "2018"
[dependencies] [dependencies]
diesel = { version = "1.4.2", features = ["postgres","chrono"] } diesel = { version = "1.4.2", features = ["postgres","chrono"] }

View File

@ -1,18 +1,18 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use failure::Error; use failure::Error;
use db::*; use crate::db::*;
use db::community::*; use crate::db::community::*;
use db::user::*; use crate::db::user::*;
use db::post::*; use crate::db::post::*;
use db::comment::*; use crate::db::comment::*;
use db::post_view::*; use crate::db::post_view::*;
use db::comment_view::*; use crate::db::comment_view::*;
use db::category::*; use crate::db::category::*;
use db::community_view::*; use crate::db::community_view::*;
use db::user_view::*; use crate::db::user_view::*;
use db::moderator_views::*; use crate::db::moderator_views::*;
use db::moderator::*; use crate::db::moderator::*;
use {has_slurs, remove_slurs, Settings, naive_now, naive_from_unix}; use crate::{has_slurs, remove_slurs, Settings, naive_now, naive_from_unix};
pub mod user; pub mod user;
pub mod community; pub mod community;

View File

@ -1,10 +1,10 @@
extern crate activitypub; extern crate activitypub;
use self::activitypub::{context, actor::Person}; use self::activitypub::{context, actor::Person};
use db::user::User_; use crate::db::user::User_;
impl User_ { impl User_ {
pub fn person(&self) -> Person { pub fn person(&self) -> Person {
use {Settings, to_datetime_utc}; use crate::{Settings, to_datetime_utc};
let base_url = &format!("{}/user/{}", Settings::get().api_endpoint(), self.name); let base_url = &format!("{}/user/{}", Settings::get().api_endpoint(), self.name);
let mut person = Person::default(); let mut person = Person::default();
person.object_props.set_context_object(context()).ok(); person.object_props.set_context_object(context()).ok();
@ -31,7 +31,7 @@ impl User_ {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::User_; use super::User_;
use naive_now; use crate::naive_now;
#[test] #[test]
fn test_person() { fn test_person() {

View File

@ -1,5 +1,5 @@
use schema::{category}; use crate::schema::{category};
use schema::category::dsl::*; use crate::schema::category::dsl::*;
use super::*; use super::*;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]

View File

@ -1,4 +1,4 @@
use schema::{comment, comment_like, comment_saved}; use crate::schema::{comment, comment_like, comment_saved};
use super::*; use super::*;
use super::post::Post; use super::post::Post;
@ -40,26 +40,26 @@ pub struct CommentForm {
impl Crud<CommentForm> for Comment { impl Crud<CommentForm> for Comment {
fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
use schema::comment::dsl::*; use crate::schema::comment::dsl::*;
comment.find(comment_id) comment.find(comment_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, comment_id: i32) -> Result<usize, Error> {
use schema::comment::dsl::*; use crate::schema::comment::dsl::*;
diesel::delete(comment.find(comment_id)) diesel::delete(comment.find(comment_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> { fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
use schema::comment::dsl::*; use crate::schema::comment::dsl::*;
insert_into(comment) insert_into(comment)
.values(comment_form) .values(comment_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, comment_id: i32, comment_form: &CommentForm) -> Result<Self, Error> { fn update(conn: &PgConnection, comment_id: i32, comment_form: &CommentForm) -> Result<Self, Error> {
use schema::comment::dsl::*; use crate::schema::comment::dsl::*;
diesel::update(comment.find(comment_id)) diesel::update(comment.find(comment_id))
.set(comment_form) .set(comment_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -89,20 +89,20 @@ pub struct CommentLikeForm {
impl Likeable <CommentLikeForm> for CommentLike { impl Likeable <CommentLikeForm> for CommentLike {
fn read(conn: &PgConnection, comment_id_from: i32) -> Result<Vec<Self>, Error> { fn read(conn: &PgConnection, comment_id_from: i32) -> Result<Vec<Self>, Error> {
use schema::comment_like::dsl::*; use crate::schema::comment_like::dsl::*;
comment_like comment_like
.filter(comment_id.eq(comment_id_from)) .filter(comment_id.eq(comment_id_from))
.load::<Self>(conn) .load::<Self>(conn)
} }
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> { fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
use schema::comment_like::dsl::*; use crate::schema::comment_like::dsl::*;
insert_into(comment_like) insert_into(comment_like)
.values(comment_like_form) .values(comment_like_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn remove(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<usize, Error> { fn remove(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<usize, Error> {
use schema::comment_like::dsl::*; use crate::schema::comment_like::dsl::*;
diesel::delete(comment_like diesel::delete(comment_like
.filter(comment_id.eq(comment_like_form.comment_id)) .filter(comment_id.eq(comment_like_form.comment_id))
.filter(user_id.eq(comment_like_form.user_id))) .filter(user_id.eq(comment_like_form.user_id)))
@ -112,7 +112,7 @@ impl Likeable <CommentLikeForm> for CommentLike {
impl CommentLike { impl CommentLike {
pub fn from_post(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> { pub fn from_post(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> {
use schema::comment_like::dsl::*; use crate::schema::comment_like::dsl::*;
comment_like comment_like
.filter(post_id.eq(post_id_from)) .filter(post_id.eq(post_id_from))
.load::<Self>(conn) .load::<Self>(conn)
@ -138,13 +138,13 @@ pub struct CommentSavedForm {
impl Saveable <CommentSavedForm> for CommentSaved { impl Saveable <CommentSavedForm> for CommentSaved {
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> { fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
use schema::comment_saved::dsl::*; use crate::schema::comment_saved::dsl::*;
insert_into(comment_saved) insert_into(comment_saved)
.values(comment_saved_form) .values(comment_saved_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> { fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
use schema::comment_saved::dsl::*; use crate::schema::comment_saved::dsl::*;
diesel::delete(comment_saved diesel::delete(comment_saved
.filter(comment_id.eq(comment_saved_form.comment_id)) .filter(comment_id.eq(comment_saved_form.comment_id))
.filter(user_id.eq(comment_saved_form.user_id))) .filter(user_id.eq(comment_saved_form.user_id)))

View File

@ -1,4 +1,4 @@
use schema::{community, community_moderator, community_follower, community_user_ban, site}; use crate::schema::{community, community_moderator, community_follower, community_user_ban, site};
use super::*; use super::*;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
@ -31,26 +31,26 @@ pub struct CommunityForm {
impl Crud<CommunityForm> for Community { impl Crud<CommunityForm> for Community {
fn read(conn: &PgConnection, community_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, community_id: i32) -> Result<Self, Error> {
use schema::community::dsl::*; use crate::schema::community::dsl::*;
community.find(community_id) community.find(community_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, community_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, community_id: i32) -> Result<usize, Error> {
use schema::community::dsl::*; use crate::schema::community::dsl::*;
diesel::delete(community.find(community_id)) diesel::delete(community.find(community_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
use schema::community::dsl::*; use crate::schema::community::dsl::*;
insert_into(community) insert_into(community)
.values(new_community) .values(new_community)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, community_id: i32, new_community: &CommunityForm) -> Result<Self, Error> { fn update(conn: &PgConnection, community_id: i32, new_community: &CommunityForm) -> Result<Self, Error> {
use schema::community::dsl::*; use crate::schema::community::dsl::*;
diesel::update(community.find(community_id)) diesel::update(community.find(community_id))
.set(new_community) .set(new_community)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -59,7 +59,7 @@ impl Crud<CommunityForm> for Community {
impl Community { impl Community {
pub fn read_from_name(conn: &PgConnection, community_name: String) -> Result<Self, Error> { pub fn read_from_name(conn: &PgConnection, community_name: String) -> Result<Self, Error> {
use schema::community::dsl::*; use crate::schema::community::dsl::*;
community.filter(name.eq(community_name)) community.filter(name.eq(community_name))
.first::<Self>(conn) .first::<Self>(conn)
} }
@ -84,14 +84,14 @@ pub struct CommunityModeratorForm {
impl Joinable<CommunityModeratorForm> for CommunityModerator { impl Joinable<CommunityModeratorForm> for CommunityModerator {
fn join(conn: &PgConnection, community_user_form: &CommunityModeratorForm) -> Result<Self, Error> { fn join(conn: &PgConnection, community_user_form: &CommunityModeratorForm) -> Result<Self, Error> {
use schema::community_moderator::dsl::*; use crate::schema::community_moderator::dsl::*;
insert_into(community_moderator) insert_into(community_moderator)
.values(community_user_form) .values(community_user_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn leave(conn: &PgConnection, community_user_form: &CommunityModeratorForm) -> Result<usize, Error> { fn leave(conn: &PgConnection, community_user_form: &CommunityModeratorForm) -> Result<usize, Error> {
use schema::community_moderator::dsl::*; use crate::schema::community_moderator::dsl::*;
diesel::delete(community_moderator diesel::delete(community_moderator
.filter(community_id.eq(community_user_form.community_id)) .filter(community_id.eq(community_user_form.community_id))
.filter(user_id.eq(community_user_form.user_id))) .filter(user_id.eq(community_user_form.user_id)))
@ -118,14 +118,14 @@ pub struct CommunityUserBanForm {
impl Bannable<CommunityUserBanForm> for CommunityUserBan { impl Bannable<CommunityUserBanForm> for CommunityUserBan {
fn ban(conn: &PgConnection, community_user_ban_form: &CommunityUserBanForm) -> Result<Self, Error> { fn ban(conn: &PgConnection, community_user_ban_form: &CommunityUserBanForm) -> Result<Self, Error> {
use schema::community_user_ban::dsl::*; use crate::schema::community_user_ban::dsl::*;
insert_into(community_user_ban) insert_into(community_user_ban)
.values(community_user_ban_form) .values(community_user_ban_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn unban(conn: &PgConnection, community_user_ban_form: &CommunityUserBanForm) -> Result<usize, Error> { fn unban(conn: &PgConnection, community_user_ban_form: &CommunityUserBanForm) -> Result<usize, Error> {
use schema::community_user_ban::dsl::*; use crate::schema::community_user_ban::dsl::*;
diesel::delete(community_user_ban diesel::delete(community_user_ban
.filter(community_id.eq(community_user_ban_form.community_id)) .filter(community_id.eq(community_user_ban_form.community_id))
.filter(user_id.eq(community_user_ban_form.user_id))) .filter(user_id.eq(community_user_ban_form.user_id)))
@ -152,13 +152,13 @@ pub struct CommunityFollowerForm {
impl Followable<CommunityFollowerForm> for CommunityFollower { impl Followable<CommunityFollowerForm> for CommunityFollower {
fn follow(conn: &PgConnection, community_follower_form: &CommunityFollowerForm) -> Result<Self, Error> { fn follow(conn: &PgConnection, community_follower_form: &CommunityFollowerForm) -> Result<Self, Error> {
use schema::community_follower::dsl::*; use crate::schema::community_follower::dsl::*;
insert_into(community_follower) insert_into(community_follower)
.values(community_follower_form) .values(community_follower_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn ignore(conn: &PgConnection, community_follower_form: &CommunityFollowerForm) -> Result<usize, Error> { fn ignore(conn: &PgConnection, community_follower_form: &CommunityFollowerForm) -> Result<usize, Error> {
use schema::community_follower::dsl::*; use crate::schema::community_follower::dsl::*;
diesel::delete(community_follower diesel::delete(community_follower
.filter(community_id.eq(&community_follower_form.community_id)) .filter(community_id.eq(&community_follower_form.community_id))
.filter(user_id.eq(&community_follower_form.user_id))) .filter(user_id.eq(&community_follower_form.user_id)))
@ -188,25 +188,25 @@ pub struct SiteForm {
impl Crud<SiteForm> for Site { impl Crud<SiteForm> for Site {
fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
use schema::site::dsl::*; use crate::schema::site::dsl::*;
site.first::<Self>(conn) site.first::<Self>(conn)
} }
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
use schema::site::dsl::*; use crate::schema::site::dsl::*;
diesel::delete(site.find(site_id)) diesel::delete(site.find(site_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
use schema::site::dsl::*; use crate::schema::site::dsl::*;
insert_into(site) insert_into(site)
.values(new_site) .values(new_site)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> { fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
use schema::site::dsl::*; use crate::schema::site::dsl::*;
diesel::update(site.find(site_id)) diesel::update(site.find(site_id))
.set(new_site) .set(new_site)
.get_result::<Self>(conn) .get_result::<Self>(conn)

View File

@ -1,7 +1,7 @@
use diesel::*; use diesel::*;
use diesel::dsl::*; use diesel::dsl::*;
use diesel::result::Error; use diesel::result::Error;
use {Settings}; use crate::{Settings};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod user; pub mod user;

View File

@ -1,4 +1,4 @@
use schema::{mod_remove_post, mod_lock_post, mod_remove_comment, mod_remove_community, mod_ban_from_community, mod_ban, mod_add_community, mod_add}; use crate::schema::{mod_remove_post, mod_lock_post, mod_remove_comment, mod_remove_community, mod_ban_from_community, mod_ban, mod_add_community, mod_add};
use super::*; use super::*;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
@ -23,26 +23,26 @@ pub struct ModRemovePostForm {
impl Crud<ModRemovePostForm> for ModRemovePost { impl Crud<ModRemovePostForm> for ModRemovePost {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_remove_post::dsl::*; use crate::schema::mod_remove_post::dsl::*;
mod_remove_post.find(from_id) mod_remove_post.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_remove_post::dsl::*; use crate::schema::mod_remove_post::dsl::*;
diesel::delete(mod_remove_post.find(from_id)) diesel::delete(mod_remove_post.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
use schema::mod_remove_post::dsl::*; use crate::schema::mod_remove_post::dsl::*;
insert_into(mod_remove_post) insert_into(mod_remove_post)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
use schema::mod_remove_post::dsl::*; use crate::schema::mod_remove_post::dsl::*;
diesel::update(mod_remove_post.find(from_id)) diesel::update(mod_remove_post.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -71,26 +71,26 @@ pub struct ModLockPostForm {
impl Crud<ModLockPostForm> for ModLockPost { impl Crud<ModLockPostForm> for ModLockPost {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_lock_post::dsl::*; use crate::schema::mod_lock_post::dsl::*;
mod_lock_post.find(from_id) mod_lock_post.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_lock_post::dsl::*; use crate::schema::mod_lock_post::dsl::*;
diesel::delete(mod_lock_post.find(from_id)) diesel::delete(mod_lock_post.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
use schema::mod_lock_post::dsl::*; use crate::schema::mod_lock_post::dsl::*;
insert_into(mod_lock_post) insert_into(mod_lock_post)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
use schema::mod_lock_post::dsl::*; use crate::schema::mod_lock_post::dsl::*;
diesel::update(mod_lock_post.find(from_id)) diesel::update(mod_lock_post.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -119,26 +119,26 @@ pub struct ModRemoveCommentForm {
impl Crud<ModRemoveCommentForm> for ModRemoveComment { impl Crud<ModRemoveCommentForm> for ModRemoveComment {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_remove_comment::dsl::*; use crate::schema::mod_remove_comment::dsl::*;
mod_remove_comment.find(from_id) mod_remove_comment.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_remove_comment::dsl::*; use crate::schema::mod_remove_comment::dsl::*;
diesel::delete(mod_remove_comment.find(from_id)) diesel::delete(mod_remove_comment.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
use schema::mod_remove_comment::dsl::*; use crate::schema::mod_remove_comment::dsl::*;
insert_into(mod_remove_comment) insert_into(mod_remove_comment)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
use schema::mod_remove_comment::dsl::*; use crate::schema::mod_remove_comment::dsl::*;
diesel::update(mod_remove_comment.find(from_id)) diesel::update(mod_remove_comment.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -169,26 +169,26 @@ pub struct ModRemoveCommunityForm {
impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity { impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_remove_community::dsl::*; use crate::schema::mod_remove_community::dsl::*;
mod_remove_community.find(from_id) mod_remove_community.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_remove_community::dsl::*; use crate::schema::mod_remove_community::dsl::*;
diesel::delete(mod_remove_community.find(from_id)) diesel::delete(mod_remove_community.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
use schema::mod_remove_community::dsl::*; use crate::schema::mod_remove_community::dsl::*;
insert_into(mod_remove_community) insert_into(mod_remove_community)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommunityForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
use schema::mod_remove_community::dsl::*; use crate::schema::mod_remove_community::dsl::*;
diesel::update(mod_remove_community.find(from_id)) diesel::update(mod_remove_community.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -221,26 +221,26 @@ pub struct ModBanFromCommunityForm {
impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity { impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_ban_from_community::dsl::*; use crate::schema::mod_ban_from_community::dsl::*;
mod_ban_from_community.find(from_id) mod_ban_from_community.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_ban_from_community::dsl::*; use crate::schema::mod_ban_from_community::dsl::*;
diesel::delete(mod_ban_from_community.find(from_id)) diesel::delete(mod_ban_from_community.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
use schema::mod_ban_from_community::dsl::*; use crate::schema::mod_ban_from_community::dsl::*;
insert_into(mod_ban_from_community) insert_into(mod_ban_from_community)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModBanFromCommunityForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
use schema::mod_ban_from_community::dsl::*; use crate::schema::mod_ban_from_community::dsl::*;
diesel::update(mod_ban_from_community.find(from_id)) diesel::update(mod_ban_from_community.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -272,26 +272,26 @@ pub struct ModBanForm {
impl Crud<ModBanForm> for ModBan { impl Crud<ModBanForm> for ModBan {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_ban::dsl::*; use crate::schema::mod_ban::dsl::*;
mod_ban.find(from_id) mod_ban.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_ban::dsl::*; use crate::schema::mod_ban::dsl::*;
diesel::delete(mod_ban.find(from_id)) diesel::delete(mod_ban.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
use schema::mod_ban::dsl::*; use crate::schema::mod_ban::dsl::*;
insert_into(mod_ban) insert_into(mod_ban)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
use schema::mod_ban::dsl::*; use crate::schema::mod_ban::dsl::*;
diesel::update(mod_ban.find(from_id)) diesel::update(mod_ban.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -320,26 +320,26 @@ pub struct ModAddCommunityForm {
impl Crud<ModAddCommunityForm> for ModAddCommunity { impl Crud<ModAddCommunityForm> for ModAddCommunity {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_add_community::dsl::*; use crate::schema::mod_add_community::dsl::*;
mod_add_community.find(from_id) mod_add_community.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_add_community::dsl::*; use crate::schema::mod_add_community::dsl::*;
diesel::delete(mod_add_community.find(from_id)) diesel::delete(mod_add_community.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
use schema::mod_add_community::dsl::*; use crate::schema::mod_add_community::dsl::*;
insert_into(mod_add_community) insert_into(mod_add_community)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
use schema::mod_add_community::dsl::*; use crate::schema::mod_add_community::dsl::*;
diesel::update(mod_add_community.find(from_id)) diesel::update(mod_add_community.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -366,26 +366,26 @@ pub struct ModAddForm {
impl Crud<ModAddForm> for ModAdd { impl Crud<ModAddForm> for ModAdd {
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
use schema::mod_add::dsl::*; use crate::schema::mod_add::dsl::*;
mod_add.find(from_id) mod_add.find(from_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
use schema::mod_add::dsl::*; use crate::schema::mod_add::dsl::*;
diesel::delete(mod_add.find(from_id)) diesel::delete(mod_add.find(from_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> { fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
use schema::mod_add::dsl::*; use crate::schema::mod_add::dsl::*;
insert_into(mod_add) insert_into(mod_add)
.values(form) .values(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> { fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
use schema::mod_add::dsl::*; use crate::schema::mod_add::dsl::*;
diesel::update(mod_add.find(from_id)) diesel::update(mod_add.find(from_id))
.set(form) .set(form)
.get_result::<Self>(conn) .get_result::<Self>(conn)

View File

@ -1,4 +1,4 @@
use schema::{post, post_like, post_saved, post_read}; use crate::schema::{post, post_like, post_saved, post_read};
use super::*; use super::*;
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)] #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
@ -33,26 +33,26 @@ pub struct PostForm {
impl Crud<PostForm> for Post { impl Crud<PostForm> for Post {
fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
use schema::post::dsl::*; use crate::schema::post::dsl::*;
post.find(post_id) post.find(post_id)
.first::<Self>(conn) .first::<Self>(conn)
} }
fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> { fn delete(conn: &PgConnection, post_id: i32) -> Result<usize, Error> {
use schema::post::dsl::*; use crate::schema::post::dsl::*;
diesel::delete(post.find(post_id)) diesel::delete(post.find(post_id))
.execute(conn) .execute(conn)
} }
fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> { fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
use schema::post::dsl::*; use crate::schema::post::dsl::*;
insert_into(post) insert_into(post)
.values(new_post) .values(new_post)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn update(conn: &PgConnection, post_id: i32, new_post: &PostForm) -> Result<Self, Error> { fn update(conn: &PgConnection, post_id: i32, new_post: &PostForm) -> Result<Self, Error> {
use schema::post::dsl::*; use crate::schema::post::dsl::*;
diesel::update(post.find(post_id)) diesel::update(post.find(post_id))
.set(new_post) .set(new_post)
.get_result::<Self>(conn) .get_result::<Self>(conn)
@ -80,19 +80,19 @@ pub struct PostLikeForm {
impl Likeable <PostLikeForm> for PostLike { impl Likeable <PostLikeForm> for PostLike {
fn read(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> { fn read(conn: &PgConnection, post_id_from: i32) -> Result<Vec<Self>, Error> {
use schema::post_like::dsl::*; use crate::schema::post_like::dsl::*;
post_like post_like
.filter(post_id.eq(post_id_from)) .filter(post_id.eq(post_id_from))
.load::<Self>(conn) .load::<Self>(conn)
} }
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> { fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use schema::post_like::dsl::*; use crate::schema::post_like::dsl::*;
insert_into(post_like) insert_into(post_like)
.values(post_like_form) .values(post_like_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn remove(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<usize, Error> { fn remove(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<usize, Error> {
use schema::post_like::dsl::*; use crate::schema::post_like::dsl::*;
diesel::delete(post_like diesel::delete(post_like
.filter(post_id.eq(post_like_form.post_id)) .filter(post_id.eq(post_like_form.post_id))
.filter(user_id.eq(post_like_form.user_id))) .filter(user_id.eq(post_like_form.user_id)))
@ -119,13 +119,13 @@ pub struct PostSavedForm {
impl Saveable <PostSavedForm> for PostSaved { impl Saveable <PostSavedForm> for PostSaved {
fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> { fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
use schema::post_saved::dsl::*; use crate::schema::post_saved::dsl::*;
insert_into(post_saved) insert_into(post_saved)
.values(post_saved_form) .values(post_saved_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> { fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
use schema::post_saved::dsl::*; use crate::schema::post_saved::dsl::*;
diesel::delete(post_saved diesel::delete(post_saved
.filter(post_id.eq(post_saved_form.post_id)) .filter(post_id.eq(post_saved_form.post_id))
.filter(user_id.eq(post_saved_form.user_id))) .filter(user_id.eq(post_saved_form.user_id)))
@ -152,13 +152,13 @@ pub struct PostReadForm {
impl Readable <PostReadForm> for PostRead { impl Readable <PostReadForm> for PostRead {
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> { fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
use schema::post_read::dsl::*; use crate::schema::post_read::dsl::*;
insert_into(post_read) insert_into(post_read)
.values(post_read_form) .values(post_read_form)
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> { fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
use schema::post_read::dsl::*; use crate::schema::post_read::dsl::*;
diesel::delete(post_read diesel::delete(post_read
.filter(post_id.eq(post_read_form.post_id)) .filter(post_id.eq(post_read_form.post_id))
.filter(user_id.eq(post_read_form.user_id))) .filter(user_id.eq(post_read_form.user_id)))

View File

@ -1,7 +1,7 @@
use schema::user_; use crate::schema::user_;
use schema::user_::dsl::*; use crate::schema::user_::dsl::*;
use super::*; use super::*;
use {Settings, is_email_regex}; use crate::{Settings, is_email_regex};
use jsonwebtoken::{encode, decode, Header, Validation, TokenData}; use jsonwebtoken::{encode, decode, Header, Validation, TokenData};
use bcrypt::{DEFAULT_COST, hash}; use bcrypt::{DEFAULT_COST, hash};
@ -36,7 +36,7 @@ pub struct UserForm {
impl Crud<UserForm> for User_ { impl Crud<UserForm> for User_ {
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
use schema::user_::dsl::*; use crate::schema::user_::dsl::*;
user_.find(user_id) user_.find(user_id)
.first::<Self>(conn) .first::<Self>(conn)
} }

View File

@ -72,7 +72,7 @@ pub fn has_slurs(test: &str) -> bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use {Settings, is_email_regex, remove_slurs, has_slurs}; use crate::{Settings, is_email_regex, remove_slurs, has_slurs};
#[test] #[test]
fn test_api() { fn test_api() {
assert_eq!(Settings::get().api_endpoint(), "rrr/api/v1"); assert_eq!(Settings::get().api_endpoint(), "rrr/api/v1");

View File

@ -11,12 +11,12 @@ use std::str::FromStr;
use failure::Error; use failure::Error;
use std::time::{SystemTime}; use std::time::{SystemTime};
use api::*; use crate::api::*;
use api::user::*; use crate::api::user::*;
use api::community::*; use crate::api::community::*;
use api::post::*; use crate::api::post::*;
use api::comment::*; use crate::api::comment::*;
use api::site::*; use crate::api::site::*;
const RATE_LIMIT_MESSAGES: i32 = 30; const RATE_LIMIT_MESSAGES: i32 = 30;
const RATE_LIMIT_PER_SECOND: i32 = 60; const RATE_LIMIT_PER_SECOND: i32 = 60;
@ -118,7 +118,7 @@ impl ChatServer {
fn join_room(&mut self, room_id: i32, id: usize) { fn join_room(&mut self, room_id: i32, id: usize) {
// remove session from all rooms // remove session from all rooms
for (_n, mut sessions) in &mut self.rooms { for (_n, sessions) in &mut self.rooms {
sessions.remove(&id); sessions.remove(&id);
} }
@ -131,8 +131,8 @@ impl ChatServer {
} }
fn send_community_message(&self, community_id: &i32, message: &str, skip_id: usize) -> Result<(), Error> { fn send_community_message(&self, community_id: &i32, message: &str, skip_id: usize) -> Result<(), Error> {
use db::*; use crate::db::*;
use db::post_view::*; use crate::db::post_view::*;
let conn = establish_connection(); let conn = establish_connection();
let posts = PostView::list(&conn, let posts = PostView::list(&conn,
PostListingType::Community, PostListingType::Community,