|
| 1 | +package subscriptionaddons |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http" |
| 6 | + |
| 7 | + apiv3 "github.com/openmeterio/openmeter/api/v3" |
| 8 | + subscriptionaddon "github.com/openmeterio/openmeter/openmeter/subscription/addon" |
| 9 | + "github.com/openmeterio/openmeter/pkg/framework/commonhttp" |
| 10 | + "github.com/openmeterio/openmeter/pkg/framework/transport/httptransport" |
| 11 | + "github.com/openmeterio/openmeter/pkg/models" |
| 12 | +) |
| 13 | + |
| 14 | +type ( |
| 15 | + GetSubscriptionAddonRequest = subscriptionaddon.GetSubscriptionAddonInput |
| 16 | + GetSubscriptionAddonParams struct { |
| 17 | + SubscriptionID string |
| 18 | + SubscriptionAddonID string |
| 19 | + } |
| 20 | + GetSubscriptionAddonResponse = apiv3.SubscriptionAddon |
| 21 | + GetSubscriptionAddonHandler httptransport.HandlerWithArgs[GetSubscriptionAddonRequest, GetSubscriptionAddonResponse, GetSubscriptionAddonParams] |
| 22 | +) |
| 23 | + |
| 24 | +func (h *handler) GetSubscriptionAddons() GetSubscriptionAddonHandler { |
| 25 | + return httptransport.NewHandlerWithArgs( |
| 26 | + func(ctx context.Context, r *http.Request, params GetSubscriptionAddonParams) (GetSubscriptionAddonRequest, error) { |
| 27 | + ns, err := h.resolveNamespace(ctx) |
| 28 | + if err != nil { |
| 29 | + return GetSubscriptionAddonRequest{}, err |
| 30 | + } |
| 31 | + |
| 32 | + return GetSubscriptionAddonRequest{ |
| 33 | + NamespacedID: models.NamespacedID{ |
| 34 | + Namespace: ns, |
| 35 | + ID: params.SubscriptionAddonID, |
| 36 | + }, |
| 37 | + SubscriptionID: params.SubscriptionID, |
| 38 | + }, nil |
| 39 | + }, |
| 40 | + func(ctx context.Context, request GetSubscriptionAddonRequest) (GetSubscriptionAddonResponse, error) { |
| 41 | + a, err := h.addonService.Get(ctx, request) |
| 42 | + if err != nil { |
| 43 | + return GetSubscriptionAddonResponse{}, err |
| 44 | + } |
| 45 | + |
| 46 | + return toAPISubscriptionAddon(*a) |
| 47 | + }, |
| 48 | + commonhttp.JSONResponseEncoderWithStatus[GetSubscriptionAddonResponse](http.StatusOK), |
| 49 | + httptransport.AppendOptions( |
| 50 | + h.options, |
| 51 | + httptransport.WithOperationName("get-subscription-addon"), |
| 52 | + )..., |
| 53 | + ) |
| 54 | +} |
0 commit comments