mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-09 21:58:53 +00:00
fix(m2-pr-d): thread ctx through Job/Notification/Audit services
Collapse CancelJobWithContext into CancelJob; eliminate 10 context.Background()
hits across the Job+Notification+Audit service cluster by threading ctx
through their handler-facing service interfaces.
Services (ctx-first):
- service/job.go: ListJobs, GetJob, CancelJob, ApproveJob, RejectJob now
accept ctx; the CancelJobWithContext wrapper is removed (handler callers
continue to invoke CancelJob, now ctx-aware).
- service/notification.go: ListNotifications, GetNotification, MarkAsRead
accept ctx.
- service/audit.go: ListAuditEvents, GetAuditEvent accept ctx.
Handlers (interface + callsites):
- handler/jobs.go, handler/notifications.go, handler/audit.go: local
service interfaces updated, r.Context() threaded at every callsite.
Tests:
- Mock services updated to match the new interfaces (ctx accepted and
ignored via '_ context.Context' first parameter; Fn closure fields
unchanged).
- job_test.go / notification_test.go callsites thread context.Background()
to match production shape.
Verification:
go build ./... ok
go vet ./... ok
go test -short ./... ok
go test -race -short ./... ok
golangci-lint run ./... 0 issues
Locked decisions from the M-2 plan:
D-1 ctx-only signatures (no dual forms)
D-4 preserve handler method names facing the router
D-5 domain types stay ctx-free
Audit complete. Commit: 1f6cf0eafa. Sections: 12. Findings: 2/7/10/4/6.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -11,9 +12,9 @@ import (
|
||||
|
||||
// NotificationService defines the service interface for notification operations.
|
||||
type NotificationService interface {
|
||||
ListNotifications(page, perPage int) ([]domain.NotificationEvent, int64, error)
|
||||
GetNotification(id string) (*domain.NotificationEvent, error)
|
||||
MarkAsRead(id string) error
|
||||
ListNotifications(ctx context.Context, page, perPage int) ([]domain.NotificationEvent, int64, error)
|
||||
GetNotification(ctx context.Context, id string) (*domain.NotificationEvent, error)
|
||||
MarkAsRead(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
// NotificationHandler handles HTTP requests for notification operations.
|
||||
@@ -50,7 +51,7 @@ func (h NotificationHandler) ListNotifications(w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
}
|
||||
|
||||
notifications, total, err := h.svc.ListNotifications(page, perPage)
|
||||
notifications, total, err := h.svc.ListNotifications(r.Context(), page, perPage)
|
||||
if err != nil {
|
||||
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to list notifications", requestID)
|
||||
return
|
||||
@@ -84,7 +85,7 @@ func (h NotificationHandler) GetNotification(w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
id = parts[0]
|
||||
|
||||
notification, err := h.svc.GetNotification(id)
|
||||
notification, err := h.svc.GetNotification(r.Context(), id)
|
||||
if err != nil {
|
||||
ErrorWithRequestID(w, http.StatusNotFound, "Notification not found", requestID)
|
||||
return
|
||||
@@ -112,7 +113,7 @@ func (h NotificationHandler) MarkAsRead(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
notificationID := parts[0]
|
||||
|
||||
if err := h.svc.MarkAsRead(notificationID); err != nil {
|
||||
if err := h.svc.MarkAsRead(r.Context(), notificationID); err != nil {
|
||||
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to mark notification as read", requestID)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user