validate auth from old app and fill auth info
This commit is contained in:
@@ -180,9 +180,7 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode
|
||||
}
|
||||
|
||||
func GetAuthInfoByUserName(userName string) (data *pa.AuthInfo, err error) {
|
||||
// disini isi var `data`
|
||||
// return error jika terjadi apa2
|
||||
return
|
||||
return getAuthByUserName(userName)
|
||||
}
|
||||
|
||||
func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package authentication
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -10,10 +11,13 @@ import (
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
ms "github.com/karincake/apem/ms-redis"
|
||||
d "github.com/karincake/dodol"
|
||||
gh "github.com/karincake/getuk"
|
||||
l "github.com/karincake/lepet"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
|
||||
erg "simrs-vx/internal/domain/references/organization"
|
||||
|
||||
edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
@@ -26,7 +30,6 @@ import (
|
||||
essp "simrs-vx/internal/domain/main-entities/subspecialist-position"
|
||||
eup "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
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"
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/division"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
func Create(input *e.CreateDto) error {
|
||||
endpoint := 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
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.UpdateDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
|
||||
@@ -1,165 +1,35 @@
|
||||
package installation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
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"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
func Create(input *e.CreateDto) error {
|
||||
endpoint := 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
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.UpdateDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package patient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
@@ -16,150 +16,25 @@ import (
|
||||
)
|
||||
|
||||
func Create(input *e.Patient) error {
|
||||
endpoint := 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
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.Patient) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func GenerateNomrPatient() (*string, error) {
|
||||
|
||||
@@ -1,165 +1,35 @@
|
||||
package specialist
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/specialist"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
func Create(input *e.CreateDto) error {
|
||||
endpoint := 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
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.UpdateDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
|
||||
@@ -1,165 +1,35 @@
|
||||
package subspecialist
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
func Create(input *e.CreateDto) error {
|
||||
endpoint := 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
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.UpdateDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
|
||||
@@ -1,165 +1,35 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
helper "simrs-vx/internal/use-case/simgos-sync-plugin/new"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
func Create(input *e.CreateDto) error {
|
||||
endpoint := 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
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.UpdateDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
|
||||
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
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
|
||||
@@ -381,9 +381,7 @@ func updatePatientCaraBayar(input etp.TPendaftaran, event *pl.Event, dbx ...*gor
|
||||
|
||||
if err := tx.Model(&ep.MPasien{}).
|
||||
Where("\"nomr\" = ?", input.Nomr).
|
||||
Updates(map[string]interface{}{
|
||||
"kdcarabayar": input.Kdcarabayar,
|
||||
}).Error; err != nil {
|
||||
Update("kdcarabayar", input.Kdcarabayar).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "update-fail",
|
||||
|
||||
Reference in New Issue
Block a user