2026-03-13 17:33:39 +00:00
|
|
|
package platform
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-22 21:22:33 +00:00
|
|
|
"context"
|
2026-05-07 16:38:42 +00:00
|
|
|
"errors"
|
2026-04-22 21:22:33 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
2026-05-07 16:38:42 +00:00
|
|
|
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
2026-03-13 17:33:39 +00:00
|
|
|
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Address = types.Address
|
2026-04-22 21:22:33 +00:00
|
|
|
|
|
|
|
|
func AddressFromComplianceReportRequestID(ctx context.Context, public_id string) (*types.Address, error) {
|
2026-05-07 16:38:42 +00:00
|
|
|
row, err := querypublic.AddressFromComplianceReportRequestID(ctx, db.PGInstance.PGXPool, public_id)
|
2026-04-22 21:22:33 +00:00
|
|
|
if err != nil {
|
2026-05-07 16:38:42 +00:00
|
|
|
if errors.Is(err, db.ErrNoRows) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
2026-04-22 21:22:33 +00:00
|
|
|
return nil, fmt.Errorf("query address from compliance report request: %w", err)
|
|
|
|
|
}
|
2026-05-07 16:38:42 +00:00
|
|
|
result := types.AddressFromModel(row)
|
|
|
|
|
return &result, nil
|
2026-04-22 21:22:33 +00:00
|
|
|
}
|
2026-04-29 15:01:35 +00:00
|
|
|
|
2026-05-07 10:39:17 +00:00
|
|
|
func AddressLocation(ctx context.Context, address types.Address) (*types.Location, error) {
|
2026-05-07 16:38:42 +00:00
|
|
|
address_id := int64(*address.ID)
|
|
|
|
|
addr, err := querypublic.AddressFromID(ctx, db.PGInstance.PGXPool, address_id)
|
2026-04-29 15:01:35 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("query address: %w", err)
|
|
|
|
|
}
|
2026-05-07 16:38:42 +00:00
|
|
|
l, err := types.LocationFromGeom(addr.Location)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("location from geom: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return &l, nil
|
2026-04-29 15:01:35 +00:00
|
|
|
}
|
2026-05-07 10:39:17 +00:00
|
|
|
|
|
|
|
|
func AddressInsert(ctx context.Context) (*types.Address, error) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|