fix code insert surkon
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PostData(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.ResponseInsertSuratKontrol, error) {
|
||||
func PostData(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.ResponseInsert, error) {
|
||||
log.Println("URL", url)
|
||||
|
||||
reqMarshall, err := json.Marshal(request)
|
||||
@@ -21,6 +21,8 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
log.Printf("Error json marshal: %v", err)
|
||||
}
|
||||
|
||||
responses := &suratkontrol.ResponseInsert{}
|
||||
|
||||
log.Println("REQUEST: ", string(reqMarshall))
|
||||
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(reqMarshall))
|
||||
@@ -58,10 +60,15 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Println("metadata : ", resSuratKontrolRaw.MetaData.Code)
|
||||
|
||||
if resSuratKontrolRaw.MetaData.Code == "201" {
|
||||
errMsg := errors.New(resSuratKontrolRaw.MetaData.Message)
|
||||
log.Printf("error : %v", errMsg)
|
||||
return nil, errMsg
|
||||
responses.MetaData.Code = resSuratKontrolRaw.MetaData.Code
|
||||
responses.MetaData.Message = resSuratKontrolRaw.MetaData.Message
|
||||
log.Println("responses: ", responses)
|
||||
return responses, errMsg
|
||||
}
|
||||
|
||||
dataResp, err := docs.StringDecrypt(key, resSuratKontrolRaw.Response)
|
||||
@@ -81,9 +88,12 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Println("res: ", resSuratKontrol)
|
||||
responses = &suratkontrol.ResponseInsert{
|
||||
MetaData: resSuratKontrolRaw.MetaData,
|
||||
Response: *resSuratKontrol,
|
||||
}
|
||||
|
||||
return resSuratKontrol, nil
|
||||
return responses, nil
|
||||
}
|
||||
|
||||
func ResponseUpdateSuratKontrol(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestRencanaKontrol) (interface{}, error) {
|
||||
|
||||
@@ -61,18 +61,16 @@ func InsertSuratKontrol(c *gin.Context) {
|
||||
}
|
||||
res, err := PostData(url, header, headers, reqSuratKontrol)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
c.JSON(http.StatusInternalServerError, res)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Masuk sini?")
|
||||
|
||||
reqInsert := &sk.InsertDataSuratKontrol{
|
||||
Status: "1", // First Insert status always set to 1
|
||||
UserCreated: req.User,
|
||||
TglCetakSurKon: dateNow,
|
||||
TglRencanaKontrol: res.TglRencanaKontrol,
|
||||
NomorSurKon: res.NoSuratKontrol,
|
||||
TglRencanaKontrol: res.Response.TglRencanaKontrol,
|
||||
NomorSurKon: res.Response.NoSuratKontrol,
|
||||
KunjunganPasien: kunjunganPasien.IDKlinikSimgos,
|
||||
RuanganSurKon: kunjunganPasien.Ruangan,
|
||||
DPJPSurKon: kunjunganPasien.DPJP,
|
||||
|
||||
@@ -34,8 +34,13 @@ type ResponseInsertRaw struct {
|
||||
}
|
||||
|
||||
type MetadataString struct {
|
||||
Code interface{} `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type ResponseInsert struct {
|
||||
MetaData MetadataString `json:"metadata"`
|
||||
Response ResponseInsertSuratKontrol `json:"response"`
|
||||
}
|
||||
|
||||
type ResponseInsertSuratKontrol struct {
|
||||
|
||||
Reference in New Issue
Block a user