From a7f43dc19504f3efb0b3f61cd2350fe34e97e34c Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 6 Mar 2024 14:39:33 +0000 Subject: [PATCH] refactor: rename fields in upload torrent response to match latest changes in the database. From: ```json { "data": { "torrent_id": 12, "info_hash": "c01f910ff0cc2a1b8c7a1f6ab948377604d8c464", "original_info_hash": "dc0c6be689b28696319263ef27f9df4da8ded0a2" } } ``` To: ``` { "data": { "torrent_id": 12, "canonical_info_hash": "c01f910ff0cc2a1b8c7a1f6ab948377604d8c464", "info_hash": "dc0c6be689b28696319263ef27f9df4da8ded0a2" } } ``` --- src/services/torrent.rs | 6 +++--- src/web/api/server/v1/contexts/torrent/responses.rs | 4 ++-- tests/common/contexts/torrent/responses.rs | 1 + tests/e2e/web/api/v1/contexts/torrent/contract.rs | 2 +- tests/e2e/web/api/v1/contexts/torrent/steps.rs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/torrent.rs b/src/services/torrent.rs index 788eec19..c3c7e7f0 100644 --- a/src/services/torrent.rs +++ b/src/services/torrent.rs @@ -45,8 +45,8 @@ pub struct AddTorrentRequest { pub struct AddTorrentResponse { pub torrent_id: TorrentId, + pub canonical_info_hash: String, pub info_hash: String, - pub original_info_hash: String, } /// User request to generate a torrent listing. @@ -172,8 +172,8 @@ impl Index { Ok(AddTorrentResponse { torrent_id, - info_hash: torrent.canonical_info_hash_hex(), - original_info_hash: original_info_hash.to_string(), + canonical_info_hash: torrent.canonical_info_hash_hex(), + info_hash: original_info_hash.to_string(), }) } diff --git a/src/web/api/server/v1/contexts/torrent/responses.rs b/src/web/api/server/v1/contexts/torrent/responses.rs index d928f675..103e3a85 100644 --- a/src/web/api/server/v1/contexts/torrent/responses.rs +++ b/src/web/api/server/v1/contexts/torrent/responses.rs @@ -11,8 +11,8 @@ use crate::web::api::server::v1::responses::OkResponseData; #[derive(Serialize, Deserialize, Debug)] pub struct NewTorrentResponseData { pub torrent_id: TorrentId, + pub canonical_info_hash: String, pub info_hash: String, - pub original_info_hash: String, } /// Response after successfully uploading a new torrent. @@ -20,8 +20,8 @@ pub fn new_torrent_response(add_torrent_response: &AddTorrentResponse) -> Json } let uploaded_torrent_response: UploadedTorrentResponse = serde_json::from_str(&response.body).unwrap(); - let canonical_info_hash_hex = uploaded_torrent_response.data.info_hash.to_lowercase(); + let canonical_info_hash_hex = uploaded_torrent_response.data.canonical_info_hash.to_lowercase(); let canonical_info_hash = InfoHash::from_str(&canonical_info_hash_hex) .unwrap_or_else(|_| panic!("Invalid info-hash in database: {canonical_info_hash_hex}"));