Rename UserDTO to UserDto
This commit is contained in:
parent
0fd1137361
commit
e1c4bb8fc7
@ -7,13 +7,13 @@ use bcrypt::{hash, verify, DEFAULT_COST};
|
|||||||
pub fn find_user_by_uid(
|
pub fn find_user_by_uid(
|
||||||
uid: i32,
|
uid: i32,
|
||||||
conn: &SqliteConnection,
|
conn: &SqliteConnection,
|
||||||
) -> Result<Option<models::UserDTO>, errors::DomainError> {
|
) -> Result<Option<models::UserDto>, errors::DomainError> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
|
|
||||||
let maybe_user = users
|
let maybe_user = users
|
||||||
.select((name, created_at))
|
.select((name, created_at))
|
||||||
.find(uid)
|
.find(uid)
|
||||||
.first::<models::UserDTO>(conn)
|
.first::<models::UserDto>(conn)
|
||||||
.optional();
|
.optional();
|
||||||
|
|
||||||
Ok(maybe_user?)
|
Ok(maybe_user?)
|
||||||
@ -22,9 +22,9 @@ pub fn find_user_by_uid(
|
|||||||
pub fn _find_user_by_name(
|
pub fn _find_user_by_name(
|
||||||
user_name: String,
|
user_name: String,
|
||||||
conn: &SqliteConnection,
|
conn: &SqliteConnection,
|
||||||
) -> Result<Option<models::UserDTO>, errors::DomainError> {
|
) -> Result<Option<models::UserDto>, errors::DomainError> {
|
||||||
let maybe_user = query::_get_user_by_name(&user_name)
|
let maybe_user = query::_get_user_by_name(&user_name)
|
||||||
.first::<models::UserDTO>(conn)
|
.first::<models::UserDto>(conn)
|
||||||
.optional();
|
.optional();
|
||||||
|
|
||||||
Ok(maybe_user?)
|
Ok(maybe_user?)
|
||||||
@ -32,11 +32,11 @@ pub fn _find_user_by_name(
|
|||||||
|
|
||||||
pub fn get_all(
|
pub fn get_all(
|
||||||
conn: &SqliteConnection,
|
conn: &SqliteConnection,
|
||||||
) -> Result<Option<Vec<models::UserDTO>>, errors::DomainError> {
|
) -> Result<Option<Vec<models::UserDto>>, errors::DomainError> {
|
||||||
use crate::schema::users::dsl::*;
|
use crate::schema::users::dsl::*;
|
||||||
Ok(users
|
Ok(users
|
||||||
.select((name, created_at))
|
.select((name, created_at))
|
||||||
.load::<models::UserDTO>(conn)
|
.load::<models::UserDto>(conn)
|
||||||
.optional()?)
|
.optional()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ pub fn get_all(
|
|||||||
pub fn insert_new_user(
|
pub fn insert_new_user(
|
||||||
nu: models::NewUser,
|
nu: models::NewUser,
|
||||||
conn: &SqliteConnection,
|
conn: &SqliteConnection,
|
||||||
) -> Result<models::UserDTO, errors::DomainError> {
|
) -> Result<models::UserDto, errors::DomainError> {
|
||||||
// It is common when using Diesel with Actix web to import schema-related
|
// It is common when using Diesel with Actix web to import schema-related
|
||||||
// modules inside a function's scope (rather than the normal module's scope)
|
// modules inside a function's scope (rather than the normal module's scope)
|
||||||
// to prevent import collisions and namespace pollution.
|
// to prevent import collisions and namespace pollution.
|
||||||
@ -57,7 +57,7 @@ pub fn insert_new_user(
|
|||||||
|
|
||||||
diesel::insert_into(users).values(&nu).execute(conn)?;
|
diesel::insert_into(users).values(&nu).execute(conn)?;
|
||||||
let user =
|
let user =
|
||||||
query::_get_user_by_name(&nu.name).first::<models::UserDTO>(conn)?;
|
query::_get_user_by_name(&nu.name).first::<models::UserDto>(conn)?;
|
||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ pub struct NewUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Queryable)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Queryable)]
|
||||||
pub struct UserDTO {
|
pub struct UserDto {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub registration_date: chrono::NaiveDateTime,
|
pub registration_date: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -4,20 +4,20 @@ pub trait UserService {
|
|||||||
fn find_user_by_uid(
|
fn find_user_by_uid(
|
||||||
&self,
|
&self,
|
||||||
uid: i32,
|
uid: i32,
|
||||||
) -> Result<Option<models::UserDTO>, errors::DomainError>;
|
) -> Result<Option<models::UserDto>, errors::DomainError>;
|
||||||
fn _find_user_by_name(
|
fn _find_user_by_name(
|
||||||
&self,
|
&self,
|
||||||
user_name: String,
|
user_name: String,
|
||||||
) -> Result<Option<models::UserDTO>, errors::DomainError>;
|
) -> Result<Option<models::UserDto>, errors::DomainError>;
|
||||||
|
|
||||||
fn get_all(
|
fn get_all(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Option<Vec<models::UserDTO>>, errors::DomainError>;
|
) -> Result<Option<Vec<models::UserDto>>, errors::DomainError>;
|
||||||
|
|
||||||
fn insert_new_user(
|
fn insert_new_user(
|
||||||
&self,
|
&self,
|
||||||
nu: models::NewUser,
|
nu: models::NewUser,
|
||||||
) -> Result<models::UserDTO, errors::DomainError>;
|
) -> Result<models::UserDto, errors::DomainError>;
|
||||||
|
|
||||||
// fn woot(&self) -> i32;
|
// fn woot(&self) -> i32;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ impl UserService for UserServiceImpl {
|
|||||||
fn find_user_by_uid(
|
fn find_user_by_uid(
|
||||||
&self,
|
&self,
|
||||||
uid: i32,
|
uid: i32,
|
||||||
) -> Result<Option<models::UserDTO>, errors::DomainError> {
|
) -> Result<Option<models::UserDto>, errors::DomainError> {
|
||||||
let conn = self.pool.get()?;
|
let conn = self.pool.get()?;
|
||||||
actions::find_user_by_uid(uid, &conn)
|
actions::find_user_by_uid(uid, &conn)
|
||||||
}
|
}
|
||||||
@ -45,14 +45,14 @@ impl UserService for UserServiceImpl {
|
|||||||
fn _find_user_by_name(
|
fn _find_user_by_name(
|
||||||
&self,
|
&self,
|
||||||
user_name: String,
|
user_name: String,
|
||||||
) -> Result<Option<models::UserDTO>, errors::DomainError> {
|
) -> Result<Option<models::UserDto>, errors::DomainError> {
|
||||||
let conn = self.pool.get()?;
|
let conn = self.pool.get()?;
|
||||||
actions::_find_user_by_name(user_name, &conn)
|
actions::_find_user_by_name(user_name, &conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_all(
|
fn get_all(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Option<Vec<models::UserDTO>>, errors::DomainError> {
|
) -> Result<Option<Vec<models::UserDto>>, errors::DomainError> {
|
||||||
let conn = self.pool.get()?;
|
let conn = self.pool.get()?;
|
||||||
actions::get_all(&conn)
|
actions::get_all(&conn)
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ impl UserService for UserServiceImpl {
|
|||||||
fn insert_new_user(
|
fn insert_new_user(
|
||||||
&self,
|
&self,
|
||||||
nu: models::NewUser,
|
nu: models::NewUser,
|
||||||
) -> Result<models::UserDTO, errors::DomainError> {
|
) -> Result<models::UserDto, errors::DomainError> {
|
||||||
let conn = self.pool.get()?;
|
let conn = self.pool.get()?;
|
||||||
actions::insert_new_user(nu, &conn)
|
actions::insert_new_user(nu, &conn)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user