Skip to content

Commit

Permalink
Merge #265: Add torrent name to torrent list an detail endpoints
Browse files Browse the repository at this point in the history
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
  • Loading branch information
josecelano committed Sep 11, 2023
2 parents f493964 + 7c4b530 commit 9ba65cc
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl Database for Mysql {
};

let mut query_string = format!(
"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,
"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,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down Expand Up @@ -629,7 +629,7 @@ impl Database for Mysql {

async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result<TorrentListing, database::Error> {
query_as::<_, TorrentListing>(
"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,
"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,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand All @@ -647,7 +647,7 @@ impl Database for Mysql {

async fn get_torrent_listing_from_info_hash(&self, info_hash: &InfoHash) -> Result<TorrentListing, database::Error> {
query_as::<_, TorrentListing>(
"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,
"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,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down
6 changes: 3 additions & 3 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl Database for Sqlite {
};

let mut query_string = format!(
"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,
"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,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down Expand Up @@ -617,7 +617,7 @@ impl Database for Sqlite {

async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result<TorrentListing, database::Error> {
query_as::<_, TorrentListing>(
"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,
"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,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand All @@ -635,7 +635,7 @@ impl Database for Sqlite {

async fn get_torrent_listing_from_info_hash(&self, info_hash: &InfoHash) -> Result<TorrentListing, database::Error> {
query_as::<_, TorrentListing>(
"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,
"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,
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
FROM torrust_torrents tt
Expand Down
2 changes: 2 additions & 0 deletions src/models/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct TorrentResponse {
pub trackers: Vec<String>,
pub magnet_link: String,
pub tags: Vec<TorrentTag>,
pub name: String,
}

impl TorrentResponse {
Expand All @@ -81,6 +82,7 @@ impl TorrentResponse {
trackers: vec![],
magnet_link: String::new(),
tags: vec![],
name: torrent_listing.name,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/models/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct TorrentListing {
pub file_size: i64,
pub seeders: i64,
pub leechers: i64,
pub name: String,
}

#[derive(Debug, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions tests/common/contexts/torrent/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct TorrentIndexInfo {
pub description: String,
pub category: String,
pub torrent_file: BinaryFile,
pub name: String,
}

impl From<TorrentIndexInfo> for UploadTorrentMultipartForm {
Expand Down Expand Up @@ -84,6 +85,7 @@ impl TestTorrent {
description: format!("description-{id}"),
category: software_predefined_category_name(),
torrent_file,
name: format!("name-{id}"),
};

TestTorrent {
Expand Down
2 changes: 2 additions & 0 deletions tests/common/contexts/torrent/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct ListItem {
pub file_size: i64,
pub seeders: i64,
pub leechers: i64,
pub name: String,
}

#[derive(Deserialize, PartialEq, Debug)]
Expand All @@ -60,6 +61,7 @@ pub struct TorrentDetails {
pub files: Vec<File>,
pub trackers: Vec<String>,
pub magnet_link: String,
pub name: String,
}

#[derive(Deserialize, PartialEq, Debug)]
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/web/api/v1/contexts/torrent/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ mod for_guests {
encoded_tracker_url,
encoded_tracker_url
),
name: test_torrent.index_info.name.clone(),
};

assert_expected_torrent_details(&torrent_details_response.data, &expected_torrent);
Expand Down

0 comments on commit 9ba65cc

Please sign in to comment.