@@ -25,21 +25,15 @@ type EventHandler interface {
2525}
2626
2727type HandleResult struct {
28- EventID string `json:"id"`
29- MatchedCount int `json:"matched_count"`
30- QueuedCount int `json:"queued_count"`
31- Destinations []DestinationStatus `json:"destinations,omitempty"`
32- }
33-
34- type DestinationStatus struct {
35- ID string `json:"id"`
36- Status DestinationMatchStatus `json:"status"`
28+ EventID string `json:"id"`
29+ MatchedCount int `json:"matched_count"`
30+ QueuedCount int `json:"queued_count"`
31+ DestinationStatus * DestinationMatchStatus `json:"destination_status,omitempty"`
3732}
3833
3934type DestinationMatchStatus string
4035
4136const (
42- DestinationStatusQueued DestinationMatchStatus = "queued"
4337 DestinationStatusDisabled DestinationMatchStatus = "disabled"
4438 DestinationStatusNotFound DestinationMatchStatus = "not_found"
4539 DestinationStatusTopicMismatch DestinationMatchStatus = "topic_mismatch"
@@ -95,7 +89,7 @@ func (h *eventHandler) Handle(ctx context.Context, event *models.Event) (*Handle
9589 zap .String ("destination_id" , event .DestinationID ))
9690
9791 var matchedDestinations []models.DestinationSummary
98- var destStatus * DestinationStatus
92+ var destStatus * DestinationMatchStatus
9993 var err error
10094
10195 // Branch: specific destination vs topic-based matching
@@ -123,12 +117,12 @@ func (h *eventHandler) Handle(ctx context.Context, event *models.Event) (*Handle
123117 QueuedCount : 0 ,
124118 }
125119
126- if destStatus != nil {
127- result .Destinations = []DestinationStatus {* destStatus }
128- }
129-
130120 // Early return if no destinations matched
131121 if len (matchedDestinations ) == 0 {
122+ // Only set destination_status if destination_id was specified and nothing matched
123+ if event .DestinationID != "" && destStatus != nil {
124+ result .DestinationStatus = destStatus
125+ }
132126 logger .Info ("no matching destinations" ,
133127 zap .String ("event_id" , event .ID ),
134128 zap .String ("tenant_id" , event .TenantID ))
@@ -176,51 +170,35 @@ func (h *eventHandler) doPublish(ctx context.Context, event *models.Event, match
176170
177171// matchSpecificDestination handles the case where a specific destination_id is provided.
178172// It retrieves the destination and validates it, returning both the matched destinations
179- // and the status for the API response .
180- func (h * eventHandler ) matchSpecificDestination (ctx context.Context , event * models.Event ) ([]models.DestinationSummary , * DestinationStatus , error ) {
173+ // and the status (only set when nothing matched - disabled/not_found/topic_mismatch) .
174+ func (h * eventHandler ) matchSpecificDestination (ctx context.Context , event * models.Event ) ([]models.DestinationSummary , * DestinationMatchStatus , error ) {
181175 destination , err := h .entityStore .RetrieveDestination (ctx , event .TenantID , event .DestinationID )
182176 if err != nil {
183177 h .logger .Ctx (ctx ).Warn ("failed to retrieve destination" ,
184178 zap .Error (err ),
185179 zap .String ("destination_id" , event .DestinationID ))
186- status := DestinationStatus {
187- ID : event .DestinationID ,
188- Status : DestinationStatusNotFound ,
189- }
180+ status := DestinationStatusNotFound
190181 return []models.DestinationSummary {}, & status , nil
191182 }
192183
193184 if destination == nil {
194- status := DestinationStatus {
195- ID : event .DestinationID ,
196- Status : DestinationStatusNotFound ,
197- }
185+ status := DestinationStatusNotFound
198186 return []models.DestinationSummary {}, & status , nil
199187 }
200188
201189 if destination .DisabledAt != nil {
202- status := DestinationStatus {
203- ID : event .DestinationID ,
204- Status : DestinationStatusDisabled ,
205- }
190+ status := DestinationStatusDisabled
206191 return []models.DestinationSummary {}, & status , nil
207192 }
208193
209194 // Check topic match
210195 if event .Topic != "" && event .Topic != "*" && destination .Topics [0 ] != "*" && ! slices .Contains (destination .Topics , event .Topic ) {
211- status := DestinationStatus {
212- ID : event .DestinationID ,
213- Status : DestinationStatusTopicMismatch ,
214- }
196+ status := DestinationStatusTopicMismatch
215197 return []models.DestinationSummary {}, & status , nil
216198 }
217199
218- // Matched!
219- status := DestinationStatus {
220- ID : event .DestinationID ,
221- Status : DestinationStatusQueued ,
222- }
223- return []models.DestinationSummary {* destination .ToSummary ()}, & status , nil
200+ // Matched! Return nil status since it will be queued
201+ return []models.DestinationSummary {* destination .ToSummary ()}, nil , nil
224202}
225203
226204func (h * eventHandler ) enqueueDeliveryEvent (ctx context.Context , deliveryEvent models.DeliveryEvent ) error {
0 commit comments