package auditlog import ( "crypto/md5" "fmt" "time" ) // // ======================================================= // 🕵️ AUDIT LOG — HELPER FUNCTIONS // ======================================================= // Bu dosya: // - UUID bekleyen kolonlar için int → uuid dönüşümü // - NULL-safe insert yardımcıları // içerir // // ------------------------------------------------------- // 🔹 IntUserIDToUUID // ------------------------------------------------------- // int user_id → deterministic UUID // PostgreSQL uuid kolonu ile %100 uyumlu // // Aynı userID → her zaman aynı UUID func IntUserIDToUUID(userID int) string { if userID <= 0 { return "" } sum := md5.Sum([]byte(fmt.Sprintf("bssapp-user-%d", userID))) return fmt.Sprintf( "%x-%x-%x-%x-%x", sum[0:4], sum[4:6], sum[6:8], sum[8:10], sum[10:16], ) } // ------------------------------------------------------- // 🔹 nullIfZeroTime // ------------------------------------------------------- // Zero time → NULL (SQL uyumlu) func nullIfZeroTime(t time.Time) interface{} { if t.IsZero() { return nil } return t } // ------------------------------------------------------- // 🔹 nullIfZeroInt // ------------------------------------------------------- // 0 → NULL (SQL uyumlu) func nullIfZeroInt(v int) interface{} { if v == 0 { return nil } return v } func Int64UserIDToUUID(id int64) string { return IntUserIDToUUID(int(id)) } func nullIfEmpty(s string) any { if s == "" { return nil } return s }