member, nik ok, bpjs tested but failed from 3rd party
This commit is contained in:
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package member
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
e "simrs-vx/internal/domain/bpjs-entities/member"
|
||||
ibpjs "simrs-vx/internal/infra/bpjs"
|
||||
)
|
||||
|
||||
func endpointMapper(input *e.ReadListDto) string {
|
||||
switch input.ReferenceType {
|
||||
case e.RTBpjs:
|
||||
return fmt.Sprintf("%speserta/nokartu?noKartu=%s&tglpelayanan=%s", ibpjs.O.BaseUrl, input.PathValue1, input.PathValue2)
|
||||
case e.RTNik:
|
||||
return fmt.Sprintf("%speserta/nik?nik=%s&tglpelayanan=%s", ibpjs.O.BaseUrl, input.PathValue1, input.PathValue2)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package member
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
e "simrs-vx/internal/domain/bpjs-entities/member"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func ReadList(input *e.ReadListDto, data *e.Response, tx *gorm.DB) error {
|
||||
endpoint := endpointMapper(input)
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &data); err != nil {
|
||||
return fmt.Errorf("failed to parse response JSON: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user