Merge remote-tracking branch 'origin/main' into WEB---READ-ISSUES
This commit is contained in:
@@ -29,7 +29,7 @@ func ListComments(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func CreateComment(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
svc := Services(r)
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
form, err := ParseForm[CommentForm](r)
|
||||
@@ -47,7 +47,7 @@ func CreateComment(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
comment, err := svc.Beads.AddIssueComment(r.Context(), issue.ID, form.Author, form.Text)
|
||||
comment, err := app.Issues.AddIssueComment(r.Context(), issue.ID, form.Author, form.Text)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to create comment: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -11,14 +11,14 @@ import (
|
||||
type contextKey string
|
||||
|
||||
const (
|
||||
servicesKey contextKey = "services"
|
||||
htmxKey contextKey = "htmx"
|
||||
appKey contextKey = "app"
|
||||
htmxKey contextKey = "htmx"
|
||||
)
|
||||
|
||||
func ServicesMiddleware(svc *service.Services) func(http.Handler) http.Handler {
|
||||
func AppMiddleware(app *service.App) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.WithValue(r.Context(), servicesKey, svc)
|
||||
ctx := context.WithValue(r.Context(), appKey, app)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
@@ -33,8 +33,8 @@ func HTMXMiddleware(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func Services(r *http.Request) *service.Services {
|
||||
return r.Context().Value(servicesKey).(*service.Services)
|
||||
func App(r *http.Request) *service.App {
|
||||
return r.Context().Value(appKey).(*service.App)
|
||||
}
|
||||
|
||||
func HTMX(r *http.Request) *htmx.Handler {
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
)
|
||||
|
||||
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
svc := Services(r)
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
query := strings.TrimSpace(r.URL.Query().Get("q"))
|
||||
filter := models.IssueFilter{Limit: 100}
|
||||
issuesPtr, err := svc.Beads.SearchIssues(r.Context(), query, filter)
|
||||
issuesPtr, err := app.Issues.SearchIssues(r.Context(), query, filter)
|
||||
if err != nil {
|
||||
http.Error(w, "failed to retrieve issues", http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -30,7 +30,7 @@ type UpdateIssueForm struct {
|
||||
}
|
||||
|
||||
func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
svc := Services(r)
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
form, err := ParseForm[IssueForm](r)
|
||||
@@ -49,7 +49,7 @@ func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
issue := form.toIssue()
|
||||
if err := svc.Beads.CreateIssue(r.Context(), &issue, ""); err != nil {
|
||||
if err := app.Issues.CreateIssue(r.Context(), &issue, ""); err != nil {
|
||||
http.Error(w, "Failed to create issue: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -64,10 +64,10 @@ func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
svc := Services(r)
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
issues, err := svc.Beads.AllIssues(r.Context())
|
||||
issues, err := app.Issues.AllIssues(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to retrieve issues", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -79,10 +79,10 @@ func ListIssues(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func IssueCtx(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
svc := Services(r)
|
||||
app := App(r)
|
||||
|
||||
id := chi.URLParam(r, "id")
|
||||
issue, err := svc.Beads.GetIssue(r.Context(), id)
|
||||
issue, err := app.Issues.GetIssue(r.Context(), id)
|
||||
if err != nil {
|
||||
http.Error(w, "Error getting issue: "+err.Error(), http.StatusNotFound)
|
||||
return
|
||||
@@ -92,7 +92,7 @@ func IssueCtx(next http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
comments, err := svc.Beads.GetIssueComments(r.Context(), issue.ID)
|
||||
comments, err := app.Issues.GetIssueComments(r.Context(), issue.ID)
|
||||
if err != nil {
|
||||
http.Error(w, "Error getting comments: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -132,7 +132,7 @@ func GetIssue(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func UpdateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
svc := Services(r)
|
||||
app := App(r)
|
||||
hx := HTMX(r)
|
||||
|
||||
form, err := ParseForm[UpdateIssueForm](r)
|
||||
@@ -152,12 +152,12 @@ func UpdateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
changes := form.toChanges()
|
||||
|
||||
if err := svc.Beads.UpdateIssue(r.Context(), issue.ID, changes, ""); err != nil {
|
||||
if err := app.Issues.UpdateIssue(r.Context(), issue.ID, changes, ""); err != nil {
|
||||
http.Error(w, "Failed to update issue", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
issue, err = svc.Beads.GetIssue(r.Context(), issue.ID)
|
||||
issue, err = app.Issues.GetIssue(r.Context(), issue.ID)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to retrieve updated issue", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -170,8 +170,8 @@ func UpdateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
func DeleteIssue(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
|
||||
svc := Services(r)
|
||||
if err := svc.Beads.DeleteIssue(r.Context(), issue.ID); err != nil {
|
||||
app := App(r)
|
||||
if err := app.Issues.DeleteIssue(r.Context(), issue.ID); err != nil {
|
||||
http.Error(w, "Failed to delete issue", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user