WEB - ADD COMMENTS ON ISSUES

This commit is contained in:
Ine Maria Nilssen Aanonsen
2026-02-20 11:25:08 +01:00
parent 890c57dd74
commit bb059ad8d8
10 changed files with 1145 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/pkg/web/routes"
"github.com/go-chi/chi/v5"
)
@@ -97,8 +98,27 @@ func IssueCtx(next http.Handler) http.Handler {
func GetIssue(w http.ResponseWriter, r *http.Request) {
issue := r.Context().Value(issueKey).(*models.Issue)
svc := Services(r)
hx := HTMX(r)
acceptHeader := r.Header.Get("Accept")
wantsHTML := acceptHeader == "" || (len(acceptHeader) >= 9 && acceptHeader[:9] == "text/html")
if wantsHTML && !hx.IsHxRequest() {
comments, err := svc.Beads.GetComments(r.Context(), issue.ID)
if err != nil {
http.Error(w, "Failed to retrieve comments: "+err.Error(), http.StatusInternalServerError)
return
}
routes.IssueDetail(routes.IssueDetailProps{
Issue: *issue,
Comments: comments,
}).Render(r.Context(), w)
return
}
w.Header().Set("Content-Type", "application/json")
hx.WriteJSON(issue)
}