feat: Added worked before in Net Control
This commit is contained in:
+20
-10
@@ -22,16 +22,26 @@ import (
|
||||
|
||||
// Station is one roster entry: a station registered in a net.
|
||||
type Station struct {
|
||||
Callsign string `json:"callsign"`
|
||||
Name string `json:"name,omitempty"`
|
||||
QTH string `json:"qth,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
DXCC int `json:"dxcc,omitempty"`
|
||||
ITU int `json:"itu,omitempty"`
|
||||
CQ int `json:"cq,omitempty"`
|
||||
Groups string `json:"groups,omitempty"`
|
||||
SIG string `json:"sig,omitempty"`
|
||||
SIGInfo string `json:"sig_info,omitempty"`
|
||||
Callsign string `json:"callsign"`
|
||||
Name string `json:"name,omitempty"`
|
||||
QTH string `json:"qth,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
DXCC int `json:"dxcc,omitempty"`
|
||||
ITU int `json:"itu,omitempty"`
|
||||
CQ int `json:"cq,omitempty"`
|
||||
// Full lookup detail so a roster contact carries EVERYTHING into the QSO when
|
||||
// put on air (was previously only name/qth — grid/address/etc. were lost).
|
||||
Grid string `json:"grid,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Cnty string `json:"cnty,omitempty"`
|
||||
Cont string `json:"cont,omitempty"`
|
||||
Lat float64 `json:"lat,omitempty"`
|
||||
Lon float64 `json:"lon,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Groups string `json:"groups,omitempty"`
|
||||
SIG string `json:"sig,omitempty"`
|
||||
SIGInfo string `json:"sig_info,omitempty"`
|
||||
}
|
||||
|
||||
// Net is a named net with default report values and a station roster.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user