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

fix: create facility #21

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
49 changes: 25 additions & 24 deletions healthcrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package healthcrm
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -40,15 +41,15 @@ func (h *HealthCRMLib) CreateFacility(ctx context.Context, facility *Facility) (
return nil, err
}

if response.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("unable to create facility in the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusCreated {
return nil, errors.New(string(respBytes))
}

var facilityResponse *FacilityOutput

err = json.Unmarshal(respBytes, &facilityResponse)
Expand All @@ -67,15 +68,15 @@ func (h *HealthCRMLib) GetFacilities(ctx context.Context) (*FacilityPage, error)
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch facility(ies) in the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, errors.New(string(respBytes))
}

var facilityPage *FacilityPage

err = json.Unmarshal(respBytes, &facilityPage)
Expand All @@ -94,15 +95,15 @@ func (h *HealthCRMLib) GetFacilityByID(ctx context.Context, id string) (*Facilit
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch facility from the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, errors.New(string(respBytes))
}

var facilityOutput *FacilityOutput

err = json.Unmarshal(respBytes, &facilityOutput)
Expand All @@ -121,15 +122,15 @@ func (h *HealthCRMLib) UpdateFacility(ctx context.Context, id string, updatePayl
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to update facility in the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, errors.New(string(respBytes))
}

var facilityOutput *FacilityOutput

err = json.Unmarshal(respBytes, &facilityOutput)
Expand Down Expand Up @@ -163,15 +164,15 @@ func (h *HealthCRMLib) GetFacilityServices(ctx context.Context, facilityID strin
resp = response
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to get facility services with status code: %v", resp.StatusCode)
}

respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if resp.StatusCode != http.StatusOK {
return nil, errors.New(string(respBytes))
}

var facilityServicePage *FacilityServicePage

err = json.Unmarshal(respBytes, &facilityServicePage)
Expand All @@ -193,15 +194,15 @@ func (h *HealthCRMLib) GetFacilitiesOfferingAService(ctx context.Context, servic
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to get facilities offering service with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, errors.New(string(respBytes))
}

var output *FacilityPage

err = json.Unmarshal(respBytes, &output)
Expand Down