Skip to content

Commit 41c80f3

Browse files
committed
Merge #315: feat: [#303] store in the database the torrent fields creation_date c…
c22f661 refactor: [#303] store in the database the torrent fields creation date created by encoding (Mario) c3d69f4 feat: [#303] store in the database the torrent fields creation date created_by encoding (MMelchor) aadde22 refactor: [#303] store in the database the torrent fields creation date created_by encoding (MMelchor) 0a48536 refactor: [#303] store in the database the torrent fields creation_date created_by encoding (MMelchor) b738291 feat: [#303] store in the database the torrent fields creation_date created_by encoding (MMelchor) Pull request description: Resolves #303. ACKs for top commit: josecelano: ACK c22f661 Tree-SHA512: 98e112f731b1ddd0f53eac8d55e01a7f77ec556fed32cfb07c42028c68bcdf0d27a7dcd615d97a6f04109f07707c748aa8d3fb7faed79d8997769ff1bec56961
2 parents 70cef70 + c22f661 commit 41c80f3

16 files changed

+75
-19
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE torrust_torrents ADD COLUMN creation_date BIGINT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE torrust_torrents ADD COLUMN created_by TEXT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE torrust_torrents ADD COLUMN `encoding` TEXT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "torrust_torrents" ADD COLUMN "creation_date" BIGINT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "torrust_torrents" ADD COLUMN "created_by" TEXT NULL;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "torrust_torrents" ADD COLUMN `encoding` TEXT NULL;

src/databases/mysql.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ impl Database for Mysql {
387387
tt.size AS file_size,
388388
tt.name,
389389
tt.comment,
390+
tt.creation_date,
391+
tt.created_by,
392+
tt.`encoding`,
390393
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
391394
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
392395
FROM torrust_torrents tt
@@ -465,8 +468,11 @@ impl Database for Mysql {
465468
root_hash,
466469
`source`,
467470
comment,
468-
date_uploaded
469-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP())",
471+
date_uploaded,
472+
creation_date,
473+
created_by,
474+
`encoding`
475+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP(), ?, ?, ?)",
470476
)
471477
.bind(uploader_id)
472478
.bind(metadata.category_id)
@@ -479,6 +485,9 @@ impl Database for Mysql {
479485
.bind(root_hash)
480486
.bind(torrent.info.source.clone())
481487
.bind(torrent.comment.clone())
488+
.bind(torrent.creation_date)
489+
.bind(torrent.created_by.clone())
490+
.bind(torrent.encoding.clone())
482491
.execute(&mut *tx)
483492
.await
484493
.map(|v| i64::try_from(v.last_insert_id()).expect("last ID is larger than i64"))
@@ -754,6 +763,9 @@ impl Database for Mysql {
754763
tt.size AS file_size,
755764
tt.name,
756765
tt.comment,
766+
tt.creation_date,
767+
tt.created_by,
768+
tt.`encoding`,
757769
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
758770
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
759771
FROM torrust_torrents tt
@@ -782,6 +794,9 @@ impl Database for Mysql {
782794
tt.size AS file_size,
783795
tt.name,
784796
tt.comment,
797+
tt.creation_date,
798+
tt.created_by,
799+
tt.`encoding`,
785800
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
786801
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
787802
FROM torrust_torrents tt

src/databases/sqlite.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ impl Database for Sqlite {
377377
tt.size AS file_size,
378378
tt.name,
379379
tt.comment,
380+
tt.creation_date,
381+
tt.created_by,
382+
tt.`encoding`,
380383
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
381384
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
382385
FROM torrust_torrents tt
@@ -455,8 +458,11 @@ impl Database for Sqlite {
455458
root_hash,
456459
`source`,
457460
comment,
458-
date_uploaded
459-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%d %H:%M:%S',DATETIME('now', 'utc')))",
461+
date_uploaded,
462+
creation_date,
463+
created_by,
464+
`encoding`
465+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%d %H:%M:%S',DATETIME('now', 'utc')), ?, ?, ?)",
460466
)
461467
.bind(uploader_id)
462468
.bind(metadata.category_id)
@@ -469,6 +475,9 @@ impl Database for Sqlite {
469475
.bind(root_hash)
470476
.bind(torrent.info.source.clone())
471477
.bind(torrent.comment.clone())
478+
.bind(torrent.creation_date)
479+
.bind(torrent.created_by.clone())
480+
.bind(torrent.encoding.clone())
472481
.execute(&mut *tx)
473482
.await
474483
.map(|v| v.last_insert_rowid())
@@ -743,6 +752,9 @@ impl Database for Sqlite {
743752
tt.size AS file_size,
744753
tt.name,
745754
tt.comment,
755+
tt.creation_date,
756+
tt.created_by,
757+
tt.`encoding`,
746758
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
747759
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
748760
FROM torrust_torrents tt
@@ -770,6 +782,9 @@ impl Database for Sqlite {
770782
tt.size AS file_size,
771783
tt.name,
772784
tt.comment,
785+
tt.creation_date,
786+
tt.created_by,
787+
tt.`encoding`,
773788
CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders,
774789
CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers
775790
FROM torrust_torrents tt

src/models/response.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ pub struct TorrentResponse {
6363
pub tags: Vec<TorrentTag>,
6464
pub name: String,
6565
pub comment: Option<String>,
66+
pub creation_date: Option<i64>,
67+
pub created_by: Option<String>,
68+
pub encoding: Option<String>,
6669
}
6770

6871
impl TorrentResponse {
@@ -85,6 +88,9 @@ impl TorrentResponse {
8588
tags: vec![],
8689
name: torrent_listing.name,
8790
comment: torrent_listing.comment,
91+
creation_date: torrent_listing.creation_date,
92+
created_by: torrent_listing.created_by,
93+
encoding: torrent_listing.encoding,
8894
}
8995
}
9096
}

src/models/torrent.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub struct TorrentListing {
2525
pub leechers: i64,
2626
pub name: String,
2727
pub comment: Option<String>,
28+
pub creation_date: Option<i64>,
29+
pub created_by: Option<String>,
30+
pub encoding: Option<String>,
2831
}
2932

3033
#[derive(Debug, Display, PartialEq, Eq, Error)]

0 commit comments

Comments
 (0)