Skip to content

Commit df650db

Browse files
committed
refactor: rename mod time to clock
And safer type convertion from i64 (timestamp) to u64.
1 parent d2f8db9 commit df650db

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

src/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::config::Configuration;
77
use crate::databases::database::Database;
88
use crate::errors::ServiceError;
99
use crate::models::user::{UserClaims, UserCompact};
10-
use crate::utils::time::current_time;
10+
use crate::utils::clock::current_time;
1111

1212
pub struct AuthorizationService {
1313
cfg: Arc<Configuration>,

src/databases/mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::models::torrent::TorrentListing;
99
use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile};
1010
use crate::models::tracker_key::TrackerKey;
1111
use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile};
12+
use crate::utils::clock::current_time;
1213
use crate::utils::hex::bytes_to_hex;
13-
use crate::utils::time::current_time;
1414

1515
pub struct MysqlDatabase {
1616
pub pool: MySqlPool,

src/databases/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::models::torrent::TorrentListing;
99
use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile};
1010
use crate::models::tracker_key::TrackerKey;
1111
use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile};
12+
use crate::utils::clock::current_time;
1213
use crate::utils::hex::bytes_to_hex;
13-
use crate::utils::time::current_time;
1414

1515
pub struct SqliteDatabase {
1616
pub pool: SqlitePool,

src/mailer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
99

1010
use crate::config::Configuration;
1111
use crate::errors::ServiceError;
12-
use crate::utils::time::current_time;
12+
use crate::utils::clock::current_time;
1313

1414
pub struct MailerService {
1515
cfg: Arc<Configuration>,

src/routes/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::errors::{ServiceError, ServiceResult};
1313
use crate::mailer::VerifyClaims;
1414
use crate::models::response::{OkResponse, TokenResponse};
1515
use crate::models::user::UserAuthentication;
16+
use crate::utils::clock::current_time;
1617
use crate::utils::regex::validate_email_address;
17-
use crate::utils::time::current_time;
1818

1919
pub fn init_routes(cfg: &mut web::ServiceConfig) {
2020
cfg.service(

src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct TorrentRecordV2 {
2929
}
3030

3131
impl TorrentRecordV2 {
32+
#[must_use]
3233
pub fn from_v1_data(torrent: &TorrentRecordV1, torrent_info: &TorrentInfo, uploader: &UserRecordV1) -> Self {
3334
Self {
3435
torrent_id: torrent.torrent_id,
@@ -75,7 +76,7 @@ impl SqliteDatabaseV2_0_0 {
7576
sqlx::migrate!("migrations/sqlite3")
7677
.run(&self.pool)
7778
.await
78-
.expect("Could not run database migrations.")
79+
.expect("Could not run database migrations.");
7980
}
8081

8182
pub async fn reset_categories_sequence(&self) -> Result<SqliteQueryResult, DatabaseError> {

src/utils/clock.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[must_use]
2+
pub fn current_time() -> u64 {
3+
u64::try_from(chrono::prelude::Utc::now().timestamp()).expect("timestamp should be positive")
4+
}

src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
pub mod clock;
12
pub mod hex;
23
pub mod parse_torrent;
34
pub mod regex;
4-
pub mod time;

src/utils/time.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)