fix: normalization of city name address

This commit is contained in:
2026-05-28 23:23:22 +02:00
parent 5c004f5e2f
commit edda183c16
8 changed files with 216 additions and 50 deletions
+48 -8
View File
@@ -33,6 +33,11 @@ type Profile struct {
MyPOTARef string `json:"my_pota_ref"`
MyRig string `json:"my_rig"`
MyAntenna string `json:"my_antenna"`
MyDXCC *int `json:"my_dxcc,omitempty"`
MyCQZone *int `json:"my_cqz,omitempty"`
MyITUZone *int `json:"my_ituz,omitempty"`
MyLat *float64 `json:"my_lat,omitempty"`
MyLon *float64 `json:"my_lon,omitempty"`
TxPower *float64 `json:"tx_pwr,omitempty"`
IsActive bool `json:"is_active"`
SortOrder int `json:"sort_order"`
@@ -48,7 +53,8 @@ func NewRepo(db *sql.DB) *Repo { return &Repo{db: db} }
const selectCols = `id, name, callsign, operator, owner_callsign, my_grid, my_country, my_state, my_cnty,
my_street, my_city, my_postal_code, my_sota_ref, my_pota_ref,
my_rig, my_antenna, tx_pwr, is_active, sort_order, created_at, updated_at`
my_rig, my_antenna, my_dxcc, my_cqz, my_ituz, my_lat, my_lon, tx_pwr,
is_active, sort_order, created_at, updated_at`
// List returns every profile, active first then by sort_order/id.
func (r *Repo) List(ctx context.Context) ([]Profile, error) {
@@ -96,11 +102,14 @@ func (r *Repo) Save(ctx context.Context, p *Profile) error {
INSERT INTO station_profiles
(name, callsign, operator, owner_callsign, my_grid, my_country, my_state, my_cnty,
my_street, my_city, my_postal_code, my_sota_ref, my_pota_ref,
my_rig, my_antenna, tx_pwr, is_active, sort_order, created_at, updated_at)
VALUES(?,?,?,?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?,?,?)`,
my_rig, my_antenna, my_dxcc, my_cqz, my_ituz, my_lat, my_lon, tx_pwr,
is_active, sort_order, created_at, updated_at)
VALUES(?,?,?,?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?,?,?,?, ?,?,?,?)`,
p.Name, p.Callsign, p.Operator, p.OwnerCallsign, p.MyGrid, p.MyCountry, p.MyState, p.MyCounty,
p.MyStreet, p.MyCity, p.MyPostalCode, p.MySOTARef, p.MyPOTARef,
p.MyRig, p.MyAntenna, nullableFloat(p.TxPower), boolInt(p.IsActive), p.SortOrder, now, now)
p.MyRig, p.MyAntenna, nullableInt(p.MyDXCC), nullableInt(p.MyCQZone), nullableInt(p.MyITUZone),
nullableFloat(p.MyLat), nullableFloat(p.MyLon), nullableFloat(p.TxPower),
boolInt(p.IsActive), p.SortOrder, now, now)
if err != nil {
return err
}
@@ -112,12 +121,15 @@ func (r *Repo) Save(ctx context.Context, p *Profile) error {
UPDATE station_profiles SET
name = ?, callsign = ?, operator = ?, owner_callsign = ?, my_grid = ?, my_country = ?,
my_state = ?, my_cnty = ?, my_street = ?, my_city = ?, my_postal_code = ?,
my_sota_ref = ?, my_pota_ref = ?, my_rig = ?, my_antenna = ?, tx_pwr = ?,
my_sota_ref = ?, my_pota_ref = ?, my_rig = ?, my_antenna = ?,
my_dxcc = ?, my_cqz = ?, my_ituz = ?, my_lat = ?, my_lon = ?, tx_pwr = ?,
sort_order = ?, updated_at = ?
WHERE id = ?`,
p.Name, p.Callsign, p.Operator, p.OwnerCallsign, p.MyGrid, p.MyCountry,
p.MyState, p.MyCounty, p.MyStreet, p.MyCity, p.MyPostalCode,
p.MySOTARef, p.MyPOTARef, p.MyRig, p.MyAntenna, nullableFloat(p.TxPower),
p.MySOTARef, p.MyPOTARef, p.MyRig, p.MyAntenna,
nullableInt(p.MyDXCC), nullableInt(p.MyCQZone), nullableInt(p.MyITUZone),
nullableFloat(p.MyLat), nullableFloat(p.MyLon), nullableFloat(p.TxPower),
p.SortOrder, now, p.ID)
return err
}
@@ -210,13 +222,15 @@ func scan(row scannable) (Profile, error) {
callsign, operator, ownerCall, myGrid, myCountry, myState, myCnty,
myStreet, myCity, myPostal, mySOTA, myPOTA,
myRig, myAntenna sql.NullString
txPwr sql.NullFloat64
myDXCC, myCQZ, myITUZ sql.NullInt64
myLat, myLon, txPwr sql.NullFloat64
isActive, sortOrder int
createdAt, updatedAt string
)
err := row.Scan(&p.ID, &p.Name, &callsign, &operator, &ownerCall, &myGrid, &myCountry, &myState, &myCnty,
&myStreet, &myCity, &myPostal, &mySOTA, &myPOTA,
&myRig, &myAntenna, &txPwr, &isActive, &sortOrder, &createdAt, &updatedAt)
&myRig, &myAntenna, &myDXCC, &myCQZ, &myITUZ, &myLat, &myLon, &txPwr,
&isActive, &sortOrder, &createdAt, &updatedAt)
if err != nil {
return p, err
}
@@ -234,6 +248,26 @@ func scan(row scannable) (Profile, error) {
p.MyPOTARef = myPOTA.String
p.MyRig = myRig.String
p.MyAntenna = myAntenna.String
if myDXCC.Valid {
v := int(myDXCC.Int64)
p.MyDXCC = &v
}
if myCQZ.Valid {
v := int(myCQZ.Int64)
p.MyCQZone = &v
}
if myITUZ.Valid {
v := int(myITUZ.Int64)
p.MyITUZone = &v
}
if myLat.Valid {
v := myLat.Float64
p.MyLat = &v
}
if myLon.Valid {
v := myLon.Float64
p.MyLon = &v
}
if txPwr.Valid {
v := txPwr.Float64
p.TxPower = &v
@@ -251,6 +285,12 @@ func nullableFloat(p *float64) any {
}
return *p
}
func nullableInt(p *int) any {
if p == nil {
return nil
}
return *p
}
func boolInt(b bool) int {
if b {
return 1