feat: Added worked before in Net Control

This commit is contained in:
2026-07-07 22:39:17 +02:00
parent b9b005ea36
commit 86cbe94cae
8 changed files with 208 additions and 46 deletions
+28 -1
View File
@@ -46,6 +46,28 @@ func (r *Repo) List(ctx context.Context) ([]Record, error) {
return out, rows.Err()
}
// ListFor returns the templates VISIBLE to a profile: its own plus any shared
// (NULL-profile) ones — so each profile sees and defaults independently instead
// of one global list. Defaults first, then newest first.
func (r *Repo) ListFor(ctx context.Context, profileID int64) ([]Record, error) {
rows, err := r.db.QueryContext(ctx, `SELECT `+repoCols+`
FROM qsl_templates WHERE profile_id = ? OR profile_id IS NULL
ORDER BY is_default DESC, id DESC`, profileID)
if err != nil {
return nil, err
}
defer rows.Close()
var out []Record
for rows.Next() {
rec, err := scanRecord(rows)
if err != nil {
return nil, err
}
out = append(out, rec)
}
return out, rows.Err()
}
// Get returns one template by ID, or sql.ErrNoRows if missing.
func (r *Repo) Get(ctx context.Context, id int64) (Record, error) {
row := r.db.QueryRowContext(ctx, `SELECT `+repoCols+`
@@ -124,10 +146,15 @@ func (r *Repo) SetDefault(ctx context.Context, id int64) error {
// DefaultFor returns the best template for a profile: its own default, then
// any profile-less default, then the newest template. sql.ErrNoRows if none.
func (r *Repo) DefaultFor(ctx context.Context, profileID int64) (Record, error) {
// Only the profile's OWN templates or shared (NULL) ones — never another
// profile's, so a profile with no default doesn't inherit some other
// profile's newest template (the "default looked global" bug).
row := r.db.QueryRowContext(ctx, `SELECT `+repoCols+` FROM qsl_templates
WHERE profile_id = ? OR profile_id IS NULL
ORDER BY (is_default = 1 AND profile_id = ?) DESC,
(is_default = 1 AND profile_id IS NULL) DESC,
id DESC LIMIT 1`, profileID)
(profile_id = ?) DESC,
id DESC LIMIT 1`, profileID, profileID, profileID)
return scanRecord(row)
}