Files
Ydisks-Xianyu-Helper/internal/db/notifications.go
T
2026-06-28 11:54:39 +08:00

42 lines
1.1 KiB
Go

package db
import (
"context"
"database/sql"
)
// NotificationChannel 通知渠道(含配置 JSON)。
type NotificationChannel struct {
ID int64
Name string
Type string
Config string // JSON
}
// Notifications 通知绑定操作。
type Notifications struct{ DB *sql.DB }
// AccountChannels 取某账号已启用的通知渠道(message_notifications JOIN notification_channels)。
// 移植自 get_account_notifications。
func (n *Notifications) AccountChannels(ctx context.Context, cookieID string) ([]NotificationChannel, error) {
rows, err := n.DB.QueryContext(ctx,
`SELECT nc.id, nc.name, nc.type, nc.config
FROM message_notifications mn
JOIN notification_channels nc ON mn.channel_id = nc.id
WHERE mn.cookie_id=? AND mn.enabled=1 AND nc.enabled=1
ORDER BY mn.id`, cookieID)
if err != nil {
return nil, err
}
defer rows.Close()
var out []NotificationChannel
for rows.Next() {
var c NotificationChannel
if err := rows.Scan(&c.ID, &c.Name, &c.Type, &c.Config); err != nil {
return nil, err
}
out = append(out, c)
}
return out, rows.Err()
}