+use crate::structs::{LocalUserSettingsView, LocalUserView};
use diesel::{result::Error, *};
use lemmy_db_schema::{
- aggregates::person_aggregates::PersonAggregates,
- functions::lower,
+ aggregates::structs::PersonAggregates,
newtypes::{LocalUserId, PersonId},
schema::{local_user, person, person_aggregates},
source::{
person::{Person, PersonSafe},
},
traits::{ToSafe, ToSafeSettings},
+ utils::functions::lower,
};
-use serde::{Deserialize, Serialize};
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-pub struct LocalUserView {
- pub local_user: LocalUser,
- pub person: Person,
- pub counts: PersonAggregates,
-}
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
impl LocalUserView {
- pub fn read(conn: &PgConnection, local_user_id: LocalUserId) -> Result<Self, Error> {
+ pub fn read(conn: &mut PgConnection, local_user_id: LocalUserId) -> Result<Self, Error> {
let (local_user, person, counts) = local_user::table
.find(local_user_id)
.inner_join(person::table)
})
}
- pub fn read_person(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
+ pub fn read_person(conn: &mut PgConnection, person_id: PersonId) -> Result<Self, Error> {
let (local_user, person, counts) = local_user::table
.filter(person::id.eq(person_id))
.inner_join(person::table)
}
// TODO check where this is used
- pub fn read_from_name(conn: &PgConnection, name: &str) -> Result<Self, Error> {
+ pub fn read_from_name(conn: &mut PgConnection, name: &str) -> Result<Self, Error> {
let (local_user, person, counts) = local_user::table
.filter(person::name.eq(name))
.inner_join(person::table)
})
}
- pub fn find_by_email_or_name(conn: &PgConnection, name_or_email: &str) -> Result<Self, Error> {
+ pub fn find_by_email_or_name(
+ conn: &mut PgConnection,
+ name_or_email: &str,
+ ) -> Result<Self, Error> {
let (local_user, person, counts) = local_user::table
.inner_join(person::table)
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
})
}
- pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<Self, Error> {
+ pub fn find_by_email(conn: &mut PgConnection, from_email: &str) -> Result<Self, Error> {
let (local_user, person, counts) = local_user::table
.inner_join(person::table)
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
}
}
-#[derive(Debug, Serialize, Deserialize, Clone)]
-pub struct LocalUserSettingsView {
- pub local_user: LocalUserSettings,
- pub person: PersonSafe,
- pub counts: PersonAggregates,
-}
-
type LocalUserSettingsViewTuple = (LocalUserSettings, PersonSafe, PersonAggregates);
impl LocalUserSettingsView {
- pub fn read(conn: &PgConnection, local_user_id: LocalUserId) -> Result<Self, Error> {
+ pub fn read(conn: &mut PgConnection, local_user_id: LocalUserId) -> Result<Self, Error> {
let (local_user, person, counts) = local_user::table
.find(local_user_id)
.inner_join(person::table)