Cleaned up imports.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
mod results;
|
||||
|
||||
pub use results::*;
|
||||
@@ -0,0 +1,29 @@
|
||||
use crate::database;
|
||||
|
||||
pub enum Upsert<T> {
|
||||
Created(T),
|
||||
Updated(T),
|
||||
}
|
||||
|
||||
impl<T> From<database::dtos::Upsert<T>> for Upsert<T> {
|
||||
fn from(value: database::dtos::Upsert<T>) -> Self {
|
||||
match value {
|
||||
database::dtos::Upsert::Created(v) => Upsert::Created(v),
|
||||
database::dtos::Upsert::Updated(v) => Upsert::Updated(v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Delete {
|
||||
Deleted,
|
||||
NotFound,
|
||||
}
|
||||
|
||||
impl From<database::dtos::Delete> for Delete {
|
||||
fn from(value: database::dtos::Delete) -> Self {
|
||||
match value {
|
||||
database::dtos::Delete::Deleted => Delete::Deleted,
|
||||
database::dtos::Delete::NotFound => Delete::NotFound,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{
|
||||
DecodeError, Delete, QueryConversionError, RepositoryError, Upsert,
|
||||
DecodeError, QueryConversionError, RepositoryError,
|
||||
dtos::{Delete, Upsert},
|
||||
encoding::{
|
||||
decode_direction, decode_recurrence_unit, decode_weekend_adjustment, encode_direction,
|
||||
encode_recurrence_unit, encode_weekend_adjustment,
|
||||
},
|
||||
};
|
||||
use crate::{
|
||||
database::{
|
||||
dtos::recurring_transaction::RecurringTransactionRow, recurring_transactions as db,
|
||||
},
|
||||
database::{dtos::RecurringTransactionRow, recurring_transactions as db},
|
||||
domain::{Cents, Recurrence, RecurrenceInterval, RecurringTransaction, Schedule},
|
||||
};
|
||||
|
||||
@@ -43,7 +42,7 @@ pub async fn query<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transactions = db::query_recurring_transactions(executor, query.try_into()?)
|
||||
let transactions = db::query(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -59,10 +58,7 @@ pub async fn get<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transaction = db::get_recurring_transaction_by_id(executor, id)
|
||||
.await?
|
||||
.map(decode)
|
||||
.transpose()?;
|
||||
let transaction = db::get_by_id(executor, id).await?.map(decode).transpose()?;
|
||||
|
||||
Ok(transaction)
|
||||
}
|
||||
@@ -74,18 +70,18 @@ pub async fn upsert<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transaction = db::upsert_recurring_transaction(executor, encode(transaction))
|
||||
let transaction = db::upsert(executor, encode(transaction))
|
||||
.await?
|
||||
.try_map(decode)?;
|
||||
|
||||
Ok(transaction)
|
||||
Ok(transaction.into())
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::delete_recurring_transaction_by_id(executor, id).await?)
|
||||
Ok(db::delete_by_id(executor, id).await?.into())
|
||||
}
|
||||
|
||||
fn decode(row: RecurringTransactionRow) -> Result<RecurringTransaction, DecodeError> {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{
|
||||
DecodeError, Delete, QueryConversionError, RepositoryError, Upsert,
|
||||
DecodeError, QueryConversionError, RepositoryError,
|
||||
dtos::{Delete, Upsert},
|
||||
encoding::{decode_direction, encode_direction},
|
||||
};
|
||||
use crate::{
|
||||
database::{dtos::transaction::TransactionRow, transactions as db},
|
||||
database::{dtos::TransactionRow, transactions as db},
|
||||
domain::{Cents, Transaction},
|
||||
};
|
||||
|
||||
@@ -35,7 +36,7 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Transaction>,
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transactions = db::query_transactions(executor, query.try_into()?)
|
||||
let transactions = db::query(executor, query.try_into()?)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
@@ -48,10 +49,7 @@ pub async fn get<'e, E>(executor: E, id: Uuid) -> Result<Option<Transaction>, Re
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transaction = db::get_transaction_by_id(executor, id)
|
||||
.await?
|
||||
.map(decode)
|
||||
.transpose()?;
|
||||
let transaction = db::get_by_id(executor, id).await?.map(decode).transpose()?;
|
||||
|
||||
Ok(transaction)
|
||||
}
|
||||
@@ -63,18 +61,18 @@ pub async fn upsert<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transaction = db::upsert_transaction(executor, encode(transaction))
|
||||
let transaction = db::upsert(executor, encode(transaction))
|
||||
.await?
|
||||
.try_map(decode)?;
|
||||
|
||||
Ok(transaction)
|
||||
Ok(transaction.into())
|
||||
}
|
||||
|
||||
pub async fn delete<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::delete_transaction_by_id(executor, id).await?)
|
||||
Ok(db::delete_by_id(executor, id).await?.into())
|
||||
}
|
||||
|
||||
fn decode(row: TransactionRow) -> Result<Transaction, DecodeError> {
|
||||
|
||||
Reference in New Issue
Block a user