Code reorganization Update
This commit is contained in:
34
server/routes/hardware.go
Normal file
34
server/routes/hardware.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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"})
|
||||
}
|
||||
Reference in New Issue
Block a user