Skip to content

Commit

Permalink
fix: improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
JivusAyrus committed Dec 3, 2024
1 parent 8f21677 commit 8d96032
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
27 changes: 4 additions & 23 deletions internal/api/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@ import (
platformv1 "github.com/wundergraph/cosmo/connect-go/gen/proto/wg/cosmo/platform/v1"
)

func (p *PlatformClient) CreateContract(ctx context.Context, name, namespace, sourceGraphName, routingUrl, admissionWebhookUrl, admissionWebhookSecret string, excludeTags []string, includeTags []string, readme string) (*platformv1.CreateContractResponse, *ApiError) {
request := connect.NewRequest(&platformv1.CreateContractRequest{
Name: name,
Namespace: namespace,
SourceGraphName: sourceGraphName,
RoutingUrl: routingUrl,
AdmissionWebhookUrl: admissionWebhookUrl,
ExcludeTags: excludeTags,
Readme: &readme,
AdmissionWebhookSecret: &admissionWebhookSecret,
IncludeTags: includeTags,
})
func (p *PlatformClient) CreateContract(ctx context.Context, data *platformv1.CreateContractRequest) (*platformv1.CreateContractResponse, *ApiError) {
request := connect.NewRequest(data)

response, err := p.Client.CreateContract(ctx, request)
if err != nil {
Expand All @@ -38,17 +28,8 @@ func (p *PlatformClient) CreateContract(ctx context.Context, name, namespace, so
return response.Msg, nil
}

func (p *PlatformClient) UpdateContract(ctx context.Context, name, namespace string, excludeTags []string, includeTags []string, routingUrl, admissionWebhookUrl, admissionWebhookSecret, readme string) (*platformv1.UpdateContractResponse, *ApiError) {
request := connect.NewRequest(&platformv1.UpdateContractRequest{
Name: name,
Namespace: namespace,
ExcludeTags: excludeTags,
IncludeTags: includeTags,
RoutingUrl: &routingUrl,
AdmissionWebhookUrl: &admissionWebhookUrl,
AdmissionWebhookSecret: &admissionWebhookSecret,
Readme: &readme,
})
func (p *PlatformClient) UpdateContract(ctx context.Context, data *platformv1.UpdateContractRequest) (*platformv1.UpdateContractResponse, *ApiError) {
request := connect.NewRequest(data)

response, err := p.Client.UpdateContract(ctx, request)
if err != nil {
Expand Down
29 changes: 27 additions & 2 deletions internal/service/contract/resource_cosmo_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,19 @@ func (r *contractResource) Update(ctx context.Context, req resource.UpdateReques
readme = *data.Readme.ValueStringPointer()
}

_, apiError := r.client.UpdateContract(ctx, data.Name.ValueString(), data.Namespace.ValueString(), excludeTags, includeTags, data.RoutingURL.ValueString(), admissionWebhookUrl, admissionWebhookSecret, readme)
routingUrl := data.RoutingURL.ValueString()
requestData := &platformv1.UpdateContractRequest{
Name: data.Name.ValueString(),
Namespace: data.Namespace.ValueString(),
ExcludeTags: excludeTags,
IncludeTags: includeTags,
RoutingUrl: &routingUrl,
AdmissionWebhookUrl: &admissionWebhookUrl,
AdmissionWebhookSecret: &admissionWebhookSecret,
Readme: &readme,
}

_, apiError := r.client.UpdateContract(ctx, requestData)
if apiError != nil {
if api.IsContractCompositionFailedError(apiError) || api.IsSubgraphCompositionFailedError(apiError) {
utils.AddDiagnosticError(resp,
Expand Down Expand Up @@ -399,7 +411,20 @@ func (r *contractResource) createAndFetchContract(ctx context.Context, data cont
"includeTags": strings.Join(includeTags, ","),
})

_, apiError := r.client.CreateContract(ctx, data.Name.ValueString(), data.Namespace.ValueString(), data.SourceGraphName.ValueString(), data.RoutingURL.ValueString(), data.AdmissionWebhookUrl.ValueString(), data.AdmissionWebhookSecret.ValueString(), excludeTags, includeTags, data.Readme.ValueString())
readme := data.Readme.ValueString()
requestData := &platformv1.CreateContractRequest{
Name: data.Name.ValueString(),
Namespace: data.Namespace.ValueString(),
SourceGraphName: data.SourceGraphName.ValueString(),
RoutingUrl: data.RoutingURL.ValueString(),
AdmissionWebhookUrl: data.AdmissionWebhookUrl.ValueString(),
ExcludeTags: excludeTags,
Readme: &readme,
AdmissionWebhookSecret: data.AdmissionWebhookSecret.ValueStringPointer(),
IncludeTags: includeTags,
}

_, apiError := r.client.CreateContract(ctx, requestData)
if apiError != nil {
if api.IsContractCompositionFailedError(apiError) || api.IsSubgraphCompositionFailedError(apiError) {
utils.AddDiagnosticError(resp,
Expand Down

0 comments on commit 8d96032

Please sign in to comment.