add timestamp to ChatMessage struct

This commit is contained in:
2025-06-07 14:11:33 +02:00
parent 19fd34b92c
commit 016940a45c
3 changed files with 10 additions and 1 deletions

2
Cargo.lock generated
View File

@@ -336,6 +336,7 @@ dependencies = [
"axum",
"axum-valid",
"axum_typed_multipart",
"chrono",
"futures-util",
"serde",
"serde_json",
@@ -353,6 +354,7 @@ dependencies = [
"iana-time-zone",
"js-sys",
"num-traits",
"serde",
"wasm-bindgen",
"windows-link",
]

View File

@@ -13,3 +13,4 @@ axum-valid = { path = "../axum-valid", features = ["basic", "typed_multipart", "
validify = "2.0.0"
axum_typed_multipart = "0.16.2"
serde_json = "1.0.140"
chrono = { version = "0.4.41", features = ["serde"] }

View File

@@ -1,3 +1,4 @@
use chrono::{NaiveDateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -5,10 +6,15 @@ use serde::{Deserialize, Serialize};
pub struct ChatMessage {
pub sender_id: u32,
pub content: String,
pub timestamp: NaiveDateTime,
}
impl ChatMessage {
pub fn new(sender_id: u32, content: String) -> Self {
Self { sender_id, content }
Self {
sender_id,
content,
timestamp: Utc::now().naive_utc(),
}
}
}