Add header to handler

This commit is contained in:
poetrasapoetra
2025-11-28 17:29:12 +07:00
parent 0decd8330a
commit af6ff92948
2 changed files with 18 additions and 6 deletions
@@ -6,9 +6,10 @@ import (
"fmt"
"net/http"
rw "github.com/karincake/risoles"
p "simrs-vx/internal/domain/simgos-entities/m-pasien"
cfg "simrs-vx/internal/infra/sync-cfg"
p "simrs-vx/internal/domain/simgos-entities/patient"
rw "github.com/karincake/risoles"
)
type myBase struct{}
@@ -47,8 +48,11 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
}
// fmt.Println(string(jsonPatient))
url := fmt.Sprintf("%s%s%v", baseUrl, "patient/", *patient.Person_Id)
fmt.Println(url)
reqBody := bytes.NewBuffer(jsonPatient)
err = send(http.MethodPatch, fmt.Sprintf("%s%s%v", baseUrl, "patient/", patient.Id), reqBody)
err = send(http.MethodPatch, url, reqBody)
if err != nil {
fmt.Println("request error:", err)
}
@@ -64,7 +68,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
fmt.Println(err)
}
reqBody := bytes.NewBuffer(jsonPatient)
err = send(http.MethodDelete, fmt.Sprintf("%s%s%v", baseUrl, "patient/", patient.Id), reqBody)
err = send(http.MethodDelete, fmt.Sprintf("%s%s%v", baseUrl, "patient/", *patient.Person_Id), reqBody)
if err != nil {
fmt.Println("request error:", err)
}
@@ -79,6 +83,8 @@ func send(method string, url string, body *bytes.Buffer) error {
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Sync-Source", cfg.O.OldSource)
req.Header.Set("X-Sync-SecretKey", cfg.O.NewSecretKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
@@ -6,7 +6,7 @@ import (
/******************** infra ********************/
gs "simrs-vx/internal/infra/gorm-setting"
simgosdb "simrs-vx/internal/infra/simgos-db"
sync "simrs-vx/internal/infra/sync-consumer-cfg"
sync "simrs-vx/internal/infra/sync-cfg"
/******************** pkg ********************/
cmw "simrs-vx/pkg/cors-manager-mw"
@@ -29,6 +29,8 @@ import (
"simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist"
"simrs-vx/internal/interface/simgos-sync-handler/new/unit"
oldpatient "simrs-vx/internal/interface/simgos-sync-handler/old/patient"
oauth "simrs-vx/internal/interface/simgos-sync-handler/old/authentication" // just a reminder, an openauth
)
@@ -71,6 +73,10 @@ func SetRoutes() http.Handler {
/******************** SvcToNew ******************/
prefixold := "/old-to-new"
hk.GroupRoutes(prefixold+"/v1/patient", r, oauth.OldGuardMW, hk.MapHandlerFunc{}) // FINISH THIS
hk.GroupRoutes(prefixold+"/v1/patient", r, oauth.OldGuardMW, hk.MapHandlerFunc{
"POST /": oldpatient.O.Create,
"PATCH /{id}": oldpatient.O.Update,
"DELETE /{id}": oldpatient.O.Delete,
}) // FINISH THIS
return cmw.SetCors(handlerlogger.SetLog(r))
}