Skip to content

Commit 9ba65cc

Browse files
committed
Merge #265: Add torrent name to torrent list an detail endpoints
7c4b530 test: [#264] Added torrent name to list and detail endpoints (MMelchor) f2369b4 feat: [#264] Added torrent name to list and detail endpoints (MMelchor) Pull request description: Resolves #264 ACKs for top commit: josecelano: ACK 7c4b530 Tree-SHA512: 77f2b6fde32d9b077c633866ce22d628ed54d5d8bf9a54b794b6f6defab8fd69a4be8022112721de9586bfb4d9b3454ee12df1601c7f0cceec6ff9bc45e204e9
2 parents f493964 + 7c4b530 commit 9ba65cc

File tree

7 files changed

+14
-6
lines changed

7 files changed

+14
-6
lines changed

src/databases/mysql.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ impl Database for Mysql {
375375
};
376376

377377
let mut query_string = format!(
378-
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size,
378+
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, tt.name,
379379
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
380380
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
381381
FROM torrust_torrents tt
@@ -629,7 +629,7 @@ impl Database for Mysql {
629629

630630
async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result<TorrentListing, database::Error> {
631631
query_as::<_, TorrentListing>(
632-
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size,
632+
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, tt.name,
633633
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
634634
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
635635
FROM torrust_torrents tt
@@ -647,7 +647,7 @@ impl Database for Mysql {
647647

648648
async fn get_torrent_listing_from_info_hash(&self, info_hash: &InfoHash) -> Result<TorrentListing, database::Error> {
649649
query_as::<_, TorrentListing>(
650-
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size,
650+
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, tt.name,
651651
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
652652
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
653653
FROM torrust_torrents tt

src/databases/sqlite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Database for Sqlite {
363363
};
364364

365365
let mut query_string = format!(
366-
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size,
366+
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, tt.name,
367367
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
368368
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
369369
FROM torrust_torrents tt
@@ -617,7 +617,7 @@ impl Database for Sqlite {
617617

618618
async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result<TorrentListing, database::Error> {
619619
query_as::<_, TorrentListing>(
620-
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size,
620+
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, tt.name,
621621
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
622622
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
623623
FROM torrust_torrents tt
@@ -635,7 +635,7 @@ impl Database for Sqlite {
635635

636636
async fn get_torrent_listing_from_info_hash(&self, info_hash: &InfoHash) -> Result<TorrentListing, database::Error> {
637637
query_as::<_, TorrentListing>(
638-
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size,
638+
"SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, tt.name,
639639
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
640640
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
641641
FROM torrust_torrents tt

src/models/response.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct TorrentResponse {
6161
pub trackers: Vec<String>,
6262
pub magnet_link: String,
6363
pub tags: Vec<TorrentTag>,
64+
pub name: String,
6465
}
6566

6667
impl TorrentResponse {
@@ -81,6 +82,7 @@ impl TorrentResponse {
8182
trackers: vec![],
8283
magnet_link: String::new(),
8384
tags: vec![],
85+
name: torrent_listing.name,
8486
}
8587
}
8688
}

src/models/torrent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct TorrentListing {
2020
pub file_size: i64,
2121
pub seeders: i64,
2222
pub leechers: i64,
23+
pub name: String,
2324
}
2425

2526
#[derive(Debug, Deserialize)]

tests/common/contexts/torrent/fixtures.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct TorrentIndexInfo {
1818
pub description: String,
1919
pub category: String,
2020
pub torrent_file: BinaryFile,
21+
pub name: String,
2122
}
2223

2324
impl From<TorrentIndexInfo> for UploadTorrentMultipartForm {
@@ -84,6 +85,7 @@ impl TestTorrent {
8485
description: format!("description-{id}"),
8586
category: software_predefined_category_name(),
8687
torrent_file,
88+
name: format!("name-{id}"),
8789
};
8890

8991
TestTorrent {

tests/common/contexts/torrent/responses.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct ListItem {
3838
pub file_size: i64,
3939
pub seeders: i64,
4040
pub leechers: i64,
41+
pub name: String,
4142
}
4243

4344
#[derive(Deserialize, PartialEq, Debug)]
@@ -60,6 +61,7 @@ pub struct TorrentDetails {
6061
pub files: Vec<File>,
6162
pub trackers: Vec<String>,
6263
pub magnet_link: String,
64+
pub name: String,
6365
}
6466

6567
#[derive(Deserialize, PartialEq, Debug)]

tests/e2e/web/api/v1/contexts/torrent/contract.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ mod for_guests {
208208
encoded_tracker_url,
209209
encoded_tracker_url
210210
),
211+
name: test_torrent.index_info.name.clone(),
211212
};
212213

213214
assert_expected_torrent_details(&torrent_details_response.data, &expected_torrent);

0 commit comments

Comments
 (0)