Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions backend/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Database {
pub async fn soft_delete(&self, id: i32) -> Result<bool, color_eyre::eyre::Error> {
let mut tx = self.connection.begin().await?;

let rows_affected = sqlx::query(queries::SOFT_DELETE_BY_ID)
let rows_affected = sqlx::query(queries::SOFT_DELETE_ANY_BY_ID)
.bind(id)
.execute(&mut *tx)
.await?
Expand Down Expand Up @@ -255,7 +255,10 @@ impl Database {
}

/// Permanently deletes a paper from the database
pub async fn hard_delete(&self, id: i32) -> Result<Transaction<'_, Postgres>, color_eyre::eyre::Error> {
pub async fn hard_delete(
&self,
id: i32,
) -> Result<Transaction<'_, Postgres>, color_eyre::eyre::Error> {
let mut tx = self.connection.begin().await?;
let rows_affected = sqlx::query(queries::HARD_DELETE_BY_ID)
.bind(id)
Expand All @@ -267,10 +270,10 @@ impl Database {
return Err(eyre!(
"Error: {} (> 1) papers were deleted. Rolling back.",
rows_affected
))
));
} else if rows_affected < 1 {
tx.rollback().await?;
return Err(eyre!("Error: No papers were deleted."))
return Err(eyre!("Error: No papers were deleted."));
}
Ok(tx)
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/routing/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub struct DeleteReq {
id: i32,
}

/// Deletes a given paper. Library papers cannot be deleted.
/// (Soft) Deletes a given paper.
///
/// Request format - [`DeleteReq`]
pub async fn delete(
Expand All @@ -468,7 +468,7 @@ pub async fn delete(
))
} else {
Ok(BackendResponse::error(
"No paper was changed. Either the paper does not exist, is a library paper (cannot be deleted), or is already deleted.".into(),
"No paper was changed. Either the paper does not exist, or is already deleted.".into(),
StatusCode::BAD_REQUEST,
))
}
Expand All @@ -485,7 +485,7 @@ pub struct HardDeleteReq {
pub struct DeleteStatus {
id: i32,
status: Status,
message: String
message: String,
}

/// Hard deletes papers from a list of ids.
Expand Down