This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhouseholdsEligibilityEstimates.go
78 lines (69 loc) · 1.96 KB
/
householdsEligibilityEstimates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"github.com/gin-gonic/gin"
)
func GinHouseholdsEligibilityEstimates(c *gin.Context) {
body, err := io.ReadAll(c.Request.Body)
if err != nil {
c.String(http.StatusInternalServerError, "Error reading response")
return
}
var req CampaignRequest
if err := json.Unmarshal(body, &req); err != nil {
fmt.Println(string(body[:]))
fmt.Println(err)
fmt.Println("Error unmarshalling json to struct for GinHouseholdsEligibilityEstimates()")
return
}
// code for averaging and replacing age range
// if req.Household != nil {
// if req.Household.People != nil {
// for index, person := range *req.Household.People {
// if person.Age == 0 {
// ageRange := SearchByCampID(req.CampaignID).AgeRange
// fmt.Println(ageRange)
// result := (ageRange.Min + ageRange.Max) / 2
// (*req.Household.People)[index].Age = int32(result)
// }
// }
// }
// }
var url string = "https://marketplace.api.healthcare.gov/api/v1/households/eligibility/estimates?apikey=d687412e7b53146b2631dc01974ad0a4&year=2024"
reqByte, err := json.Marshal(req)
if err != nil {
panic(err)
}
//fmt.Println(string(reqByte))
estimateRes, err := http.Post(url, "application/json", bytes.NewBuffer(reqByte))
if err != nil {
panic(err)
}
defer estimateRes.Body.Close()
finalBody, err := ioutil.ReadAll(estimateRes.Body)
if err != nil {
panic(err)
}
//fmt.Println(string(finalBody))
var estimateResponse HouseholdsEligibilityEstimatesRespond
if err := json.Unmarshal(finalBody, &estimateResponse); err != nil {
fmt.Println(string(body[:]))
fmt.Println("Error unmarshalling json to struct for estimateResponse()")
panic(err)
}
c.IndentedJSON(http.StatusOK, estimateResponse)
}
func SearchByCampID(camp_id string) Campaign {
rtnCampaign := Campaign{}
for _, campaign := range Campaigns {
if campaign.CampaignID == camp_id {
rtnCampaign = campaign
}
}
return rtnCampaign
}