Fix MongoDB DateTime serialization issues - Replace chrono::DateTime with mongodb::bson::DateTime in models - Update API responses to use timestamp_millis() for JSON serialization - Fix User, Share model DateTime fields - Update all handler responses to return i64 timestamps - This fixes the Kind: invalid type: map, expected RFC 3339 error
This commit is contained in:
parent
1e914089d5
commit
3a6bcbd94d
5 changed files with 25 additions and 20 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use mongodb::bson::{doc, oid::ObjectId};
|
||||
use mongodb::Collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use mongodb::bson::DateTime;
|
||||
|
||||
use super::permission::Permission;
|
||||
|
||||
|
|
@ -15,8 +16,8 @@ pub struct Share {
|
|||
pub resource_id: Option<ObjectId>,
|
||||
pub permissions: Vec<Permission>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expires_at: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub expires_at: Option<DateTime>,
|
||||
pub created_at: DateTime,
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ impl Share {
|
|||
resource_type: String,
|
||||
resource_id: Option<ObjectId>,
|
||||
permissions: Vec<Permission>,
|
||||
expires_at: Option<chrono::DateTime<chrono::Utc>>,
|
||||
expires_at: Option<DateTime>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
|
|
@ -37,14 +38,14 @@ impl Share {
|
|||
resource_id,
|
||||
permissions,
|
||||
expires_at,
|
||||
created_at: chrono::Utc::now(),
|
||||
created_at: DateTime::now(),
|
||||
active: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_expired(&self) -> bool {
|
||||
if let Some(expires) = self.expires_at {
|
||||
chrono::Utc::now() > expires
|
||||
DateTime::now() > expires
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use mongodb::bson::{doc, oid::ObjectId};
|
|||
use mongodb::Collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use mongodb::bson::DateTime;
|
||||
use crate::auth::password::verify_password;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
|
@ -26,10 +27,10 @@ pub struct User {
|
|||
pub token_version: i32,
|
||||
|
||||
/// When the user was created
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub created_at: DateTime,
|
||||
|
||||
/// Last time the user was active
|
||||
pub last_active: chrono::DateTime<chrono::Utc>,
|
||||
pub last_active: DateTime,
|
||||
|
||||
/// Email verification status
|
||||
pub email_verified: bool,
|
||||
|
|
@ -40,7 +41,7 @@ pub struct User {
|
|||
|
||||
/// When the verification token expires
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub verification_expires: Option<chrono::DateTime<chrono::Utc>>,
|
||||
pub verification_expires: Option<DateTime>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
|
|
@ -64,7 +65,7 @@ impl User {
|
|||
None
|
||||
};
|
||||
|
||||
let now = chrono::Utc::now();
|
||||
let now = DateTime::now();
|
||||
let recovery_enabled = recovery_phrase_hash.is_some();
|
||||
|
||||
Ok(User {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue