@@ -4,83 +4,87 @@ import (
44 "github.com/oapi-codegen/nullable"
55 "github.com/samber/lo"
66
7- api "github.com/openmeterio/openmeter/api/v3"
7+ apiv3 "github.com/openmeterio/openmeter/api/v3"
88 customershandler "github.com/openmeterio/openmeter/api/v3/handlers/customers"
99 "github.com/openmeterio/openmeter/openmeter/governance"
1010)
1111
1212// ToAPIGovernanceQueryResponse maps a domain QueryResult to the API response.
13- func ToAPIGovernanceQueryResponse (res governance.QueryResult , pageSize int ) api.GovernanceQueryResponse {
14- data := make ([]api.GovernanceQueryResult , 0 , len (res .Customers ))
13+ func ToAPIGovernanceQueryResponse (res governance.QueryResult , pageSize int ) apiv3.GovernanceQueryResponse {
14+ data := make ([]apiv3.GovernanceQueryResult , 0 , len (res .Customers ))
15+
1516 for _ , c := range res .Customers {
16- features := make (map [string ]api .GovernanceFeatureAccess , len (c .Features ))
17+ features := make (map [string ]apiv3 .GovernanceFeatureAccess , len (c .Features ))
1718 for key , fa := range c .Features {
1819 features [key ] = toAPIFeatureAccess (fa )
1920 }
2021
21- data = append (data , api .GovernanceQueryResult {
22+ data = append (data , apiv3 .GovernanceQueryResult {
2223 Matched : c .Matched ,
2324 Customer : customershandler .ToAPIBillingCustomer (c .Customer ),
2425 Features : features ,
2526 UpdatedAt : c .UpdatedAt ,
2627 })
2728 }
2829
29- errs := make ([]api.GovernanceQueryError , 0 , len (res .Errors ))
30+ errs := make ([]apiv3.GovernanceQueryError , 0 , len (res .Errors ))
31+
3032 for _ , e := range res .Errors {
31- errs = append (errs , api .GovernanceQueryError {
33+ errs = append (errs , apiv3 .GovernanceQueryError {
3234 Customer : lo .ToPtr (e .CustomerKey ),
3335 Code : toAPIQueryErrorCode (e .Code ),
3436 Message : e .Message ,
3537 })
3638 }
3739
38- return api .GovernanceQueryResponse {
40+ return apiv3 .GovernanceQueryResponse {
3941 Data : data ,
4042 Errors : errs ,
4143 Meta : toAPICursorMeta (res , pageSize ),
4244 }
4345}
4446
45- func toAPIFeatureAccess (fa governance.FeatureAccess ) api.GovernanceFeatureAccess {
46- out := api.GovernanceFeatureAccess {HasAccess : fa .HasAccess }
47+ func toAPIFeatureAccess (fa governance.FeatureAccess ) apiv3.GovernanceFeatureAccess {
48+ out := apiv3.GovernanceFeatureAccess {HasAccess : fa .HasAccess }
49+
4750 if fa .Reason != nil {
48- out .Reason = & api .GovernanceFeatureAccessReason {
51+ out .Reason = & apiv3 .GovernanceFeatureAccessReason {
4952 Code : toAPIReasonCode (fa .Reason .Code ),
5053 Message : fa .Reason .Message ,
5154 }
5255 }
56+
5357 return out
5458}
5559
56- func toAPIReasonCode (code governance.ReasonCode ) api .GovernanceFeatureAccessReasonCode {
60+ func toAPIReasonCode (code governance.ReasonCode ) apiv3 .GovernanceFeatureAccessReasonCode {
5761 switch code {
5862 case governance .ReasonUsageLimitReached :
59- return api .GovernanceFeatureAccessReasonCodeUsageLimitReached
63+ return apiv3 .GovernanceFeatureAccessReasonCodeUsageLimitReached
6064 case governance .ReasonFeatureUnavailable :
61- return api .GovernanceFeatureAccessReasonCodeFeatureUnavailable
65+ return apiv3 .GovernanceFeatureAccessReasonCodeFeatureUnavailable
6266 case governance .ReasonFeatureNotFound :
63- return api .GovernanceFeatureAccessReasonCodeFeatureNotFound
67+ return apiv3 .GovernanceFeatureAccessReasonCodeFeatureNotFound
6468 case governance .ReasonNoCreditAvailable :
65- return api .GovernanceFeatureAccessReasonCodeNoCreditAvailable
69+ return apiv3 .GovernanceFeatureAccessReasonCodeNoCreditAvailable
6670 default :
67- return api .GovernanceFeatureAccessReasonCodeUnknown
71+ return apiv3 .GovernanceFeatureAccessReasonCodeUnknown
6872 }
6973}
7074
71- func toAPIQueryErrorCode (code governance.QueryErrorCode ) api .GovernanceQueryErrorCode {
75+ func toAPIQueryErrorCode (code governance.QueryErrorCode ) apiv3 .GovernanceQueryErrorCode {
7276 switch code {
7377 case governance .QueryErrorCustomerNotFound :
74- return api .GovernanceQueryErrorCodeCustomerNotFound
78+ return apiv3 .GovernanceQueryErrorCodeCustomerNotFound
7579 default :
76- return api .GovernanceQueryErrorCodeUnknown
80+ return apiv3 .GovernanceQueryErrorCodeUnknown
7781 }
7882}
7983
8084// toAPICursorMeta builds cursor pagination metadata from the domain result.
81- func toAPICursorMeta (res governance.QueryResult , pageSize int ) api .CursorMeta {
82- meta := api .CursorMeta {
83- Page : api .CursorMetaPage {
85+ func toAPICursorMeta (res governance.QueryResult , pageSize int ) apiv3 .CursorMeta {
86+ meta := apiv3 .CursorMeta {
87+ Page : apiv3 .CursorMetaPage {
8488 Next : nullable .NewNullNullable [string ](),
8589 Previous : nullable .NewNullNullable [string ](),
8690 Size : float32 (pageSize ),
@@ -93,6 +97,7 @@ func toAPICursorMeta(res governance.QueryResult, pageSize int) api.CursorMeta {
9397 meta .Page .Previous = nullable .NewNullableWithValue (res .First .Encode ())
9498 }
9599 }
100+
96101 if res .Last != nil {
97102 meta .Page .Last = lo .ToPtr (res .Last .Encode ())
98103 if res .HasNext {
0 commit comments