Skip to content

Commit

Permalink
chore: pass radius distance as a query param
Browse files Browse the repository at this point in the history
  • Loading branch information
Salaton committed Oct 31, 2023
1 parent 887c853 commit d366101
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion healthcrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,16 @@ func (h *HealthCRMLib) GetFacilities(ctx context.Context, location *Coordinates,
}

if location != nil {
queryParams["ref_location"] = location.ToString()
coordinateString, err := location.ToString()
if err != nil {
return nil, err
}

queryParams["ref_location"] = coordinateString

if location.Radius != "" {
queryParams["distance"] = location.Radius
}
}

if len(serviceIDs) > 0 && searchParameter != "" {
Expand Down
8 changes: 6 additions & 2 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ type Facility struct {
type Coordinates struct {
Latitude string `json:"latitude,omitempty"`
Longitude string `json:"longitude,omitempty"`
Radius string `json:"radius,omitempty"`
}

// ToString returns the location in comma-separated values format.
// The order of values in the string is longitude,latitude.
// The latitude and longitude are formatted up to 5 decimal places.
// For example, if the Location has Latitude 36.79 and Longitude -1.29,
// the returned string will be "-1.29, 36.79".
func (c Coordinates) ToString() string {
return fmt.Sprintf("%v, %v", c.Longitude, c.Latitude)
func (c Coordinates) ToString() (string, error) {
if c.Latitude == "" || c.Longitude == "" {
return "", fmt.Errorf("both Latitude and Longitude must be provided to generate the coordinates string")
}
return fmt.Sprintf("%v, %v", c.Longitude, c.Latitude), nil
}

// Contacts models facility's model data class
Expand Down

0 comments on commit d366101

Please sign in to comment.