add created_at()
on IDs
This commit is contained in:
parent
5782651aa6
commit
1f8e642612
5 changed files with 11 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2338,6 +2338,7 @@ dependencies = [
|
||||||
"axum-login",
|
"axum-login",
|
||||||
"axum-macros",
|
"axum-macros",
|
||||||
"axum-test",
|
"axum-test",
|
||||||
|
"chrono",
|
||||||
"justerror",
|
"justerror",
|
||||||
"optional_optional_user",
|
"optional_optional_user",
|
||||||
"password-hash",
|
"password-hash",
|
||||||
|
|
|
@ -23,10 +23,11 @@ password-hash = { version = "0.5", features = ["std", "getrandom"] }
|
||||||
axum-login = { version = "0.5", features = ["sqlite", "sqlx"] }
|
axum-login = { version = "0.5", features = ["sqlite", "sqlx"] }
|
||||||
unicode-segmentation = "1"
|
unicode-segmentation = "1"
|
||||||
async-session = "3"
|
async-session = "3"
|
||||||
ulid = { version = "1.0.0", features = ["rand"] }
|
ulid = { version = "1", features = ["rand"] }
|
||||||
|
|
||||||
# proc macros:
|
# proc macros:
|
||||||
optional_optional_user = {path = "optional_optional_user"}
|
optional_optional_user = {path = "optional_optional_user"}
|
||||||
|
chrono = { version = "0.4", default-features = false, features = ["std", "clock"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
axum-test = "9.0.0"
|
axum-test = "9.0.0"
|
||||||
|
|
|
@ -3,6 +3,7 @@ use std::{
|
||||||
fmt::{Debug, Display},
|
fmt::{Debug, Display},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use chrono::Utc;
|
||||||
use serde::{de::Visitor, Deserialize, Serialize};
|
use serde::{de::Visitor, Deserialize, Serialize};
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
encode::IsNull,
|
encode::IsNull,
|
||||||
|
@ -39,6 +40,10 @@ impl DbId {
|
||||||
pub fn as_string(&self) -> String {
|
pub fn as_string(&self) -> String {
|
||||||
self.0.to_string()
|
self.0.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn created_at(&self) -> chrono::DateTime<Utc> {
|
||||||
|
self.0.datetime().into()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
|
|
|
@ -110,7 +110,8 @@ pub async fn post_create_user(
|
||||||
let id = DbId::new();
|
let id = DbId::new();
|
||||||
|
|
||||||
let user = create_user(username, &displayname, &email, password, &pool, id).await?;
|
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 id = user.id.as_string();
|
||||||
let location = format!("/signup_success/{id}");
|
let location = format!("/signup_success/{id}");
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub struct User {
|
||||||
impl Debug for User {
|
impl Debug for User {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("User")
|
f.debug_struct("User")
|
||||||
.field("id", &self.id)
|
.field("id", &self.id.as_string())
|
||||||
.field("username", &self.username)
|
.field("username", &self.username)
|
||||||
.field("displayname", &self.displayname)
|
.field("displayname", &self.displayname)
|
||||||
.field("email", &self.email)
|
.field("email", &self.email)
|
||||||
|
|
Loading…
Reference in a new issue