package routes import ( "encoding/json" "log" "net/http" ) func (rt *Router) UpdateSimulationTime(w http.ResponseWriter, r *http.Request, idStr string) { w.Header().Set("Access-Control-Allow-Origin", "*") var reqBody struct { SearchTime *float64 `json:"search_time"` TotalTime *float64 `json:"total_time"` } err := json.NewDecoder(r.Body).Decode(&reqBody) if err != nil { http.Error(w, "Invalid request body", http.StatusBadRequest) return } defer r.Body.Close() if reqBody.SearchTime == nil || reqBody.TotalTime == nil { http.Error(w, "Missing search_time or total_time", http.StatusBadRequest) return } _, err = rt.DB.Exec("UPDATE simulations SET search_time = ?, total_time = ? WHERE id = ?", *reqBody.SearchTime, *reqBody.TotalTime, idStr) if err != nil { log.Println("Update simulation 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"}) }