@@ -144,7 +144,7 @@ func (s *WebSubAPIService) Create(orgUUID, createdBy string, req *api.WebSubAPI)
144144 Context : req .Context ,
145145 Channels : mapWebSubChannelsAPIToModel (req .Channels ),
146146 Upstream : * mapUpstreamAPIToModel (req .Upstream ),
147- AllChannels : mapWebSubPoliciesAPIToAllChannels (req .Policies ),
147+ AllChannels : mapWebSubAllChannelPoliciesAPIToModel (req .AllChannels ),
148148 SubscriptionPlans : subscriptionPlans ,
149149 },
150150 }
@@ -259,7 +259,7 @@ func (s *WebSubAPIService) Update(orgUUID, handle string, req *api.WebSubAPI) (*
259259 Context : req .Context ,
260260 Channels : mapWebSubChannelsAPIToModel (req .Channels ),
261261 Upstream : * mapUpstreamAPIToModel (req .Upstream ),
262- AllChannels : mapWebSubPoliciesAPIToAllChannels (req .Policies ),
262+ AllChannels : mapWebSubAllChannelPoliciesAPIToModel (req .AllChannels ),
263263 SubscriptionPlans : subscriptionPlans ,
264264 }
265265
@@ -415,7 +415,7 @@ func mapWebSubAPIModelToAPI(m *model.WebSubAPI, apiUtil *utils.APIUtil) *api.Web
415415 Context : m .Configuration .Context ,
416416 Upstream : mapUpstreamModelToAPI (& m .Configuration .Upstream ),
417417 Channels : mapWebSubChannelsModelToAPI (m .Configuration .Channels ),
418- Policies : mapAllChannelsModelToWebSubPolicies (m .Configuration .AllChannels ),
418+ AllChannels : mapWebSubAllChannelPoliciesModelToAPI (m .Configuration .AllChannels ),
419419 SubscriptionPlans : subscriptionPlans ,
420420 CreatedAt : utils .TimePtr (m .CreatedAt ),
421421 UpdatedAt : utils .TimePtr (m .UpdatedAt ),
@@ -431,15 +431,11 @@ func mapWebSubChannelsAPIToModel(in *map[string]api.WebSubChannel) map[string]mo
431431 }
432432 out := make (map [string ]model.WebSubChannel , len (* in ))
433433 for name , ch := range * in {
434- var p * api.WebSubChannelPolicies
435- if ch .Policies != nil {
436- p = ch .Policies
437- }
438434 out [name ] = model.WebSubChannel {
439- OnSubscription : policySlicePtrToEventPolicies ( policySlicePtrFromChannelPolicies ( p , "on_subscription" ) ),
440- OnUnsubscription : policySlicePtrToEventPolicies ( policySlicePtrFromChannelPolicies ( p , "on_unsubscription" ) ),
441- OnMessageReceived : policySlicePtrToEventPolicies ( policySlicePtrFromChannelPolicies ( p , "on_message_received" ) ),
442- OnMessageDelivery : policySlicePtrToEventPolicies ( policySlicePtrFromChannelPolicies ( p , "on_message_delivery" ) ),
435+ OnSubscription : mapEventPoliciesAPIToModel ( ch . OnSubscription ),
436+ OnUnsubscription : mapEventPoliciesAPIToModel ( ch . OnUnsubscription ),
437+ OnMessageReceived : mapEventPoliciesAPIToModel ( ch . OnMessageReceived ),
438+ OnMessageDelivery : mapEventPoliciesAPIToModel ( ch . OnMessageDelivery ),
443439 }
444440 }
445441 return out
@@ -455,19 +451,6 @@ func mapEventPoliciesAPIToModel(in *api.WebSubEventPolicies) *model.WebSubEventP
455451 }
456452}
457453
458- // mapWebSubChannelPoliciesAPIToModel is kept for compatibility.
459- func mapWebSubChannelPoliciesAPIToModel (in * api.WebSubChannelPolicies ) * model.WebSubChannelPolicies {
460- if in == nil {
461- return nil
462- }
463- return & model.WebSubChannelPolicies {
464- OnSubscription : policySlicePtrToEventPolicies (in .OnSubscription ),
465- OnUnsubscription : policySlicePtrToEventPolicies (in .OnUnsubscription ),
466- OnMessageReceived : policySlicePtrToEventPolicies (in .OnMessageReceived ),
467- OnMessageDelivery : policySlicePtrToEventPolicies (in .OnMessageDelivery ),
468- }
469- }
470-
471454// mapWebSubAllChannelPoliciesAPIToModel converts API all-channel policies to model.
472455func mapWebSubAllChannelPoliciesAPIToModel (in * api.WebSubAllChannelPolicies ) * model.WebSubAllChannelPolicies {
473456 if in == nil {
@@ -481,80 +464,6 @@ func mapWebSubAllChannelPoliciesAPIToModel(in *api.WebSubAllChannelPolicies) *mo
481464 }
482465}
483466
484- // mapWebSubPoliciesAPIToAllChannels converts flat WebSubChannelPolicies (from API) to model.WebSubAllChannelPolicies (for storage).
485- func mapWebSubPoliciesAPIToAllChannels (in * api.WebSubChannelPolicies ) * model.WebSubAllChannelPolicies {
486- if in == nil {
487- return nil
488- }
489- return & model.WebSubAllChannelPolicies {
490- OnSubscription : policySlicePtrToEventPolicies (in .OnSubscription ),
491- OnUnsubscription : policySlicePtrToEventPolicies (in .OnUnsubscription ),
492- OnMessageReceived : policySlicePtrToEventPolicies (in .OnMessageReceived ),
493- OnMessageDelivery : policySlicePtrToEventPolicies (in .OnMessageDelivery ),
494- }
495- }
496-
497- // mapAllChannelsModelToWebSubPolicies converts stored model.WebSubAllChannelPolicies to flat WebSubChannelPolicies (for API response).
498- func mapAllChannelsModelToWebSubPolicies (in * model.WebSubAllChannelPolicies ) * api.WebSubChannelPolicies {
499- if in == nil {
500- return nil
501- }
502- return & api.WebSubChannelPolicies {
503- OnSubscription : eventPoliciesToPolicySlicePtr (in .OnSubscription ),
504- OnUnsubscription : eventPoliciesToPolicySlicePtr (in .OnUnsubscription ),
505- OnMessageReceived : eventPoliciesToPolicySlicePtr (in .OnMessageReceived ),
506- OnMessageDelivery : eventPoliciesToPolicySlicePtr (in .OnMessageDelivery ),
507- }
508- }
509-
510- // policySlicePtrToEventPolicies wraps a flat policy slice pointer into a model.WebSubEventPolicies.
511- func policySlicePtrToEventPolicies (in * []api.Policy ) * model.WebSubEventPolicies {
512- if in == nil {
513- return nil
514- }
515- policies := make ([]model.Policy , 0 , len (* in ))
516- for _ , p := range * in {
517- policy := model.Policy {
518- Name : p .Name ,
519- Version : p .Version ,
520- }
521- if p .ExecutionCondition != nil {
522- policy .ExecutionCondition = p .ExecutionCondition
523- }
524- if p .Params != nil {
525- policy .Params = p .Params
526- }
527- policies = append (policies , policy )
528- }
529- return & model.WebSubEventPolicies {Policies : policies }
530- }
531-
532- // eventPoliciesToPolicySlicePtr converts a model.WebSubEventPolicies to a flat policy slice pointer.
533- func eventPoliciesToPolicySlicePtr (in * model.WebSubEventPolicies ) * []api.Policy {
534- if in == nil || len (in .Policies ) == 0 {
535- return nil
536- }
537- return mapModelPolicySliceToAPI (in .Policies )
538- }
539-
540- // policySlicePtrFromChannelPolicies extracts the policy slice for a given event type from WebSubChannelPolicies.
541- func policySlicePtrFromChannelPolicies (p * api.WebSubChannelPolicies , event string ) * []api.Policy {
542- if p == nil {
543- return nil
544- }
545- switch event {
546- case "on_subscription" :
547- return p .OnSubscription
548- case "on_unsubscription" :
549- return p .OnUnsubscription
550- case "on_message_received" :
551- return p .OnMessageReceived
552- case "on_message_delivery" :
553- return p .OnMessageDelivery
554- }
555- return nil
556- }
557-
558467// mapWebSubChannelsModelToAPI converts the model channel map to the API channel map.
559468func mapWebSubChannelsModelToAPI (in map [string ]model.WebSubChannel ) * map [string ]api.WebSubChannel {
560469 if len (in ) == 0 {
@@ -563,12 +472,10 @@ func mapWebSubChannelsModelToAPI(in map[string]model.WebSubChannel) *map[string]
563472 out := make (map [string ]api.WebSubChannel , len (in ))
564473 for name , ch := range in {
565474 out [name ] = api.WebSubChannel {
566- Policies : & api.WebSubChannelPolicies {
567- OnSubscription : eventPoliciesToPolicySlicePtr (ch .OnSubscription ),
568- OnUnsubscription : eventPoliciesToPolicySlicePtr (ch .OnUnsubscription ),
569- OnMessageReceived : eventPoliciesToPolicySlicePtr (ch .OnMessageReceived ),
570- OnMessageDelivery : eventPoliciesToPolicySlicePtr (ch .OnMessageDelivery ),
571- },
475+ OnSubscription : mapEventPoliciesModelToAPI (ch .OnSubscription ),
476+ OnUnsubscription : mapEventPoliciesModelToAPI (ch .OnUnsubscription ),
477+ OnMessageReceived : mapEventPoliciesModelToAPI (ch .OnMessageReceived ),
478+ OnMessageDelivery : mapEventPoliciesModelToAPI (ch .OnMessageDelivery ),
572479 }
573480 }
574481 return & out
@@ -584,19 +491,6 @@ func mapEventPoliciesModelToAPI(in *model.WebSubEventPolicies) *api.WebSubEventP
584491 }
585492}
586493
587- // mapWebSubChannelPoliciesModelToAPI is kept for compatibility.
588- func mapWebSubChannelPoliciesModelToAPI (in * model.WebSubChannelPolicies ) * api.WebSubChannelPolicies {
589- if in == nil {
590- return nil
591- }
592- return & api.WebSubChannelPolicies {
593- OnSubscription : eventPoliciesToPolicySlicePtr (in .OnSubscription ),
594- OnUnsubscription : eventPoliciesToPolicySlicePtr (in .OnUnsubscription ),
595- OnMessageReceived : eventPoliciesToPolicySlicePtr (in .OnMessageReceived ),
596- OnMessageDelivery : eventPoliciesToPolicySlicePtr (in .OnMessageDelivery ),
597- }
598- }
599-
600494// mapWebSubAllChannelPoliciesModelToAPI converts model all-channel policies to API.
601495func mapWebSubAllChannelPoliciesModelToAPI (in * model.WebSubAllChannelPolicies ) * api.WebSubAllChannelPolicies {
602496 if in == nil {
0 commit comments