github.com/sacloud/iaas-api-go@v1.12.0/internal/define/coupon.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package define 16 17 import ( 18 "fmt" 19 "net/http" 20 21 "github.com/sacloud/iaas-api-go/internal/define/names" 22 "github.com/sacloud/iaas-api-go/internal/dsl" 23 "github.com/sacloud/iaas-api-go/internal/dsl/meta" 24 "github.com/sacloud/iaas-api-go/naked" 25 ) 26 27 const ( 28 couponAPIName = "Coupon" 29 couponPathName = "coupon" 30 ) 31 32 var couponAPI = &dsl.Resource{ 33 Name: couponAPIName, 34 PathName: couponPathName, 35 PathSuffix: dsl.BillingAPISuffix, // 請求情報向けエンドポイント 36 IsGlobal: true, 37 Operations: dsl.Operations{ 38 { 39 ResourceName: couponAPIName, 40 Name: "Find", 41 PathFormat: couponPathFormat, 42 Method: http.MethodGet, 43 UseWrappedResult: true, 44 Arguments: dsl.Arguments{ 45 couponArgAccountID, 46 }, 47 ResponseEnvelope: dsl.ResponseEnvelopePlural(&dsl.EnvelopePayloadDesc{ 48 Type: couponNakedType, 49 Name: couponAPIName, 50 }), 51 Results: dsl.Results{ 52 { 53 SourceField: couponAPIName, 54 DestField: names.ResourceFieldName(couponAPIName, dsl.PayloadForms.Plural), 55 IsPlural: true, 56 Model: couponView, 57 }, 58 }, 59 }, 60 }, 61 } 62 63 var ( 64 couponArgAccountID = &dsl.Argument{ 65 Name: "accountID", 66 Type: meta.TypeID, 67 } 68 couponPathFormat = fmt.Sprintf("{{.rootURL}}/{{.zone}}/{{.pathSuffix}}/{{.pathName}}/{{.%s}}", couponArgAccountID.ArgName()) 69 ) 70 71 var ( 72 couponNakedType = meta.Static(naked.Coupon{}) 73 couponView = &dsl.Model{ 74 Name: "Coupon", 75 NakedType: couponNakedType, 76 Fields: []*dsl.FieldDesc{ 77 fields.ID(), 78 fields.Def("MemberID", meta.TypeString), 79 fields.Def("ContractID", meta.TypeID), 80 fields.Def("ServiceClassID", meta.TypeID), 81 fields.Def("Discount", meta.TypeInt64), 82 fields.Def("AppliedAt", meta.TypeTime), 83 fields.Def("UntilAt", meta.TypeTime), 84 }, 85 } 86 )