mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-12 10:28:52 +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:
@@ -319,7 +319,7 @@ func (s *NotificationService) GetNotificationHistory(ctx context.Context, certID
|
||||
}
|
||||
|
||||
// ListNotifications returns paginated notifications (handler interface method).
|
||||
func (s *NotificationService) ListNotifications(page, perPage int) ([]domain.NotificationEvent, int64, error) {
|
||||
func (s *NotificationService) ListNotifications(ctx context.Context, page, perPage int) ([]domain.NotificationEvent, int64, error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func (s *NotificationService) ListNotifications(page, perPage int) ([]domain.Not
|
||||
PerPage: perPage,
|
||||
}
|
||||
|
||||
notifications, err := s.notifRepo.List(context.Background(), filter)
|
||||
notifications, err := s.notifRepo.List(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("failed to list notifications: %w", err)
|
||||
}
|
||||
@@ -349,12 +349,12 @@ func (s *NotificationService) ListNotifications(page, perPage int) ([]domain.Not
|
||||
}
|
||||
|
||||
// GetNotification returns a single notification (handler interface method).
|
||||
func (s *NotificationService) GetNotification(id string) (*domain.NotificationEvent, error) {
|
||||
func (s *NotificationService) GetNotification(ctx context.Context, id string) (*domain.NotificationEvent, error) {
|
||||
filter := &repository.NotificationFilter{
|
||||
PerPage: 1,
|
||||
}
|
||||
|
||||
notifications, err := s.notifRepo.List(context.Background(), filter)
|
||||
notifications, err := s.notifRepo.List(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get notification: %w", err)
|
||||
}
|
||||
@@ -370,6 +370,6 @@ func (s *NotificationService) GetNotification(id string) (*domain.NotificationEv
|
||||
}
|
||||
|
||||
// MarkAsRead marks a notification as read (handler interface method).
|
||||
func (s *NotificationService) MarkAsRead(id string) error {
|
||||
return s.notifRepo.UpdateStatus(context.Background(), id, "read", time.Now())
|
||||
func (s *NotificationService) MarkAsRead(ctx context.Context, id string) error {
|
||||
return s.notifRepo.UpdateStatus(ctx, id, "read", time.Now())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user