Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: pass radius distance as a query param #28

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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