35 lines
948 B
Go
35 lines
948 B
Go
package routes
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func (rt *Router) UpdateSimulationHardware(w http.ResponseWriter, r *http.Request, idStr string) {
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
|
|
var reqBody struct {
|
|
CPUInfo *string `json:"cpu_info"`
|
|
GPUInfo *string `json:"gpu_info"`
|
|
RAMInfo *string `json:"ram_info"`
|
|
}
|
|
|
|
err := json.NewDecoder(r.Body).Decode(&reqBody)
|
|
if err != nil {
|
|
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
|
return
|
|
}
|
|
defer r.Body.Close()
|
|
|
|
_, err = rt.DB.Exec("UPDATE simulations SET cpu_info = ?, gpu_info = ?, ram_info = ? WHERE id = ?", reqBody.CPUInfo, reqBody.GPUInfo, reqBody.RAMInfo, idStr)
|
|
if err != nil {
|
|
log.Println("Update simulation hardware error:", err)
|
|
http.Error(w, "Failed to update", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
|
|
}
|