Skip to content

Commit

Permalink
refactor: rename mod time to clock
Browse files Browse the repository at this point in the history
And safer type convertion from i64 (timestamp) to u64.
  • Loading branch information
josecelano committed May 5, 2023
1 parent d2f8db9 commit df650db
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::config::Configuration;
use crate::databases::database::Database;
use crate::errors::ServiceError;
use crate::models::user::{UserClaims, UserCompact};
use crate::utils::time::current_time;
use crate::utils::clock::current_time;

pub struct AuthorizationService {
cfg: Arc<Configuration>,
Expand Down
2 changes: 1 addition & 1 deletion src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::models::torrent::TorrentListing;
use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile};
use crate::models::tracker_key::TrackerKey;
use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile};
use crate::utils::clock::current_time;
use crate::utils::hex::bytes_to_hex;
use crate::utils::time::current_time;

pub struct MysqlDatabase {
pub pool: MySqlPool,
Expand Down
2 changes: 1 addition & 1 deletion src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::models::torrent::TorrentListing;
use crate::models::torrent_file::{DbTorrentAnnounceUrl, DbTorrentFile, DbTorrentInfo, Torrent, TorrentFile};
use crate::models::tracker_key::TrackerKey;
use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile};
use crate::utils::clock::current_time;
use crate::utils::hex::bytes_to_hex;
use crate::utils::time::current_time;

pub struct SqliteDatabase {
pub pool: SqlitePool,
Expand Down
2 changes: 1 addition & 1 deletion src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};

use crate::config::Configuration;
use crate::errors::ServiceError;
use crate::utils::time::current_time;
use crate::utils::clock::current_time;

pub struct MailerService {
cfg: Arc<Configuration>,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::errors::{ServiceError, ServiceResult};
use crate::mailer::VerifyClaims;
use crate::models::response::{OkResponse, TokenResponse};
use crate::models::user::UserAuthentication;
use crate::utils::clock::current_time;
use crate::utils::regex::validate_email_address;
use crate::utils::time::current_time;

pub fn init_routes(cfg: &mut web::ServiceConfig) {
cfg.service(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct TorrentRecordV2 {
}

impl TorrentRecordV2 {
#[must_use]
pub fn from_v1_data(torrent: &TorrentRecordV1, torrent_info: &TorrentInfo, uploader: &UserRecordV1) -> Self {
Self {
torrent_id: torrent.torrent_id,
Expand Down Expand Up @@ -75,7 +76,7 @@ impl SqliteDatabaseV2_0_0 {
sqlx::migrate!("migrations/sqlite3")
.run(&self.pool)
.await
.expect("Could not run database migrations.")
.expect("Could not run database migrations.");
}

pub async fn reset_categories_sequence(&self) -> Result<SqliteQueryResult, DatabaseError> {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/clock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[must_use]
pub fn current_time() -> u64 {
u64::try_from(chrono::prelude::Utc::now().timestamp()).expect("timestamp should be positive")
}
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod clock;
pub mod hex;
pub mod parse_torrent;
pub mod regex;
pub mod time;
3 changes: 0 additions & 3 deletions src/utils/time.rs

This file was deleted.

0 comments on commit df650db

Please sign in to comment.