style: apply rustfmt to backend codebase
- Apply rustfmt to all Rust source files in backend/ - Fix trailing whitespace inconsistencies - Standardize formatting across handlers, models, and services - Improve code readability with consistent formatting These changes are purely stylistic and do not affect functionality. All CI checks now pass with proper formatting.
This commit is contained in:
parent
6b7e4d4016
commit
ee0feb77ef
41 changed files with 1266 additions and 819 deletions
|
|
@ -1,16 +1,16 @@
|
|||
use mongodb::{
|
||||
Collection,
|
||||
bson::{doc, oid::ObjectId},
|
||||
};
|
||||
use futures::stream::TryStreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use anyhow::Result;
|
||||
use futures::stream::TryStreamExt;
|
||||
use mongodb::{
|
||||
bson::{doc, oid::ObjectId},
|
||||
Collection,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::SystemTime;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DeviceInfo {
|
||||
pub device_type: String, // "mobile", "desktop", "tablet"
|
||||
pub os: String, // "iOS", "Android", "Windows", "macOS", "Linux"
|
||||
pub device_type: String, // "mobile", "desktop", "tablet"
|
||||
pub os: String, // "iOS", "Android", "Windows", "macOS", "Linux"
|
||||
pub browser: Option<String>,
|
||||
pub ip_address: String,
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ pub struct Session {
|
|||
pub id: Option<ObjectId>,
|
||||
pub user_id: ObjectId,
|
||||
pub device_info: DeviceInfo,
|
||||
pub token_hash: String, // Hash of the JWT token
|
||||
pub token_hash: String, // Hash of the JWT token
|
||||
pub created_at: mongodb::bson::DateTime,
|
||||
pub last_used_at: mongodb::bson::DateTime,
|
||||
pub expires_at: mongodb::bson::DateTime,
|
||||
|
|
@ -48,7 +48,7 @@ impl SessionRepository {
|
|||
) -> Result<ObjectId> {
|
||||
let now = SystemTime::now();
|
||||
let now_bson = mongodb::bson::DateTime::from(now);
|
||||
|
||||
|
||||
let expires_at = SystemTime::now()
|
||||
.checked_add(std::time::Duration::from_secs(duration_hours as u64 * 3600))
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid duration"))?;
|
||||
|
|
@ -65,11 +65,17 @@ impl SessionRepository {
|
|||
is_revoked: false,
|
||||
};
|
||||
|
||||
self.collection.insert_one(session, None).await?.inserted_id.as_object_id().ok_or_else(|| anyhow::anyhow!("Failed to get inserted id"))
|
||||
self.collection
|
||||
.insert_one(session, None)
|
||||
.await?
|
||||
.inserted_id
|
||||
.as_object_id()
|
||||
.ok_or_else(|| anyhow::anyhow!("Failed to get inserted id"))
|
||||
}
|
||||
|
||||
pub async fn find_by_user(&self, user_id: &ObjectId) -> Result<Vec<Session>> {
|
||||
let cursor = self.collection
|
||||
let cursor = self
|
||||
.collection
|
||||
.find(
|
||||
doc! {
|
||||
"user_id": user_id,
|
||||
|
|
@ -98,7 +104,7 @@ impl SessionRepository {
|
|||
pub async fn revoke_all_for_user(&self, user_id: &ObjectId) -> Result<()> {
|
||||
self.collection
|
||||
.update_many(
|
||||
doc! {
|
||||
doc! {
|
||||
"user_id": user_id,
|
||||
"is_revoked": false
|
||||
},
|
||||
|
|
@ -110,7 +116,8 @@ impl SessionRepository {
|
|||
}
|
||||
|
||||
pub async fn cleanup_expired(&self) -> Result<u64> {
|
||||
let result = self.collection
|
||||
let result = self
|
||||
.collection
|
||||
.delete_many(
|
||||
doc! {
|
||||
"expires_at": { "$lt": mongodb::bson::DateTime::now() }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue