add create installation

This commit is contained in:
vanilia
2025-11-13 17:28:20 +07:00
parent 3ebd3a38d0
commit e75025f87d
9 changed files with 254 additions and 110 deletions
@@ -0,0 +1,46 @@
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
}