diff --git a/server/pkg/handlers.go b/server/pkg/handlers.go index 30a5247..b2f2dc4 100644 --- a/server/pkg/handlers.go +++ b/server/pkg/handlers.go @@ -221,3 +221,21 @@ func (h *Handler) RestartInstance() http.HandlerFunc { } } } + +func (h *Handler) DeleteInstance() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + id := chi.URLParam(r, "id") + uuid, err := uuid.Parse(id) + if err != nil { + http.Error(w, "Invalid UUID format", http.StatusBadRequest) + return + } + + if err := h.InstanceManager.DeleteInstance(uuid); err != nil { + http.Error(w, "Failed to delete instance: "+err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusNoContent) // No content for successful deletion + } +} diff --git a/server/pkg/routes.go b/server/pkg/routes.go index 77c3ff5..0a0a365 100644 --- a/server/pkg/routes.go +++ b/server/pkg/routes.go @@ -31,9 +31,9 @@ func SetupRouter(handler *Handler) *chi.Mux { r.Route("/{id}", func(r chi.Router) { // Instance management - r.Get("/", handler.GetInstance()) // Get instance details - r.Put("/", handler.UpdateInstance()) // Update instance configuration - // r.Delete("/", handler.DeleteInstance()) // Stop and remove instance + r.Get("/", handler.GetInstance()) // Get instance details + r.Put("/", handler.UpdateInstance()) // Update instance configuration + r.Delete("/", handler.DeleteInstance()) // Stop and remove instance r.Post("/start", handler.StartInstance()) // Start stopped instance r.Post("/stop", handler.StopInstance()) // Stop running instance r.Post("/restart", handler.RestartInstance()) // Restart instance