Files
imphnen-backend-service/imphnen-entities/src/seaorm/common/utils.rs
T
maulanasdqnandClaude Sonnet 4.6 331a4a4e88 feat: v0.3.0 — standardize codebase, centralize infra, merge QR into CMS
- Enforce axum best practices across all 13 workspace crates
  (max 200 LOC/file, no comments, no unwrap, clean architecture)
- Fix domain→infrastructure dependency inversions in imphnen-iam and imphnen-dimentorin
- Extract imphnen-storage (MinIO) and imphnen-email (Lettre) as standalone crates
- Centralize all config in ENV struct: CDN_URL, CORS_ALLOWED_ORIGINS
- Centralize SMTP through imphnen-email; remove dead HackathonConfig
- Centralize database: QR crate now shares main DB pool (single DATABASE_URL)
- Rename QR users table to qr_users to avoid collision with main users table
- Merge imphnen-qr into imphnen-cms/src/qr (13 crates, down from 14)
- Restructure imphnen-hackathon flat modules into clean architecture
- Remove all stale env vars from .env.example (SurrealDB, QR_JWT, Hackathon infra)
- Fix Dockerfile to include all current workspace crates
- Bump all crate versions 0.2.0 → 0.3.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 22:29:08 +07:00

75 lines
1.6 KiB
Rust

use chrono::{DateTime, Utc};
use uuid::Uuid;
use super::types::{PgTimestamp, PgUuid};
pub fn generate_uuid() -> Uuid {
Uuid::new_v4()
}
pub fn generate_timestamp() -> PgTimestamp {
PgTimestamp(Utc::now())
}
pub fn string_to_uuid(uuid_str: &str) -> Result<PgUuid, String> {
Uuid::parse_str(uuid_str)
.map(PgUuid)
.map_err(|e| format!("Invalid UUID format: {e}"))
}
pub fn uuid_to_string(uuid: &uuid::Uuid) -> String {
uuid.to_string()
}
pub fn current_timestamp() -> DateTime<Utc> {
Utc::now()
}
pub fn format_timestamp(timestamp: &PgTimestamp) -> String {
timestamp.0.format("%Y-%m-%d %H:%M:%S UTC").to_string()
}
pub fn create_deleted_at() -> Option<DateTime<Utc>> {
Some(current_timestamp())
}
pub fn remove_deleted_at() -> Option<PgTimestamp> {
None
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_generate_uuid() {
let uuid1 = generate_uuid();
let uuid2 = generate_uuid();
assert_ne!(uuid1, uuid2);
assert!(Uuid::parse_str(&uuid_to_string(&uuid1)).is_ok());
}
#[test]
fn test_generate_timestamp() {
let ts1 = generate_timestamp();
let ts2 = generate_timestamp();
let diff = ts2.0.signed_duration_since(ts1.0).num_milliseconds();
assert!(diff >= 0);
assert!(diff < 1000);
}
#[test]
fn test_string_to_uuid() {
let uuid_str = "123e4567-e89b-12d3-a456-426614174000";
let result = string_to_uuid(uuid_str);
assert!(result.is_ok());
let uuid = result.unwrap();
let uuid_plain: uuid::Uuid = uuid.into();
assert_eq!(uuid_to_string(&uuid_plain), uuid_str);
let invalid_uuid = "invalid-uuid";
let result = string_to_uuid(invalid_uuid);
assert!(result.is_err());
}
}