Standardized the upsert and delete pattern across the repo.
This commit is contained in:
@@ -4,7 +4,7 @@ use uuid::Uuid;
|
||||
|
||||
use super::{
|
||||
DecodeError, QueryConversionError, ReferenceRelation, ReferenceViolationKind, RepositoryError,
|
||||
dtos::{Delete, Upsert},
|
||||
dtos::Upsert,
|
||||
};
|
||||
use crate::{
|
||||
database::{Constraint, DatabaseError, accounts as db, dtos::AccountRow},
|
||||
@@ -91,16 +91,17 @@ where
|
||||
Ok(account)
|
||||
}
|
||||
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<Account>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let result = db::delete_by_id(executor, id)
|
||||
let account = db::delete_by_id(executor, id)
|
||||
.await
|
||||
.map_err(classify_delete_error)?
|
||||
.into();
|
||||
.map(decode)
|
||||
.transpose()?;
|
||||
|
||||
Ok(result)
|
||||
Ok(account)
|
||||
}
|
||||
|
||||
fn classify_delete_error(error: DatabaseError) -> RepositoryError {
|
||||
|
||||
Reference in New Issue
Block a user