From 9f17a559faa73edb1cff596e36cef685bd23295d Mon Sep 17 00:00:00 2001 From: Yun Cheng <129205442+ycheng-kickstarter@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:47:26 -0500 Subject: [PATCH] MBL-1251 get create attribution event graphqltransformer (#1969) MBL-1251 Add a new getCreateAttributionEvent GraphQLTransformer --- .../transformers/GraphQLTransformers.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt b/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt index 96941dcf3e..c265ef9b88 100644 --- a/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt +++ b/app/src/main/java/com/kickstarter/services/transformers/GraphQLTransformers.kt @@ -1,7 +1,10 @@ package com.kickstarter.services.transformers +import CreateAttributionEventMutation import TriggerThirdPartyEventMutation +import UserPrivacyQuery import com.google.android.gms.common.util.Base64Utils +import com.google.gson.Gson import com.kickstarter.libs.Permission import com.kickstarter.libs.utils.extensions.negate import com.kickstarter.mock.factories.RewardFactory @@ -28,6 +31,7 @@ import com.kickstarter.models.UserPrivacy import com.kickstarter.models.Video import com.kickstarter.models.Web import com.kickstarter.services.apiresponses.ShippingRulesEnvelope +import com.kickstarter.services.mutations.CreateAttributionEventData import com.kickstarter.viewmodels.usecases.TPEventInputData import fragment.FullProject import fragment.ProjectCard @@ -35,6 +39,7 @@ import org.jetbrains.annotations.Nullable import org.joda.time.DateTime import type.AppDataInput import type.CollaboratorPermission +import type.CreateAttributionEventInput import type.CreditCardPaymentType import type.CurrencyCode import type.RewardType @@ -854,3 +859,24 @@ fun getTriggerThirdPartyEventMutation(eventInput: TPEventInputData): TriggerThir return TriggerThirdPartyEventMutation.builder().triggerThirdPartyEventInput(graphInput) .build() } + +/** + * From KS dataModel CreateAttributionEventData, transform it into + * GraphQL defined mutation CreateAttributionEventMutation + */ +fun getCreateAttributionEventMutation(eventInput: CreateAttributionEventData, gson: Gson): CreateAttributionEventMutation { + + // Use gson to convert map -> JSON type to match mutation + val eventPropertiesJson = gson.toJson(eventInput.eventProperties) + + val graphInput = + CreateAttributionEventInput.builder() + .eventName(eventInput.eventName) + .eventProperties(eventPropertiesJson) + .projectId(eventInput.projectId) + .clientMutationId(eventInput.clientMutationId) + .build() + + return CreateAttributionEventMutation.builder().input(graphInput) + .build() +}