add installation
This commit is contained in:
No files matched your search
@@ -6,25 +6,29 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/installation"
|
||||
egos "simrs-vx/internal/domain/simgos-entities/installation"
|
||||
|
||||
"gorm.io/gorm"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
)
|
||||
|
||||
var endpoint = fmt.Sprintf("%s/v1/installation", sync.O.BaseUrl)
|
||||
|
||||
func Create(input *e.CreateDto, data *egos.MInstalasi, tx *gorm.DB) error {
|
||||
var endpoint = fmt.Sprintf("%s%s/v1/installation", sync.O.Host, sync.O.Prefix)
|
||||
|
||||
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)
|
||||
@@ -33,6 +37,10 @@ func Create(input *e.CreateDto, data *egos.MInstalasi, tx *gorm.DB) error {
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf(resp.Status)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -44,3 +52,36 @@ func Create(input *e.CreateDto, data *egos.MInstalasi, tx *gorm.DB) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
var endpoint = fmt.Sprintf("%s%s/v1/installation/log", sync.O.Host, sync.O.Prefix)
|
||||
|
||||
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()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf(resp.Status)
|
||||
}
|
||||
|
||||
_, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user