mirror of https://github.com/LemmyNet/lemmy
Merge remote-tracking branch 'origin/split-db-workspace' into move_views_to_diesel_split
commit
1a0d1f64f0
@ -1,71 +1,45 @@
|
||||
use crate::{naive_now, schema::site, Crud};
|
||||
use crate::Crud;
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
|
||||
#[table_name = "site"]
|
||||
pub struct Site {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub creator_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub enable_downvotes: bool,
|
||||
pub open_registration: bool,
|
||||
pub enable_nsfw: bool,
|
||||
pub icon: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "site"]
|
||||
pub struct SiteForm {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub creator_id: i32,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub enable_downvotes: bool,
|
||||
pub open_registration: bool,
|
||||
pub enable_nsfw: bool,
|
||||
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
||||
pub icon: Option<Option<String>>,
|
||||
pub banner: Option<Option<String>>,
|
||||
}
|
||||
use lemmy_db_schema::{naive_now, source::site::*};
|
||||
|
||||
impl Crud<SiteForm> for Site {
|
||||
fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
|
||||
use crate::schema::site::dsl::*;
|
||||
use lemmy_db_schema::schema::site::dsl::*;
|
||||
site.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
|
||||
use crate::schema::site::dsl::*;
|
||||
use lemmy_db_schema::schema::site::dsl::*;
|
||||
insert_into(site).values(new_site).get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
|
||||
use crate::schema::site::dsl::*;
|
||||
use lemmy_db_schema::schema::site::dsl::*;
|
||||
diesel::update(site.find(site_id))
|
||||
.set(new_site)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
|
||||
use crate::schema::site::dsl::*;
|
||||
use lemmy_db_schema::schema::site::dsl::*;
|
||||
diesel::delete(site.find(site_id)).execute(conn)
|
||||
}
|
||||
}
|
||||
|
||||
impl Site {
|
||||
pub fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Self, Error> {
|
||||
use crate::schema::site::dsl::*;
|
||||
pub trait Site_ {
|
||||
fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error>;
|
||||
fn read_simple(conn: &PgConnection) -> Result<Site, Error>;
|
||||
}
|
||||
|
||||
impl Site_ for Site {
|
||||
fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error> {
|
||||
use lemmy_db_schema::schema::site::dsl::*;
|
||||
diesel::update(site.find(1))
|
||||
.set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
pub fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
|
||||
use crate::schema::site::dsl::*;
|
||||
fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::site::dsl::*;
|
||||
site.first::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "lemmy_db_schema"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
serde = { version = "1.0.118", features = ["derive"] }
|
||||
serde_json = { version = "1.0.60", features = ["preserve_order"] }
|
||||
log = "0.4.11"
|
||||
url = { version = "2.2.0", features = ["serde"] }
|
@ -0,0 +1,12 @@
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
pub mod schema;
|
||||
pub mod source;
|
||||
|
||||
// TODO: can probably move this back to lemmy_db
|
||||
pub fn naive_now() -> NaiveDateTime {
|
||||
chrono::prelude::Utc::now().naive_utc()
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
use crate::schema::activity;
|
||||
use serde_json::Value;
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug)]
|
||||
#[table_name = "activity"]
|
||||
pub struct Activity {
|
||||
pub id: i32,
|
||||
pub data: Value,
|
||||
pub local: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub ap_id: Option<String>,
|
||||
pub sensitive: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "activity"]
|
||||
pub struct ActivityForm {
|
||||
pub data: Value,
|
||||
pub local: bool,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub ap_id: String,
|
||||
pub sensitive: bool,
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
use crate::schema::category;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
||||
#[table_name = "category"]
|
||||
pub struct Category {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "category"]
|
||||
pub struct CategoryForm {
|
||||
pub name: String,
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
use crate::{
|
||||
schema::{comment, comment_alias_1, comment_like, comment_saved},
|
||||
source::post::Post,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use url::{ParseError, Url};
|
||||
|
||||
// WITH RECURSIVE MyTree AS (
|
||||
// SELECT * FROM comment WHERE parent_id IS NULL
|
||||
// UNION ALL
|
||||
// SELECT m.* FROM comment AS m JOIN MyTree AS t ON m.parent_id = t.id
|
||||
// )
|
||||
// SELECT * FROM MyTree;
|
||||
|
||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[belongs_to(Post)]
|
||||
#[table_name = "comment"]
|
||||
pub struct Comment {
|
||||
pub id: i32,
|
||||
pub creator_id: i32,
|
||||
pub post_id: i32,
|
||||
pub parent_id: Option<i32>,
|
||||
pub content: String,
|
||||
pub removed: bool,
|
||||
pub read: bool, // Whether the recipient has read the comment or not
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: bool,
|
||||
pub ap_id: String,
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[belongs_to(Post)]
|
||||
#[table_name = "comment_alias_1"]
|
||||
pub struct CommentAlias1 {
|
||||
pub id: i32,
|
||||
pub creator_id: i32,
|
||||
pub post_id: i32,
|
||||
pub parent_id: Option<i32>,
|
||||
pub content: String,
|
||||
pub removed: bool,
|
||||
pub read: bool, // Whether the recipient has read the comment or not
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: bool,
|
||||
pub ap_id: String,
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "comment"]
|
||||
pub struct CommentForm {
|
||||
pub creator_id: i32,
|
||||
pub post_id: i32,
|
||||
pub parent_id: Option<i32>,
|
||||
pub content: String,
|
||||
pub removed: Option<bool>,
|
||||
pub read: Option<bool>,
|
||||
pub published: Option<chrono::NaiveDateTime>,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: Option<bool>,
|
||||
pub ap_id: Option<String>,
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
impl CommentForm {
|
||||
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
|
||||
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)]
|
||||
#[belongs_to(Comment)]
|
||||
#[table_name = "comment_like"]
|
||||
pub struct CommentLike {
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub post_id: i32, // TODO this is redundant
|
||||
pub score: i16,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "comment_like"]
|
||||
pub struct CommentLikeForm {
|
||||
pub user_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub post_id: i32, // TODO this is redundant
|
||||
pub score: i16,
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||
#[belongs_to(Comment)]
|
||||
#[table_name = "comment_saved"]
|
||||
pub struct CommentSaved {
|
||||
pub id: i32,
|
||||
pub comment_id: i32,
|
||||
pub user_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "comment_saved"]
|
||||
pub struct CommentSavedForm {
|
||||
pub comment_id: i32,
|
||||
pub user_id: i32,
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
use crate::{schema::comment_report, source::comment::Comment};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
|
||||
)]
|
||||
#[belongs_to(Comment)]
|
||||
#[table_name = "comment_report"]
|
||||
pub struct CommentReport {
|
||||
pub id: i32,
|
||||
pub creator_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub original_comment_text: String,
|
||||
pub reason: String,
|
||||
pub resolved: bool,
|
||||
pub resolver_id: Option<i32>,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "comment_report"]
|
||||
pub struct CommentReportForm {
|
||||
pub creator_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub original_comment_text: String,
|
||||
pub reason: String,
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
use crate::schema::{community, community_follower, community_moderator, community_user_ban};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "community"]
|
||||
pub struct Community {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub category_id: i32,
|
||||
pub creator_id: i32,
|
||||
pub removed: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: bool,
|
||||
pub nsfw: bool,
|
||||
pub actor_id: String,
|
||||
pub local: bool,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub icon: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
}
|
||||
|
||||
/// A safe representation of community, without the sensitive info
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "community"]
|
||||
pub struct CommunitySafe {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub category_id: i32,
|
||||
pub creator_id: i32,
|
||||
pub removed: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: bool,
|
||||
pub nsfw: bool,
|
||||
pub actor_id: String,
|
||||
pub local: bool,
|
||||
pub icon: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Debug)]
|
||||
#[table_name = "community"]
|
||||
pub struct CommunityForm {
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub category_id: i32,
|
||||
pub creator_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
pub published: Option<chrono::NaiveDateTime>,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: Option<bool>,
|
||||
pub nsfw: bool,
|
||||
pub actor_id: Option<String>,
|
||||
pub local: bool,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: Option<chrono::NaiveDateTime>,
|
||||
pub icon: Option<Option<String>>,
|
||||
pub banner: Option<Option<String>>,
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||
#[belongs_to(Community)]
|
||||
#[table_name = "community_moderator"]
|
||||
pub struct CommunityModerator {
|
||||
pub id: i32,
|
||||
pub community_id: i32,
|
||||
pub user_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "community_moderator"]
|
||||
pub struct CommunityModeratorForm {
|
||||
pub community_id: i32,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||
#[belongs_to(Community)]
|
||||
#[table_name = "community_user_ban"]
|
||||
pub struct CommunityUserBan {
|
||||
pub id: i32,
|
||||
pub community_id: i32,
|
||||
pub user_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "community_user_ban"]
|
||||
pub struct CommunityUserBanForm {
|
||||
pub community_id: i32,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||
#[belongs_to(Community)]
|
||||
#[table_name = "community_follower"]
|
||||
pub struct CommunityFollower {
|
||||
pub id: i32,
|
||||
pub community_id: i32,
|
||||
pub user_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub pending: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "community_follower"]
|
||||
pub struct CommunityFollowerForm {
|
||||
pub community_id: i32,
|
||||
pub user_id: i32,
|
||||
pub pending: bool,
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
pub mod activity;
|
||||
pub mod category;
|
||||
pub mod comment;
|
||||
pub mod comment_report;
|
||||
pub mod community;
|
||||
pub mod moderator;
|
||||
pub mod password_reset_request;
|
||||
pub mod post;
|
||||
pub mod post_report;
|
||||
pub mod private_message;
|
||||
pub mod site;
|
||||
pub mod user;
|
||||
pub mod user_mention;
|
@ -0,0 +1,194 @@
|
||||
use crate::schema::{
|
||||
mod_add,
|
||||
mod_add_community,
|
||||
mod_ban,
|
||||
mod_ban_from_community,
|
||||
mod_lock_post,
|
||||
mod_remove_comment,
|
||||
mod_remove_community,
|
||||
mod_remove_post,
|
||||
mod_sticky_post,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_remove_post"]
|
||||
pub struct ModRemovePost {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_remove_post"]
|
||||
pub struct ModRemovePostForm {
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_lock_post"]
|
||||
pub struct ModLockPost {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub locked: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_lock_post"]
|
||||
pub struct ModLockPostForm {
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub locked: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_sticky_post"]
|
||||
pub struct ModStickyPost {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub stickied: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_sticky_post"]
|
||||
pub struct ModStickyPostForm {
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub stickied: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_remove_comment"]
|
||||
pub struct ModRemoveComment {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_remove_comment"]
|
||||
pub struct ModRemoveCommentForm {
|
||||
pub mod_user_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_remove_community"]
|
||||
pub struct ModRemoveCommunity {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_remove_community"]
|
||||
pub struct ModRemoveCommunityForm {
|
||||
pub mod_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_ban_from_community"]
|
||||
pub struct ModBanFromCommunity {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub banned: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_ban_from_community"]
|
||||
pub struct ModBanFromCommunityForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub banned: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_ban"]
|
||||
pub struct ModBan {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub banned: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_ban"]
|
||||
pub struct ModBanForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub banned: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_add_community"]
|
||||
pub struct ModAddCommunity {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_add_community"]
|
||||
pub struct ModAddCommunityForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "mod_add"]
|
||||
pub struct ModAdd {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "mod_add"]
|
||||
pub struct ModAddForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
use crate::schema::password_reset_request;
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug)]
|
||||
#[table_name = "password_reset_request"]
|
||||
pub struct PasswordResetRequest {
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
pub token_encrypted: String,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "password_reset_request"]
|
||||
pub struct PasswordResetRequestForm {
|
||||
pub user_id: i32,
|
||||
pub token_encrypted: String,
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
use crate::schema::{post, post_like, post_read, post_saved};
|
||||
use serde::Serialize;
|
||||
use url::{ParseError, Url};
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "post"]
|
||||
pub struct Post {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub url: Option<String>,
|
||||
pub body: Option<String>,
|
||||
pub creator_id: i32,
|
||||
pub community_id: i32,
|
||||
pub removed: bool,
|
||||
pub locked: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: bool,
|
||||
pub nsfw: bool,
|
||||
pub stickied: bool,
|
||||
pub embed_title: Option<String>,
|
||||
pub embed_description: Option<String>,
|
||||
pub embed_html: Option<String>,
|
||||
pub thumbnail_url: Option<String>,
|
||||
pub ap_id: String,
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "post"]
|
||||
pub struct PostForm {
|
||||
pub name: String,
|
||||
pub url: Option<String>,
|
||||
pub body: Option<String>,
|
||||
pub creator_id: i32,
|
||||
pub community_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
pub locked: Option<bool>,
|
||||
pub published: Option<chrono::NaiveDateTime>,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: Option<bool>,
|
||||
pub nsfw: bool,
|
||||
pub stickied: Option<bool>,
|
||||
pub embed_title: Option<String>,
|
||||
pub embed_description: Option<String>,
|
||||
pub embed_html: Option<String>,
|
||||
pub thumbnail_url: Option<String>,
|
||||
pub ap_id: Option<String>,
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
impl PostForm {
|
||||
pub fn get_ap_id(&self) -> Result<Url, ParseError> {
|
||||
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||
#[belongs_to(Post)]
|
||||
#[table_name = "post_like"]
|
||||
pub struct PostLike {
|
||||
pub id: i32,
|
||||
pub post_id: i32,
|
||||
pub user_id: i32,
|
||||
pub score: i16,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "post_like"]
|
||||
pub struct PostLikeForm {
|
||||
pub post_id: i32,
|
||||
pub user_id: i32,
|
||||
pub score: i16,
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||
#[belongs_to(Post)]
|
||||
#[table_name = "post_saved"]
|
||||
pub struct PostSaved {
|
||||
pub id: i32,
|
||||
pub post_id: i32,
|
||||
pub user_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "post_saved"]
|
||||
pub struct PostSavedForm {
|
||||
pub post_id: i32,
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
#[table_name = "post_read"]
|
||||
pub struct PostReadForm {
|
||||
pub post_id: i32,
|
||||
|
||||
pub user_id: i32,
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
use crate::{schema::post_report, source::post::Post};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(
|
||||
Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
|
||||
)]
|
||||
#[belongs_to(Post)]
|
||||
#[table_name = "post_report"]
|
||||
pub struct PostReport {
|
||||
pub id: i32,
|
||||
pub creator_id: i32,
|
||||
pub post_id: i32,
|
||||
pub original_post_name: String,
|
||||
pub original_post_url: Option<String>,
|
||||
pub original_post_body: Option<String>,
|
||||
pub reason: String,
|
||||
pub resolved: bool,
|
||||
pub resolver_id: Option<i32>,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "post_report"]
|
||||
pub struct PostReportForm {
|
||||
pub creator_id: i32,
|
||||
pub post_id: i32,
|
||||
pub original_post_name: String,
|
||||
pub original_post_url: Option<String>,
|
||||
pub original_post_body: Option<String>,
|
||||
pub reason: String,
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
use crate::schema::private_message;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "private_message"]
|
||||
pub struct PrivateMessage {
|
||||
pub id: i32,
|
||||
pub creator_id: i32,
|
||||
pub recipient_id: i32,
|
||||
pub content: String,
|
||||
pub deleted: bool,
|
||||
pub read: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub ap_id: String,
|
||||
pub local: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "private_message"]
|
||||
pub struct PrivateMessageForm {
|
||||
pub creator_id: i32,
|
||||
pub recipient_id: i32,
|
||||
pub content: String,
|
||||
pub deleted: Option<bool>,
|
||||
pub read: Option<bool>,
|
||||
pub published: Option<chrono::NaiveDateTime>,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub ap_id: Option<String>,
|
||||
pub local: bool,
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
use crate::schema::site;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Clone, Serialize)]
|
||||
#[table_name = "site"]
|
||||
pub struct Site {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub creator_id: i32,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub enable_downvotes: bool,
|
||||
pub open_registration: bool,
|
||||
pub enable_nsfw: bool,
|
||||
pub icon: Option<String>,
|
||||
pub banner: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "site"]
|
||||
pub struct SiteForm {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub creator_id: i32,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub enable_downvotes: bool,
|
||||
pub open_registration: bool,
|
||||
pub enable_nsfw: bool,
|
||||
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
||||
pub icon: Option<Option<String>>,
|
||||
pub banner: Option<Option<String>>,
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
use crate::schema::{user_, user_alias_1, user_alias_2};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "user_"]
|
||||
pub struct User_ {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub preferred_username: Option<String>,
|
||||
pub password_encrypted: String,
|
||||
pub email: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub show_nsfw: bool,
|
||||
pub theme: String,
|
||||
pub default_sort_type: i16,
|
||||
pub default_listing_type: i16,
|
||||
pub lang: String,
|
||||
pub show_avatars: bool,
|
||||
pub send_notifications_to_email: bool,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub actor_id: String,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
/// A safe representation of user, without the sensitive info
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "user_"]
|
||||
pub struct UserSafe {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub preferred_username: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub actor_id: String,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "user_alias_1"]
|
||||
pub struct UserAlias1 {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub preferred_username: Option<String>,
|
||||
pub password_encrypted: String,
|
||||
pub email: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub show_nsfw: bool,
|
||||
pub theme: String,
|
||||
pub default_sort_type: i16,
|
||||
pub default_listing_type: i16,
|
||||
pub lang: String,
|
||||
pub show_avatars: bool,
|
||||
pub send_notifications_to_email: bool,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub actor_id: String,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "user_alias_1"]
|
||||
pub struct UserSafeAlias1 {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub preferred_username: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub actor_id: String,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "user_alias_2"]
|
||||
pub struct UserAlias2 {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub preferred_username: Option<String>,
|
||||
pub password_encrypted: String,
|
||||
pub email: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub show_nsfw: bool,
|
||||
pub theme: String,
|
||||
pub default_sort_type: i16,
|
||||
pub default_listing_type: i16,
|
||||
pub lang: String,
|
||||
pub show_avatars: bool,
|
||||
pub send_notifications_to_email: bool,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub actor_id: String,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[table_name = "user_alias_2"]
|
||||
pub struct UserSafeAlias2 {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub preferred_username: Option<String>,
|
||||
pub avatar: Option<String>,
|
||||
pub admin: bool,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub actor_id: String,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub banner: Option<String>,
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone)]
|
||||
#[table_name = "user_"]
|
||||
pub struct UserForm {
|
||||
pub name: String,
|
||||
pub preferred_username: Option<Option<String>>,
|
||||
pub password_encrypted: String,
|
||||
pub admin: bool,
|
||||
pub banned: Option<bool>,
|
||||
pub email: Option<Option<String>>,
|
||||
pub avatar: Option<Option<String>>,
|
||||
pub published: Option<chrono::NaiveDateTime>,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub show_nsfw: bool,
|
||||
pub theme: String,
|
||||
pub default_sort_type: i16,
|
||||
pub default_listing_type: i16,
|
||||
pub lang: String,
|
||||
pub show_avatars: bool,
|
||||
pub send_notifications_to_email: bool,
|
||||
pub matrix_user_id: Option<Option<String>>,
|
||||
pub actor_id: Option<String>,
|
||||
pub bio: Option<Option<String>>,
|
||||
pub local: bool,
|
||||
pub private_key: Option<String>,
|
||||
pub public_key: Option<String>,
|
||||
pub last_refreshed_at: Option<chrono::NaiveDateTime>,
|
||||
pub banner: Option<Option<String>>,
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
use crate::{schema::user_mention, source::comment::Comment};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||
#[belongs_to(Comment)]
|
||||
#[table_name = "user_mention"]
|
||||
pub struct UserMention {
|
||||
pub id: i32,
|
||||
pub recipient_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub read: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset)]
|
||||
#[table_name = "user_mention"]
|
||||
pub struct UserMentionForm {
|
||||
pub recipient_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub read: Option<bool>,
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue