47 lines
980 B
Go
47 lines
980 B
Go
package installation
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
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"
|
|
)
|
|
|
|
var endpoint = fmt.Sprintf("%s/v1/installation", sync.O.BaseUrl)
|
|
|
|
func Create(input *e.CreateDto, data *egos.MInstalasi, tx *gorm.DB) error {
|
|
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()
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := json.Unmarshal(body, &data); err != nil {
|
|
return fmt.Errorf("failed to parse response JSON: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|