From 140895a373443addd4be656a98d97e7eeadef21c Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 24 Aug 2023 18:18:53 +0100 Subject: [PATCH] refactor: [#256] extract struct AddTorrentResponse --- src/services/torrent.rs | 14 ++++++++++++-- src/web/api/v1/contexts/torrent/handlers.rs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/services/torrent.rs b/src/services/torrent.rs index 88e5dfe5..aa6b8b0b 100644 --- a/src/services/torrent.rs +++ b/src/services/torrent.rs @@ -43,6 +43,12 @@ pub struct AddTorrentRequest { pub torrent_buffer: Vec, } +pub struct AddTorrentResponse { + pub torrent_id: TorrentId, + pub info_hash: String, + pub original_info_hash: String, +} + /// User request to generate a torrent listing. #[derive(Debug, Deserialize)] pub struct ListingRequest { @@ -120,7 +126,7 @@ impl Index { &self, add_torrent_form: AddTorrentRequest, user_id: UserId, - ) -> Result<(TorrentId, InfoHash), ServiceError> { + ) -> Result { let metadata = Metadata { title: add_torrent_form.title, description: add_torrent_form.description, @@ -184,7 +190,11 @@ impl Index { .link_torrent_to_tags(&torrent_id, &metadata.tags) .await?; - Ok((torrent_id, info_hash)) + Ok(AddTorrentResponse { + torrent_id, + info_hash: info_hash.to_string(), + original_info_hash: original_info_hash.to_string(), + }) } /// Gets a torrent from the Index. diff --git a/src/web/api/v1/contexts/torrent/handlers.rs b/src/web/api/v1/contexts/torrent/handlers.rs index 31cd29ca..1c902522 100644 --- a/src/web/api/v1/contexts/torrent/handlers.rs +++ b/src/web/api/v1/contexts/torrent/handlers.rs @@ -49,7 +49,7 @@ pub async fn upload_torrent_handler( }; match app_data.torrent_service.add_torrent(add_torrent_form, user_id).await { - Ok(torrent_ids) => new_torrent_response(torrent_ids.0, &torrent_ids.1.to_hex_string()).into_response(), + Ok(response) => new_torrent_response(response.torrent_id, &response.info_hash).into_response(), Err(error) => error.into_response(), } }