Skip to content

Commit

Permalink
Fmt fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dastansam committed Mar 28, 2024
1 parent 1e26139 commit 9dafcc3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 60 deletions.
9 changes: 7 additions & 2 deletions pcidss/api/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ impl TransactionTrait for PgTransaction {
Ok(None)
}

async fn find_by_bank_account_id(&self, source: &Uuid) -> Result<Vec<Transaction>, DomainError> {
async fn find_by_bank_account_id(
&self,
source: &Uuid,
) -> Result<Vec<Transaction>, DomainError> {
let client = self.pool.get().await?;
let stmt = client.prepare("SELECT * FROM bank_transaction WHERE source = $1 OR recipient = $1").await?;
let stmt = client
.prepare("SELECT * FROM bank_transaction WHERE source = $1 OR recipient = $1")
.await?;

let result = client.query(&stmt, &[&source]).await?;

Expand Down
52 changes: 26 additions & 26 deletions pcidss/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,51 @@ use thiserror::Error;

#[derive(Debug, Error, PartialEq, Eq)]
pub enum DomainError {
#[error("{}", _0)]
NotFound(String),
#[error("{}", _0)]
NotFound(String),

#[error("{}", _0)]
BadRequest(String),
#[error("{}", _0)]
BadRequest(String),

#[error("{}", _0)]
InternalServerError(String),
#[error("{}", _0)]
InternalServerError(String),

#[error("{}", _0)]
ApiError(String),
#[error("{}", _0)]
ApiError(String),
}

impl From<tokio_postgres::Error> for DomainError {
fn from(err: tokio_postgres::Error) -> Self {
DomainError::InternalServerError(err.to_string())
}
fn from(err: tokio_postgres::Error) -> Self {
DomainError::InternalServerError(err.to_string())
}
}

impl From<deadpool_postgres::PoolError> for DomainError {
fn from(err: deadpool_postgres::PoolError) -> Self {
DomainError::InternalServerError(err.to_string())
}
fn from(err: deadpool_postgres::PoolError) -> Self {
DomainError::InternalServerError(err.to_string())
}
}

impl From<deadpool_postgres::BuildError> for DomainError {
fn from(err: deadpool_postgres::BuildError) -> Self {
DomainError::InternalServerError(err.to_string())
}
fn from(err: deadpool_postgres::BuildError) -> Self {
DomainError::InternalServerError(err.to_string())
}
}

impl From<deadpool_postgres::CreatePoolError> for DomainError {
fn from(err: deadpool_postgres::CreatePoolError) -> Self {
DomainError::InternalServerError(err.to_string())
}
fn from(err: deadpool_postgres::CreatePoolError) -> Self {
DomainError::InternalServerError(err.to_string())
}
}

impl From<IsoError> for DomainError {
fn from(value: IsoError) -> Self {
DomainError::ApiError(value.msg)
}
fn from(value: IsoError) -> Self {
DomainError::ApiError(value.msg)
}
}

impl From<ParseIntError> for DomainError {
fn from(value: ParseIntError) -> Self {
DomainError::InternalServerError(value.to_string())
}
fn from(value: ParseIntError) -> Self {
DomainError::InternalServerError(value.to_string())
}
}
3 changes: 2 additions & 1 deletion pcidss/core/src/transaction/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pub trait TransactionTrait: Send + Sync {
async fn find_by_id(&self, id: &Uuid) -> Result<Option<Transaction>, DomainError>;

/// Find by beneficiary.
async fn find_by_bank_account_id(&self, source: &Uuid) -> Result<Vec<Transaction>, DomainError>;
async fn find_by_bank_account_id(&self, source: &Uuid)
-> Result<Vec<Transaction>, DomainError>;

/// Find a transaction by hash.
async fn find_by_hash(&self, hash: &str) -> Result<Option<Transaction>, DomainError>;
Expand Down
20 changes: 10 additions & 10 deletions pcidss/core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
/// `TransactionType` is an enum for the type of transaction.
#[derive(Debug, Clone, PartialEq)]
pub enum TransactionType {
/// Add to account balance.
Debit,
/// Deduct from account balance.
Credit,
/// Add to account balance.
Debit,
/// Deduct from account balance.
Credit,
}

#[allow(clippy::from_over_into)]
impl Into<u32> for TransactionType {
fn into(self) -> u32 {
match self {
TransactionType::Debit => 0,
TransactionType::Credit => 1,
}
}
fn into(self) -> u32 {
match self {
TransactionType::Debit => 0,
TransactionType::Credit => 1,
}
}
}
44 changes: 23 additions & 21 deletions pcidss/core/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
use std::cell::RefCell;
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
use std::{
cell::RefCell,
sync::{
atomic::{AtomicUsize, Ordering},
Arc,
},
};

/// Blocks current thread until ctrl-c is received
pub async fn block_until_sigint() {
let (ctrlc_send, ctrlc_oneshot) = futures::channel::oneshot::channel();
let ctrlc_send_c = RefCell::new(Some(ctrlc_send));
let (ctrlc_send, ctrlc_oneshot) = futures::channel::oneshot::channel();
let ctrlc_send_c = RefCell::new(Some(ctrlc_send));

let running = Arc::new(AtomicUsize::new(0));
ctrlc::set_handler(move || {
let prev = running.fetch_add(1, Ordering::SeqCst);
if prev == 0 {
println!("Got interrupt, shutting down...");
// Send sig int in channel to blocking task
if let Some(ctrlc_send) = ctrlc_send_c.try_borrow_mut().unwrap().take() {
ctrlc_send.send(()).expect("Error sending ctrl-c message");
}
} else {
std::process::exit(0);
}
})
.expect("Error setting Ctrl-C handler");
let running = Arc::new(AtomicUsize::new(0));
ctrlc::set_handler(move || {
let prev = running.fetch_add(1, Ordering::SeqCst);
if prev == 0 {
println!("Got interrupt, shutting down...");
// Send sig int in channel to blocking task
if let Some(ctrlc_send) = ctrlc_send_c.try_borrow_mut().unwrap().take() {
ctrlc_send.send(()).expect("Error sending ctrl-c message");
}
} else {
std::process::exit(0);
}
})
.expect("Error setting Ctrl-C handler");

ctrlc_oneshot.await.unwrap();
ctrlc_oneshot.await.unwrap();
}

0 comments on commit 9dafcc3

Please sign in to comment.