Skip to content

Commit

Permalink
reset: The borrowed expression implements the required traits
Browse files Browse the repository at this point in the history
  • Loading branch information
bush1D3v committed Jul 29, 2024
1 parent 84be450 commit cf20b43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/modules/user/user_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use crate::utils::{
};
use actix_web::{web::Data, HttpResponse};
use deadpool_postgres::Pool;
use sql_builder::SqlBuilder;
use sql_builder::{quote, SqlBuilder};

pub async fn email_exists(pg_pool: Data<Pool>, email: String) -> Result<(), HttpResponse> {
let mut sql_builder = SqlBuilder::select_from("users");
sql_builder.field("id");
sql_builder.or_where_eq("email", email.clone());
sql_builder.or_where_eq("email", &quote(email.clone()));

let rows = match query_constructor_executor(pg_pool, sql_builder).await {
Ok(x) => x,
Expand All @@ -31,7 +31,7 @@ pub async fn email_exists(pg_pool: Data<Pool>, email: String) -> Result<(), Http
pub async fn email_not_exists(pg_pool: Data<Pool>, email: String) -> Result<(), HttpResponse> {
let mut sql_builder = SqlBuilder::select_from("users");
sql_builder.field("id");
sql_builder.or_where_eq("email", email.clone());
sql_builder.or_where_eq("email", &quote(email.clone()));

let rows = match query_constructor_executor(pg_pool, sql_builder).await {
Ok(x) => x,
Expand Down
6 changes: 3 additions & 3 deletions src/modules/user/user_queues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async fn put_user_queue(pool: Pool, queue: Arc<PutUserAppQueue>) -> Result<(), H
sql_builder.set("password", &quote(user.new_password.clone()));
sql_builder.set("email", &quote(user.new_email.clone()));
sql_builder.set("updated_at", &quote(updated_at));
sql_builder.or_where_eq("id", user_id);
sql_builder.or_where_eq("id", &quote(user_id));

let mut this_sql = match sql_builder.sql() {
Ok(x) => x,
Expand Down Expand Up @@ -171,7 +171,7 @@ async fn delete_user_queue(pool: Pool, queue: Arc<DeleteUserAppQueue>) -> Result
let user_id = queue.pop().await;

let mut sql_builder = SqlBuilder::delete_from("salt");
sql_builder.or_where_eq("user_id", user_id.clone());
sql_builder.or_where_eq("user_id", &quote(user_id.clone()));

let mut this_sql = match sql_builder.sql() {
Ok(x) => x,
Expand All @@ -181,7 +181,7 @@ async fn delete_user_queue(pool: Pool, queue: Arc<DeleteUserAppQueue>) -> Result
salt_sql.push_str(&this_sql);

let mut sql_builder = SqlBuilder::delete_from("users");
sql_builder.or_where_eq("id", user_id);
sql_builder.or_where_eq("id", &quote(user_id));

let mut this_sql = match sql_builder.sql() {
Ok(x) => x,
Expand Down
7 changes: 4 additions & 3 deletions src/modules/user/user_repositories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use actix_web::{
web::{Data, Json, Query},
HttpResponse,
};
use sql_builder::quote;
use std::sync::Arc;

fn user_dto_constructor(rows: Vec<postgres::Row>) -> UserDTO {
Expand All @@ -35,7 +36,7 @@ pub async fn get_user_salt_repository(
) -> Result<String, HttpResponse> {
let mut sql_builder = sql_builder::SqlBuilder::select_from("salt");
sql_builder.field("salt");
sql_builder.or_where_eq("user_id", user_id);
sql_builder.or_where_eq("user_id", &quote(user_id));

let rows = match query_constructor_executor(pg_pool, sql_builder).await {
Ok(x) => x,
Expand Down Expand Up @@ -85,7 +86,7 @@ pub async fn login_user_repository(
pg_pool: Data<deadpool_postgres::Pool>,
) -> Result<UserDTO, HttpResponse> {
let mut sql_builder = sql_builder::SqlBuilder::select_from("users");
sql_builder.or_where_eq("email", email.clone());
sql_builder.or_where_eq("email", &quote(email.clone()));

let rows = match query_constructor_executor(pg_pool, sql_builder).await {
Ok(x) => x,
Expand All @@ -111,7 +112,7 @@ pub async fn detail_user_repository(
user_id: String,
) -> Result<UserDTO, HttpResponse> {
let mut sql_builder = sql_builder::SqlBuilder::select_from("users");
sql_builder.or_where_eq("id", user_id);
sql_builder.or_where_eq("id", &quote(user_id));

let rows = match query_constructor_executor(pg_pool, sql_builder).await {
Ok(x) => x,
Expand Down

0 comments on commit cf20b43

Please sign in to comment.