use crate::{
newtypes::{DbUrl, PersonId, PrivateMessageId},
- schema::private_message::dsl::*,
- source::private_message::*,
- traits::{Crud, DeleteableOrRemoveable},
+ schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
+ source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
+ traits::Crud,
utils::{get_conn, DbPool},
};
-use diesel::{dsl::*, result::Error, *};
+use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_utils::error::LemmyError;
use url::Url;
type InsertForm = PrivateMessageInsertForm;
type UpdateForm = PrivateMessageUpdateForm;
type IdType = PrivateMessageId;
- async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result<Self, Error> {
+ async fn read(
+ pool: &mut DbPool<'_>,
+ private_message_id: PrivateMessageId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
private_message
.find(private_message_id)
.await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(private_message)
.values(form)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
private_message_id: PrivateMessageId,
form: &Self::UpdateForm,
) -> Result<Self, Error> {
.get_result::<Self>(conn)
.await
}
- async fn delete(pool: &DbPool, pm_id: Self::IdType) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, pm_id: Self::IdType) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(private_message.find(pm_id))
.execute(conn)
impl PrivateMessage {
pub async fn mark_all_as_read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_recipient_id: PersonId,
) -> Result<Vec<PrivateMessage>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn read_from_apub_id(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
object_id: Url,
) -> Result<Option<Self>, LemmyError> {
let conn = &mut get_conn(pool).await?;
}
}
-impl DeleteableOrRemoveable for PrivateMessage {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.content = "".into();
- self
- }
-}
-
#[cfg(test)]
mod tests {
use crate::{
- source::{instance::Instance, person::*, private_message::*},
+ source::{
+ instance::Instance,
+ person::{Person, PersonInsertForm},
+ private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
+ },
traits::Crud,
utils::build_db_pool_for_tests,
};
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
- let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+ let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+ .await
+ .unwrap();
let creator_form = PersonInsertForm::builder()
.name("creator_pm".into())
read: false,
updated: None,
published: inserted_private_message.published,
- ap_id: inserted_private_message.ap_id.to_owned(),
+ ap_id: inserted_private_message.ap_id.clone(),
local: true,
};