mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-11 01:49:21 +00:00
5d837780f5
* Moving settings to Database. - Moves many settings into the database. Fixes #2285 - Adds a local_site and instance table. Fixes #2365 . Fixes #2368 - Separates SQL update an insert forms, to avoid runtime errors. - Adds TypedBuilder to all the SQL forms, instead of default. * Fix weird clippy issue. * Removing extra lines. * Some fixes from suggestions. * Fixing apub tests. * Using instance creation helper function. * Move forms to their own line. * Trying to fix local_site_data, still broken. * Testing out async * Testing out async 2 * Fixing federation tests. * Trying to fix check features 1. * Starting on adding diesel async. 1/4th done. * Added async to views and schema. * Adding some more async * Compiling now. * Added diesel async. Fixes #2465 * Running clippy --fix * Trying to fix cargo test on drone. * Trying new muslrust. * Trying a custom dns * Trying a custom dns 2 * Trying a custom dns 3 * Trying a custom dns 4 * Trying a custom dns 5 * Trying a custom dns 6 * Trying a custom dns 7 * Addressing PR comments. * Adding check_apub to all verify functions. * Reverting back drone. * Fixing merge * Fix docker images. * Adding missing discussion_languages. * Trying to fix federation tests. * Fix site setup user creation. * Fix clippy * Fix clippy 2 * Test api faster * Try to fix 1 * Try to fix 2 * What are these lines about * Trying to fix 3 * Moving federation test back to top. * Remove logging cat.
189 lines
4.5 KiB
Rust
189 lines
4.5 KiB
Rust
use crate::{
|
|
newtypes::{CommunityId, DbUrl, PersonId},
|
|
utils::DbPool,
|
|
};
|
|
use diesel::result::Error;
|
|
|
|
#[async_trait]
|
|
pub trait Crud {
|
|
type InsertForm;
|
|
type UpdateForm;
|
|
type IdType;
|
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn read(pool: &DbPool, id: Self::IdType) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
/// 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.
|
|
async fn update(pool: &DbPool, id: Self::IdType, form: &Self::UpdateForm) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn delete(_pool: &DbPool, _id: Self::IdType) -> Result<usize, Error>
|
|
where
|
|
Self: Sized,
|
|
Self::IdType: Send,
|
|
{
|
|
async { Err(Error::NotFound) }.await
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Followable {
|
|
type Form;
|
|
async fn follow(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn follow_accepted(
|
|
pool: &DbPool,
|
|
community_id: CommunityId,
|
|
person_id: PersonId,
|
|
) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn unfollow(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn has_local_followers(pool: &DbPool, community_id: CommunityId) -> Result<bool, Error>;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Joinable {
|
|
type Form;
|
|
async fn join(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn leave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Likeable {
|
|
type Form;
|
|
type IdType;
|
|
async fn like(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn remove(
|
|
pool: &DbPool,
|
|
person_id: PersonId,
|
|
item_id: Self::IdType,
|
|
) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Bannable {
|
|
type Form;
|
|
async fn ban(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn unban(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Saveable {
|
|
type Form;
|
|
async fn save(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn unsave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Blockable {
|
|
type Form;
|
|
async fn block(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn unblock(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Readable {
|
|
type Form;
|
|
async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait Reportable {
|
|
type Form;
|
|
type IdType;
|
|
async fn report(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn resolve(
|
|
pool: &DbPool,
|
|
report_id: Self::IdType,
|
|
resolver_id: PersonId,
|
|
) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn unresolve(
|
|
pool: &DbPool,
|
|
report_id: Self::IdType,
|
|
resolver_id: PersonId,
|
|
) -> Result<usize, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
// TODO these should be removed, there should be another way to do this
|
|
pub trait DeleteableOrRemoveable {
|
|
fn blank_out_deleted_or_removed_info(self) -> Self;
|
|
}
|
|
|
|
pub trait ToSafe {
|
|
type SafeColumns;
|
|
fn safe_columns_tuple() -> Self::SafeColumns;
|
|
}
|
|
|
|
pub trait ToSafeSettings {
|
|
type SafeSettingsColumns;
|
|
fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
|
|
}
|
|
|
|
pub trait ViewToVec {
|
|
type DbTuple;
|
|
fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
|
|
where
|
|
Self: Sized;
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait ApubActor {
|
|
// TODO: this should be in a trait ApubObject (and implemented for Post, Comment, PrivateMessage as well)
|
|
async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error>
|
|
where
|
|
Self: Sized;
|
|
/// - actor_name is the name of the community or user to read.
|
|
/// - include_deleted, if true, will return communities or users that were deleted/removed
|
|
async fn read_from_name(
|
|
pool: &DbPool,
|
|
actor_name: &str,
|
|
include_deleted: bool,
|
|
) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
async fn read_from_name_and_domain(
|
|
pool: &DbPool,
|
|
actor_name: &str,
|
|
protocol_domain: &str,
|
|
) -> Result<Self, Error>
|
|
where
|
|
Self: Sized;
|
|
}
|