Add, toggle, and delete services

This commit is contained in:
2025-10-18 23:35:07 +01:00
parent 0a90126f93
commit 9630afe00d
2 changed files with 360 additions and 38 deletions
+2 -2
View File
@@ -56,7 +56,7 @@ func ToggleService(w http.ResponseWriter, r *http.Request) {
}
query := "UPDATE services SET is_active = NOT is_active, updated_at = NOW(), updated_by = $1 WHERE id = $2"
result, err := db.DB.Exec(r.Context(), query, serviceID, r.Context().Value(mw.UserIDKey))
result, err := db.DB.Exec(r.Context(), query, r.Context().Value(mw.UserIDKey), serviceID)
if err != nil {
http.Error(w, "Failed to toggle service: "+err.Error(), http.StatusInternalServerError)
return
@@ -184,7 +184,7 @@ func DeleteServiceHandler(w http.ResponseWriter, r *http.Request) {
return
}
query := "UPDATE services SET is_active = false, updated_at = NOW() WHERE id = $1"
query := "DELETE FROM services WHERE id = $1"
result, err := db.DB.Exec(r.Context(), query, serviceID)
if err != nil {
http.Error(w, "Failed to delete service: "+err.Error(), http.StatusInternalServerError)