add `created_at()` on IDs

This commit is contained in:
Joe Ardent 2023-06-29 16:27:21 -07:00
parent 5782651aa6
commit 1f8e642612
5 changed files with 11 additions and 3 deletions

1
Cargo.lock generated
View File

@ -2338,6 +2338,7 @@ dependencies = [
"axum-login",
"axum-macros",
"axum-test",
"chrono",
"justerror",
"optional_optional_user",
"password-hash",

View File

@ -23,10 +23,11 @@ password-hash = { version = "0.5", features = ["std", "getrandom"] }
axum-login = { version = "0.5", features = ["sqlite", "sqlx"] }
unicode-segmentation = "1"
async-session = "3"
ulid = { version = "1.0.0", features = ["rand"] }
ulid = { version = "1", features = ["rand"] }
# proc macros:
optional_optional_user = {path = "optional_optional_user"}
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }
[dev-dependencies]
axum-test = "9.0.0"

View File

@ -3,6 +3,7 @@ use std::{
fmt::{Debug, Display},
};
use chrono::Utc;
use serde::{de::Visitor, Deserialize, Serialize};
use sqlx::{
encode::IsNull,
@ -39,6 +40,10 @@ impl DbId {
pub fn as_string(&self) -> String {
self.0.to_string()
}
pub fn created_at(&self) -> chrono::DateTime<Utc> {
self.0.datetime().into()
}
}
//-************************************************************************

View File

@ -110,7 +110,8 @@ pub async fn post_create_user(
let id = DbId::new();
let user = create_user(username, &displayname, &email, password, &pool, id).await?;
tracing::debug!("created {user:?}");
let now = user.id.created_at();
tracing::debug!("created {user:?} at {now:?}");
let id = user.id.as_string();
let location = format!("/signup_success/{id}");

View File

@ -26,7 +26,7 @@ pub struct User {
impl Debug for User {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("User")
.field("id", &self.id)
.field("id", &self.id.as_string())
.field("username", &self.username)
.field("displayname", &self.displayname)
.field("email", &self.email)