Skip to content

Commit 3eeecd5

Browse files
committed
feat: Give error if an item could not be removed from a comic
1 parent e5c17f4 commit 3eeecd5

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/controllers/api/comic/remove_item.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ pub(crate) async fn remove_item(
4141
.map_err(error::ErrorInternalServerError)?
4242
.ok_or_else(|| error::ErrorBadRequest(anyhow!("Item does not exist")))?;
4343

44-
DatabaseOccurrence::delete(
45-
&mut *transaction,
46-
request.item_id.into_inner(),
47-
request.comic_id.into_inner(),
48-
)
49-
.await
50-
.map_err(error::ErrorInternalServerError)?;
44+
let item_id = request.item_id.into_inner();
45+
let comic_id = request.comic_id.into_inner();
46+
let result = DatabaseOccurrence::delete(&mut *transaction, item_id, comic_id)
47+
.await
48+
.map_err(error::ErrorInternalServerError)?;
49+
50+
if result.rows_affected() != 1 {
51+
return Err(error::ErrorNotFound(format!(
52+
"Could not delete item {} from comic {}; the item is not in the comic",
53+
item_id, comic_id
54+
)));
55+
}
5156

5257
LogEntry::log_action(
5358
&mut *transaction,

0 commit comments

Comments
 (0)