mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-15 17:03:59 +00:00
91834d0d21
* h * Start doing stuff * Default impl for Crud::read * Simplify Crud::read lifetimes * fmt * Stuff * Stuff * Successfully make default read implementation work * Restore Person::read * Clean up default Crud::read and rename 'query2 * Replace filter with find * Attempt default Crud::create * Change Crud to Crud<'a> (won't compile) * Revert "Change Crud to Crud<'a> (won't compile)" This reverts commit7ed20f5f71
. * Default Crud::delete * Remove Crud::delete definitions that match default * Remove commented Site::read * Insert trait * Revert "Insert trait" This reverts commit9d780c2403
. * Use non-borrowed forms * Revert "Use non-borrowed forms" This reverts commitd2dd442563
. * Revert "Revert "Change Crud to Crud<'a> (won't compile)"" This reverts commit25a27165a8
. * Fix lifetime for everything except Crud::delete * Fix Crud::delete * Add comment about futures * Attempt Crud::create * Attempt separate CrudBounds * Revert "Attempt separate CrudBounds" This reverts commit1b4ca321c3
. * Try to fix Crud::create * Move lifetime parameters to associated types * Revert "Move lifetime parameters to associated types" This reverts commitaf1bc858ce
. * Revert "Try to fix Crud::create" This reverts commiteec238496c
. * Revert "Revert "Attempt separate CrudBounds"" This reverts commit1ec33ce502
. * Revert "Attempt separate CrudBounds" This reverts commit1b4ca321c3
. * Revert "Attempt Crud::create" This reverts commit47e8071b68
. * Revert "Add comment about futures" This reverts commitb266b14653
. * Revert "Fix Crud::delete" This reverts commit3abcce2eec
. * Revert "Fix lifetime for everything except Crud::delete" This reverts commitc1ad7a161b
. * Revert "Revert "Revert "Change Crud to Crud<'a> (won't compile)""" This reverts commit3129cd0fc3
. * Clean up * Update site.rs
53 lines
1.4 KiB
Rust
53 lines
1.4 KiB
Rust
use crate::{
|
|
newtypes::LocalUserId,
|
|
schema::registration_application::dsl::{local_user_id, registration_application},
|
|
source::registration_application::{
|
|
RegistrationApplication,
|
|
RegistrationApplicationInsertForm,
|
|
RegistrationApplicationUpdateForm,
|
|
},
|
|
traits::Crud,
|
|
utils::{get_conn, DbPool},
|
|
};
|
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
|
use diesel_async::RunQueryDsl;
|
|
|
|
#[async_trait]
|
|
impl Crud for RegistrationApplication {
|
|
type InsertForm = RegistrationApplicationInsertForm;
|
|
type UpdateForm = RegistrationApplicationUpdateForm;
|
|
type IdType = i32;
|
|
|
|
async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
insert_into(registration_application)
|
|
.values(form)
|
|
.get_result::<Self>(conn)
|
|
.await
|
|
}
|
|
|
|
async fn update(
|
|
pool: &mut DbPool<'_>,
|
|
id_: Self::IdType,
|
|
form: &Self::UpdateForm,
|
|
) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
diesel::update(registration_application.find(id_))
|
|
.set(form)
|
|
.get_result::<Self>(conn)
|
|
.await
|
|
}
|
|
}
|
|
|
|
impl RegistrationApplication {
|
|
pub async fn find_by_local_user_id(
|
|
pool: &mut DbPool<'_>,
|
|
local_user_id_: LocalUserId,
|
|
) -> Result<Self, Error> {
|
|
let conn = &mut get_conn(pool).await?;
|
|
registration_application
|
|
.filter(local_user_id.eq(local_user_id_))
|
|
.first::<Self>(conn)
|
|
.await
|
|
}
|
|
}
|