2021-12-15 19:49:59 +00:00
|
|
|
use crate::{newtypes::LocalUserId, source::registration_application::*, traits::Crud};
|
|
|
|
use diesel::{insert_into, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
|
|
|
|
|
|
|
|
impl Crud for RegistrationApplication {
|
2022-10-27 09:24:07 +00:00
|
|
|
type InsertForm = RegistrationApplicationInsertForm;
|
|
|
|
type UpdateForm = RegistrationApplicationUpdateForm;
|
2021-12-15 19:49:59 +00:00
|
|
|
type IdType = i32;
|
2022-10-27 09:24:07 +00:00
|
|
|
fn create(conn: &mut PgConnection, form: &Self::InsertForm) -> Result<Self, Error> {
|
2021-12-15 19:49:59 +00:00
|
|
|
use crate::schema::registration_application::dsl::*;
|
|
|
|
insert_into(registration_application)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2022-09-26 14:09:32 +00:00
|
|
|
fn read(conn: &mut PgConnection, id_: Self::IdType) -> Result<Self, Error> {
|
2021-12-15 19:49:59 +00:00
|
|
|
use crate::schema::registration_application::dsl::*;
|
|
|
|
registration_application.find(id_).first::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
fn update(
|
|
|
|
conn: &mut PgConnection,
|
|
|
|
id_: Self::IdType,
|
|
|
|
form: &Self::UpdateForm,
|
|
|
|
) -> Result<Self, Error> {
|
2021-12-15 19:49:59 +00:00
|
|
|
use crate::schema::registration_application::dsl::*;
|
|
|
|
diesel::update(registration_application.find(id_))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2022-09-26 14:09:32 +00:00
|
|
|
fn delete(conn: &mut PgConnection, id_: Self::IdType) -> Result<usize, Error> {
|
2021-12-15 19:49:59 +00:00
|
|
|
use crate::schema::registration_application::dsl::*;
|
|
|
|
diesel::delete(registration_application.find(id_)).execute(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RegistrationApplication {
|
|
|
|
pub fn find_by_local_user_id(
|
2022-09-26 14:09:32 +00:00
|
|
|
conn: &mut PgConnection,
|
2021-12-15 19:49:59 +00:00
|
|
|
local_user_id_: LocalUserId,
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
use crate::schema::registration_application::dsl::*;
|
|
|
|
registration_application
|
|
|
|
.filter(local_user_id.eq(local_user_id_))
|
|
|
|
.first::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|