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
Some checks failed
Lint and Build / Lint (push) Failing after 5s
Lint and Build / Build (push) Has been skipped
Lint and Build / Docker Build (push) Has been skipped

This commit is contained in:
goose 2026-02-26 09:22:36 -03:00
parent 1e914089d5
commit 3a6bcbd94d
5 changed files with 25 additions and 20 deletions

View file

@ -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
}

View file

@ -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 {