refactor bug report handlers to use centralized JSON response functions and add delete functionality

This commit is contained in:
Flavio Fois
2026-03-18 09:32:01 +01:00
parent 52947965db
commit 3f54e1cea4
3 changed files with 102 additions and 121 deletions

View File

@@ -0,0 +1,26 @@
package handlers
import (
"encoding/json"
"net/http"
)
// jsonError writes a JSON error response with the given status code and message.
func jsonError(w http.ResponseWriter, status int, msg string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(map[string]string{"error": msg})
}
// jsonOK writes a 200 JSON response with the given payload.
func jsonOK(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(v)
}
// jsonCreated writes a 201 JSON response with the given payload.
func jsonCreated(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
_ = json.NewEncoder(w).Encode(v)
}