validate auth from old app and fill auth info
This commit is contained in:
No files matched your search
@@ -72,7 +72,8 @@ syncUrlCfg:
|
|||||||
enable: false
|
enable: false
|
||||||
targetHost:
|
targetHost:
|
||||||
prefix: new-to-old
|
prefix: new-to-old
|
||||||
source: new-app
|
oldSource: new-app
|
||||||
|
newSource: new-app
|
||||||
secretKey: new-world-order!!
|
secretKey: new-world-order!!
|
||||||
|
|
||||||
docsCfg:
|
docsCfg:
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package synccfg
|
package synccfg
|
||||||
|
|
||||||
var O PartnerCfg = PartnerCfg{} // old
|
var O SyncPartnerCfg = SyncPartnerCfg{} // old
|
||||||
|
|
||||||
// Used by sync itself, so any partner should be stated here
|
// Used by sync itself, so any partner should be stated here
|
||||||
type PartnerCfg struct {
|
type SyncPartnerCfg struct {
|
||||||
OldSource string `yaml:"oldSource"`
|
OldSource string `yaml:"oldSource"`
|
||||||
OldSecretKey string `yaml:"oldSecretKey"`
|
OldSecretKey string `yaml:"oldSecretKey"`
|
||||||
OldHost string `yaml:"oldHost"`
|
OldHost string `yaml:"oldHost"`
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package synccfg
|
package synccfg
|
||||||
|
|
||||||
var O SyncUrlCfg = SyncUrlCfg{} // old
|
var O SyncUrlCfg = SyncUrlCfg{} // new
|
||||||
|
|
||||||
type SyncUrlCfg struct {
|
type SyncUrlCfg struct {
|
||||||
Prefix string `yaml:"prefix"`
|
Prefix string `yaml:"prefix"`
|
||||||
TargetHost string `yaml:"targetHost"`
|
TargetHost string `yaml:"targetHost"`
|
||||||
Enable bool `yaml:"enable"`
|
Enable bool `yaml:"enable"`
|
||||||
Source string `yaml:"source"`
|
OldSource string `yaml:"oldSource"`
|
||||||
|
NewSource string `yaml:"newSource"`
|
||||||
SecretKey string `yaml:"secretKey"`
|
SecretKey string `yaml:"secretKey"`
|
||||||
}
|
}
|
||||||
@@ -9,12 +9,13 @@ import (
|
|||||||
sp "github.com/karincake/semprit"
|
sp "github.com/karincake/semprit"
|
||||||
sr "github.com/karincake/serabi"
|
sr "github.com/karincake/serabi"
|
||||||
|
|
||||||
|
is "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||||
|
pa "simrs-vx/internal/lib/auth"
|
||||||
|
|
||||||
m "simrs-vx/internal/domain/main-entities/user"
|
m "simrs-vx/internal/domain/main-entities/user"
|
||||||
mf "simrs-vx/internal/domain/main-entities/user-fes"
|
mf "simrs-vx/internal/domain/main-entities/user-fes"
|
||||||
pa "simrs-vx/internal/lib/auth"
|
|
||||||
s "simrs-vx/internal/use-case/main-use-case/authentication"
|
|
||||||
|
|
||||||
esga "simrs-vx/internal/domain/sync-entities/authentication"
|
esga "simrs-vx/internal/domain/sync-entities/authentication"
|
||||||
|
s "simrs-vx/internal/use-case/main-use-case/authentication"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Login(w http.ResponseWriter, r *http.Request) {
|
func Login(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -68,6 +69,10 @@ func Logout(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GuardMW(next http.Handler) http.Handler {
|
func GuardMW(next http.Handler) http.Handler {
|
||||||
|
var (
|
||||||
|
accessDetail *pa.AuthInfo
|
||||||
|
err error
|
||||||
|
)
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Check if it's from sync
|
// Check if it's from sync
|
||||||
credential := esga.CredentialDto{}
|
credential := esga.CredentialDto{}
|
||||||
@@ -75,23 +80,26 @@ func GuardMW(next http.Handler) http.Handler {
|
|||||||
credential.SecretKey = r.Header.Get("X-Sync-SecretKey")
|
credential.SecretKey = r.Header.Get("X-Sync-SecretKey")
|
||||||
credential.UserName = r.Header.Get("X-Sync-UserName")
|
credential.UserName = r.Header.Get("X-Sync-UserName")
|
||||||
if credential.Source != "" || credential.SecretKey != "" || credential.UserName != "" {
|
if credential.Source != "" || credential.SecretKey != "" || credential.UserName != "" {
|
||||||
// TODO: ngecall fungsi untuk dapat dari DB menlengkapi authinfo
|
// validate secretKey and source
|
||||||
accessDetail, err := s.GetAuthInfoByUserName(credential.UserName)
|
if credential.SecretKey != is.O.SecretKey || credential.Source != is.O.OldSource {
|
||||||
|
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
accessDetail, err = s.GetAuthInfoByUserName(credential.UserName)
|
||||||
|
if err != nil {
|
||||||
|
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Normal flow goes here
|
||||||
|
accessDetail, err = s.ExtractToken(r, s.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
|
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail)
|
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal flow goes here
|
|
||||||
accessDetail, err := s.ExtractToken(r, s.AccessToken)
|
|
||||||
if err != nil {
|
|
||||||
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail)
|
ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail)
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
next.ServeHTTP(w, r.WithContext(ctx))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
/******************** infra ********************/
|
/******************** infra ********************/
|
||||||
gs "simrs-vx/internal/infra/gorm-setting"
|
gs "simrs-vx/internal/infra/gorm-setting"
|
||||||
simgosdb "simrs-vx/internal/infra/simgos-db"
|
simgosdb "simrs-vx/internal/infra/simgos-db"
|
||||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
sync "simrs-vx/internal/infra/sync-cfg"
|
||||||
|
|
||||||
/******************** pkg ********************/
|
/******************** pkg ********************/
|
||||||
cmw "simrs-vx/pkg/cors-manager-mw"
|
cmw "simrs-vx/pkg/cors-manager-mw"
|
||||||
|
|||||||
@@ -180,9 +180,7 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetAuthInfoByUserName(userName string) (data *pa.AuthInfo, err error) {
|
func GetAuthInfoByUserName(userName string) (data *pa.AuthInfo, err error) {
|
||||||
// disini isi var `data`
|
return getAuthByUserName(userName)
|
||||||
// return error jika terjadi apa2
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) {
|
func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package authentication
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
pa "simrs-vx/internal/lib/auth"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -10,10 +11,13 @@ import (
|
|||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
ms "github.com/karincake/apem/ms-redis"
|
ms "github.com/karincake/apem/ms-redis"
|
||||||
d "github.com/karincake/dodol"
|
d "github.com/karincake/dodol"
|
||||||
|
gh "github.com/karincake/getuk"
|
||||||
l "github.com/karincake/lepet"
|
l "github.com/karincake/lepet"
|
||||||
|
|
||||||
pl "simrs-vx/pkg/logger"
|
pl "simrs-vx/pkg/logger"
|
||||||
|
|
||||||
|
erg "simrs-vx/internal/domain/references/organization"
|
||||||
|
|
||||||
edp "simrs-vx/internal/domain/main-entities/division-position"
|
edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||||
@@ -26,7 +30,6 @@ import (
|
|||||||
essp "simrs-vx/internal/domain/main-entities/subspecialist-position"
|
essp "simrs-vx/internal/domain/main-entities/subspecialist-position"
|
||||||
eup "simrs-vx/internal/domain/main-entities/unit-position"
|
eup "simrs-vx/internal/domain/main-entities/unit-position"
|
||||||
eu "simrs-vx/internal/domain/main-entities/user"
|
eu "simrs-vx/internal/domain/main-entities/user"
|
||||||
erg "simrs-vx/internal/domain/references/organization"
|
|
||||||
|
|
||||||
udp "simrs-vx/internal/use-case/main-use-case/division-position"
|
udp "simrs-vx/internal/use-case/main-use-case/division-position"
|
||||||
uip "simrs-vx/internal/use-case/main-use-case/installation-position"
|
uip "simrs-vx/internal/use-case/main-use-case/installation-position"
|
||||||
@@ -334,3 +337,71 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAuthByUserName(username string) (auth *pa.AuthInfo, err error) {
|
||||||
|
// get employee
|
||||||
|
emp := ee.Employee{}
|
||||||
|
if err = dg.I.
|
||||||
|
Joins(`JOIN "User" u ON u."Id" = "Employee"."User_Id"`).
|
||||||
|
Where(`u."Name" = ?`, username).
|
||||||
|
Scopes(gh.Preload("User")).
|
||||||
|
First(&emp).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
auth = &pa.AuthInfo{
|
||||||
|
User_Id: *emp.User_Id,
|
||||||
|
User_Name: emp.User.Name,
|
||||||
|
User_ContractPosition_Code: string(emp.User.ContractPosition_Code),
|
||||||
|
Employee_Position_Code: strPtr(string(*emp.Position_Code)),
|
||||||
|
Employee_Id: &emp.Id,
|
||||||
|
Sync: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// set map table
|
||||||
|
tableMap := map[erg.EmployeePositionCode]string{
|
||||||
|
erg.EPCDoc: "Doctor",
|
||||||
|
erg.EPCNur: "Nurse",
|
||||||
|
erg.EPCMwi: "Midwife",
|
||||||
|
erg.EPCNut: "Nutritionist",
|
||||||
|
erg.EPCLab: "Laborant",
|
||||||
|
erg.EPCPha: "Pharmachist",
|
||||||
|
}
|
||||||
|
|
||||||
|
table := tableMap[*emp.Position_Code]
|
||||||
|
if table == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type CodeResult struct {
|
||||||
|
Code string
|
||||||
|
}
|
||||||
|
var result CodeResult
|
||||||
|
|
||||||
|
err = dg.I.Table(table).
|
||||||
|
Select("Code").
|
||||||
|
Where("\"Employee_Id\" = ?", emp.Id).
|
||||||
|
First(&result).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// set map for code
|
||||||
|
setterMap := map[erg.EmployeePositionCode]func(string){
|
||||||
|
erg.EPCDoc: func(v string) { auth.Doctor_Code = &v },
|
||||||
|
erg.EPCNur: func(v string) { auth.Nurse_Code = &v },
|
||||||
|
erg.EPCMwi: func(v string) { auth.Midwife_Code = &v },
|
||||||
|
erg.EPCNut: func(v string) { auth.Nutritionist_Code = &v },
|
||||||
|
erg.EPCLab: func(v string) { auth.Laborant_Code = &v },
|
||||||
|
erg.EPCPha: func(v string) { auth.Pharmachist_Code = &v },
|
||||||
|
}
|
||||||
|
|
||||||
|
setter := setterMap[*emp.Position_Code]
|
||||||
|
setter(result.Code)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func strPtr(s string) *string {
|
||||||
|
return &s
|
||||||
|
}
|
||||||
@@ -1,165 +1,35 @@
|
|||||||
package division
|
package division
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||||
|
|
||||||
e "simrs-vx/internal/domain/main-entities/division"
|
e "simrs-vx/internal/domain/main-entities/division"
|
||||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||||
|
|
||||||
d "github.com/karincake/dodol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create(input *e.CreateDto) error {
|
func Create(input *e.CreateDto) error {
|
||||||
endpoint := getPrefixEndpoint()
|
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||||
|
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateLog(input *elog.SimxLogDto) error {
|
func CreateLog(input *elog.SimxLogDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := prefixEndpoint + "/log"
|
endpoint := prefixEndpoint + "/log"
|
||||||
|
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(input *e.UpdateDto) error {
|
func Update(input *e.UpdateDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(input *e.DeleteDto) error {
|
func Delete(input *e.DeleteDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPrefixEndpoint() string {
|
func getPrefixEndpoint() string {
|
||||||
|
|||||||
@@ -1,165 +1,35 @@
|
|||||||
package installation
|
package installation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||||
|
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||||
|
|
||||||
e "simrs-vx/internal/domain/main-entities/installation"
|
e "simrs-vx/internal/domain/main-entities/installation"
|
||||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||||
|
|
||||||
d "github.com/karincake/dodol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create(input *e.CreateDto) error {
|
func Create(input *e.CreateDto) error {
|
||||||
endpoint := getPrefixEndpoint()
|
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||||
|
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateLog(input *elog.SimxLogDto) error {
|
func CreateLog(input *elog.SimxLogDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := prefixEndpoint + "/log"
|
endpoint := prefixEndpoint + "/log"
|
||||||
|
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(input *e.UpdateDto) error {
|
func Update(input *e.UpdateDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(input *e.DeleteDto) error {
|
func Delete(input *e.DeleteDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPrefixEndpoint() string {
|
func getPrefixEndpoint() string {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package patient
|
package patient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||||
|
|
||||||
d "github.com/karincake/dodol"
|
d "github.com/karincake/dodol"
|
||||||
|
|
||||||
@@ -16,150 +16,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Create(input *e.Patient) error {
|
func Create(input *e.Patient) error {
|
||||||
endpoint := getPrefixEndpoint()
|
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||||
|
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateLog(input *elog.SimxLogDto) error {
|
func CreateLog(input *elog.SimxLogDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := prefixEndpoint + "/log"
|
endpoint := prefixEndpoint + "/log"
|
||||||
|
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(input *e.Patient) error {
|
func Update(input *e.Patient) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(input *e.DeleteDto) error {
|
func Delete(input *e.DeleteDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateNomrPatient() (*string, error) {
|
func GenerateNomrPatient() (*string, error) {
|
||||||
|
|||||||
@@ -1,165 +1,35 @@
|
|||||||
package specialist
|
package specialist
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||||
|
|
||||||
e "simrs-vx/internal/domain/main-entities/specialist"
|
e "simrs-vx/internal/domain/main-entities/specialist"
|
||||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||||
|
|
||||||
d "github.com/karincake/dodol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create(input *e.CreateDto) error {
|
func Create(input *e.CreateDto) error {
|
||||||
endpoint := getPrefixEndpoint()
|
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||||
|
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateLog(input *elog.SimxLogDto) error {
|
func CreateLog(input *elog.SimxLogDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := prefixEndpoint + "/log"
|
endpoint := prefixEndpoint + "/log"
|
||||||
|
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(input *e.UpdateDto) error {
|
func Update(input *e.UpdateDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(input *e.DeleteDto) error {
|
func Delete(input *e.DeleteDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPrefixEndpoint() string {
|
func getPrefixEndpoint() string {
|
||||||
|
|||||||
@@ -1,165 +1,35 @@
|
|||||||
package subspecialist
|
package subspecialist
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||||
|
|
||||||
e "simrs-vx/internal/domain/main-entities/subspecialist"
|
e "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||||
|
|
||||||
d "github.com/karincake/dodol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create(input *e.CreateDto) error {
|
func Create(input *e.CreateDto) error {
|
||||||
endpoint := getPrefixEndpoint()
|
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||||
|
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateLog(input *elog.SimxLogDto) error {
|
func CreateLog(input *elog.SimxLogDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := prefixEndpoint + "/log"
|
endpoint := prefixEndpoint + "/log"
|
||||||
|
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(input *e.UpdateDto) error {
|
func Update(input *e.UpdateDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(input *e.DeleteDto) error {
|
func Delete(input *e.DeleteDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPrefixEndpoint() string {
|
func getPrefixEndpoint() string {
|
||||||
|
|||||||
@@ -1,165 +1,35 @@
|
|||||||
package unit
|
package unit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||||
|
|
||||||
e "simrs-vx/internal/domain/main-entities/unit"
|
e "simrs-vx/internal/domain/main-entities/unit"
|
||||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||||
|
|
||||||
d "github.com/karincake/dodol"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Create(input *e.CreateDto) error {
|
func Create(input *e.CreateDto) error {
|
||||||
endpoint := getPrefixEndpoint()
|
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||||
|
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateLog(input *elog.SimxLogDto) error {
|
func CreateLog(input *elog.SimxLogDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := prefixEndpoint + "/log"
|
endpoint := prefixEndpoint + "/log"
|
||||||
|
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(input *e.UpdateDto) error {
|
func Update(input *e.UpdateDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(input *e.DeleteDto) error {
|
func Delete(input *e.DeleteDto) error {
|
||||||
prefixEndpoint := getPrefixEndpoint()
|
prefixEndpoint := getPrefixEndpoint()
|
||||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||||
|
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||||
jsonData, err := json.Marshal(input)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to encode JSON: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData))
|
|
||||||
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()
|
|
||||||
|
|
||||||
bodyBytes, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
errors := d.FieldError{}
|
|
||||||
_ = json.Unmarshal(bodyBytes, &errors)
|
|
||||||
|
|
||||||
return fmt.Errorf(errors.Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPrefixEndpoint() string {
|
func getPrefixEndpoint() string {
|
||||||
|
|||||||
@@ -381,9 +381,7 @@ func updatePatientCaraBayar(input etp.TPendaftaran, event *pl.Event, dbx ...*gor
|
|||||||
|
|
||||||
if err := tx.Model(&ep.MPasien{}).
|
if err := tx.Model(&ep.MPasien{}).
|
||||||
Where("\"nomr\" = ?", input.Nomr).
|
Where("\"nomr\" = ?", input.Nomr).
|
||||||
Updates(map[string]interface{}{
|
Update("kdcarabayar", input.Kdcarabayar).Error; err != nil {
|
||||||
"kdcarabayar": input.Kdcarabayar,
|
|
||||||
}).Error; err != nil {
|
|
||||||
event.Status = "failed"
|
event.Status = "failed"
|
||||||
event.ErrInfo = pl.ErrorInfo{
|
event.ErrInfo = pl.ErrorInfo{
|
||||||
Code: "update-fail",
|
Code: "update-fail",
|
||||||
|
|||||||
@@ -11,9 +11,12 @@ type Dualtx struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewDualtx() *Dualtx {
|
func NewDualtx() *Dualtx {
|
||||||
|
simgosTx := dg.IS["simrs"].Begin()
|
||||||
|
simgosTx.Exec(`SET LOCAL simx.sync_source = 'new'`)
|
||||||
|
|
||||||
return &Dualtx{
|
return &Dualtx{
|
||||||
Sync: dg.I.Begin(),
|
Sync: dg.I.Begin(),
|
||||||
Simgos: dg.IS["simrs"].Begin(),
|
Simgos: simgosTx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user