WEB - ADD COMMENTS ON ISSUES
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user