- Rename Go module switchboard-core → armature (155+ files) - Rename Docker image → gobha/armature - Rename K8s resources, secrets, deployments - Rename Prometheus metrics switchboard_* → armature_* - Rename env vars SWITCHBOARD_ADMIN_* → ARMATURE_ADMIN_* - Rename DB names switchboard_core* → armature* - Update all frontend branding, notification templates, docs - Update CI scripts, e2e tests, Keycloak realm, nginx conf - Rename scripts/switchboard-ca.sh → scripts/armature-ca.sh - Rename k8s/switchboard.yaml → k8s/armature.yaml - Rename chart alerting/dashboard files - Fix: DockerHub push uses env: binding for secret injection - Helm chart updated (name, labels, template functions, dashboard, alerting) - Replace favicon/icon assets with Armature brand No functional changes. Pure mechanical rename + CI fix. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"armature/models"
|
|
)
|
|
|
|
type NotificationPreferenceStore struct{}
|
|
|
|
func NewNotificationPreferenceStore() *NotificationPreferenceStore {
|
|
return &NotificationPreferenceStore{}
|
|
}
|
|
|
|
func (s *NotificationPreferenceStore) Get(ctx context.Context, userID, notifType string) (*models.NotificationPreference, error) {
|
|
var p models.NotificationPreference
|
|
err := DB.QueryRowContext(ctx, `
|
|
SELECT id, user_id, type, in_app, email
|
|
FROM notification_preferences
|
|
WHERE user_id = $1 AND type = $2`, userID, notifType).Scan(
|
|
&p.ID, &p.UserID, &p.Type, &p.InApp, &p.Email)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &p, nil
|
|
}
|
|
|
|
func (s *NotificationPreferenceStore) ListForUser(ctx context.Context, userID string) ([]models.NotificationPreference, error) {
|
|
rows, err := DB.QueryContext(ctx, `
|
|
SELECT id, user_id, type, in_app, email
|
|
FROM notification_preferences
|
|
WHERE user_id = $1
|
|
ORDER BY type`, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var result []models.NotificationPreference
|
|
for rows.Next() {
|
|
var p models.NotificationPreference
|
|
if err := rows.Scan(&p.ID, &p.UserID, &p.Type, &p.InApp, &p.Email); err != nil {
|
|
return nil, err
|
|
}
|
|
result = append(result, p)
|
|
}
|
|
return result, rows.Err()
|
|
}
|
|
|
|
func (s *NotificationPreferenceStore) Upsert(ctx context.Context, pref *models.NotificationPreference) error {
|
|
_, err := DB.ExecContext(ctx, `
|
|
INSERT INTO notification_preferences (user_id, type, in_app, email)
|
|
VALUES ($1, $2, $3, $4)
|
|
ON CONFLICT (user_id, type) DO UPDATE SET
|
|
in_app = $3, email = $4`,
|
|
pref.UserID, pref.Type, pref.InApp, pref.Email)
|
|
return err
|
|
}
|
|
|
|
func (s *NotificationPreferenceStore) Delete(ctx context.Context, userID, notifType string) error {
|
|
_, err := DB.ExecContext(ctx, `
|
|
DELETE FROM notification_preferences
|
|
WHERE user_id = $1 AND type = $2`, userID, notifType)
|
|
return err
|
|
}
|