fix: bug sending LoTW on close
This commit is contained in:
@@ -519,6 +519,56 @@ func (r *Repo) ListForUpload(ctx context.Context, column, value string) ([]Uploa
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// UploadCandidate is a QSO eligible for an on-close upload: its id plus its
|
||||
// STATION_CALLSIGN, so the caller can keep only the rows that belong to the
|
||||
// active logbook's callsign (a mixed-call DB — F4BPO, F4BPO/P, TM2Q — must not
|
||||
// all be signed under one cert).
|
||||
type UploadCandidate struct {
|
||||
ID int64
|
||||
StationCallsign string
|
||||
}
|
||||
|
||||
// ListUploadCandidates returns QSOs eligible for an on-close upload to a
|
||||
// service, scanning the whole logbook. For LoTW (column "lotw_sent"), statuses
|
||||
// is the set of sent-status values to treat as "to send" (e.g. N, R); rows
|
||||
// already "Y" are excluded. For QRZ/Club Log, statuses is ignored and anything
|
||||
// whose upload status isn't yet "Y" qualifies.
|
||||
func (r *Repo) ListUploadCandidates(ctx context.Context, column string, statuses []string) ([]UploadCandidate, error) {
|
||||
if !uploadStatusCols[column] {
|
||||
return nil, fmt.Errorf("invalid upload column %q", column)
|
||||
}
|
||||
var where string
|
||||
var args []any
|
||||
if column == "lotw_sent" {
|
||||
if len(statuses) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
ph := make([]string, len(statuses))
|
||||
for i, s := range statuses {
|
||||
ph[i] = "?"
|
||||
args = append(args, strings.ToUpper(strings.TrimSpace(s)))
|
||||
}
|
||||
where = "UPPER(COALESCE(lotw_sent,'')) IN (" + strings.Join(ph, ",") + ")"
|
||||
} else {
|
||||
where = "UPPER(COALESCE(" + column + ",'')) <> 'Y'"
|
||||
}
|
||||
rows, err := r.db.QueryContext(ctx,
|
||||
`SELECT id, COALESCE(station_callsign,'') FROM qso WHERE `+where+` ORDER BY qso_date`, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list upload candidates: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []UploadCandidate
|
||||
for rows.Next() {
|
||||
var c UploadCandidate
|
||||
if err := rows.Scan(&c.ID, &c.StationCallsign); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, c)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// MarkQRZUploaded stamps QRZCOM_QSO_UPLOAD_STATUS=Y and the upload date on
|
||||
// a QSO after a successful push to the QRZ.com logbook. date is an ADIF
|
||||
// YYYYMMDD string. Only the two QRZ columns are touched — no full-row
|
||||
|
||||
Reference in New Issue
Block a user