summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/handlers.go')
-rw-r--r--internal/handlers/handlers.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index d52e786..8d809ae 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -829,3 +829,49 @@ func (h *Handler) HandleGetListsOptions(w http.ResponseWriter, r *http.Request)
fmt.Fprintf(w, `<option value="%s">%s</option>`, list.ID, list.Name)
}
}
+
+// HandleGetBugs returns the list of reported bugs
+func (h *Handler) HandleGetBugs(w http.ResponseWriter, r *http.Request) {
+ bugs, err := h.store.GetBugs()
+ if err != nil {
+ http.Error(w, "Failed to fetch bugs", http.StatusInternalServerError)
+ log.Printf("Error fetching bugs: %v", err)
+ return
+ }
+
+ w.Header().Set("Content-Type", "text/html")
+ if len(bugs) == 0 {
+ fmt.Fprint(w, `<p class="text-gray-500 text-sm">No bugs reported yet.</p>`)
+ return
+ }
+
+ for _, bug := range bugs {
+ fmt.Fprintf(w, `<div class="text-sm border-b border-gray-100 py-2">
+ <p class="text-gray-900">%s</p>
+ <p class="text-gray-400 text-xs">%s</p>
+ </div>`, template.HTMLEscapeString(bug.Description), bug.CreatedAt.Format("Jan 2, 3:04 PM"))
+ }
+}
+
+// HandleReportBug saves a new bug report
+func (h *Handler) HandleReportBug(w http.ResponseWriter, r *http.Request) {
+ if err := r.ParseForm(); err != nil {
+ http.Error(w, "Invalid form data", http.StatusBadRequest)
+ return
+ }
+
+ description := strings.TrimSpace(r.FormValue("description"))
+ if description == "" {
+ http.Error(w, "Description is required", http.StatusBadRequest)
+ return
+ }
+
+ if err := h.store.SaveBug(description); err != nil {
+ http.Error(w, "Failed to save bug", http.StatusInternalServerError)
+ log.Printf("Error saving bug: %v", err)
+ return
+ }
+
+ // Return updated bug list
+ h.HandleGetBugs(w, r)
+}