More layout and customisations.
This commit is contained in:
11
storage/badgecounts.go
Normal file
11
storage/badgecounts.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package storage
|
||||
|
||||
// "database/sql"
|
||||
|
||||
// // Get all for count
|
||||
// var count int
|
||||
// db.Get(&count, `SELECT COUNT(*) FROM user_notifications WHERE user_id = ? AND is_read = FALSE`, userID)
|
||||
|
||||
// // Then get the top 15 for display
|
||||
// var notifications []Notification
|
||||
// db.Select(¬ifications, `SELECT * FROM user_notifications WHERE user_id = ? AND is_read = FALSE ORDER BY created_at DESC LIMIT 15`, userID)
|
||||
@@ -135,16 +135,46 @@ func InitDB(filepath string) *sql.DB {
|
||||
|
||||
createUsersTable := `
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL,
|
||||
is_admin BOOLEAN
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL,
|
||||
is_admin BOOLEAN
|
||||
);`
|
||||
|
||||
if _, err := db.Exec(createUsersTable); err != nil {
|
||||
log.Fatal("❌ Failed to create Users table:", err)
|
||||
}
|
||||
|
||||
createUsersMessageTable := `
|
||||
CREATE TABLE IF NOT EXISTS users_messages (
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||
title TEXT NOT NULL,
|
||||
message TEXT,
|
||||
is_read BOOLEAN DEFAULT FALSE,
|
||||
type VARCHAR(50),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);`
|
||||
|
||||
if _, err := db.Exec(createUsersMessageTable); err != nil {
|
||||
log.Fatal("❌ Failed to create Users messages table:", err)
|
||||
}
|
||||
|
||||
createUsersNotificationTable := `
|
||||
CREATE TABLE IF NOT EXISTS users_notification (
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||
sender_name VARCHAR(100),
|
||||
subject TEXT,
|
||||
body TEXT,
|
||||
is_read BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);`
|
||||
|
||||
if _, err := db.Exec(createUsersNotificationTable); err != nil {
|
||||
log.Fatal("❌ Failed to create Users notification table:", err)
|
||||
}
|
||||
|
||||
createAuditLogTable := `
|
||||
CREATE TABLE IF NOT EXISTS auditlog (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
||||
Reference in New Issue
Block a user