Skip to content

Commit

Permalink
MBL-1466: Create graphQL confirm address mutation (#2053)
Browse files Browse the repository at this point in the history
* Add support for create or update backing address mutation

* linter

---------

Co-authored-by: Leigh Douglas <[email protected]>
  • Loading branch information
leighdouglas and Leigh Douglas authored Jun 6, 2024
1 parent 28f9b43 commit 1a9059c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 10 deletions.
5 changes: 5 additions & 0 deletions app/src/main/graphql/createOrUpdateBackingAddress.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation CreateOrUpdateBackingAddress($input: CreateOrUpdateBackingAddressInput!) {
createOrUpdateBackingAddress(input : $input) {
success
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.kickstarter.services.apiresponses.updatesresponse.UpdatesGraphQlEnvel
import com.kickstarter.services.mutations.CreateAttributionEventData
import com.kickstarter.services.mutations.CreateBackingData
import com.kickstarter.services.mutations.CreateCheckoutData
import com.kickstarter.services.mutations.CreateOrUpdateBackingAddressData
import com.kickstarter.services.mutations.PostCommentData
import com.kickstarter.services.mutations.SavePaymentMethodData
import com.kickstarter.services.mutations.UpdateBackingData
Expand Down Expand Up @@ -299,6 +300,10 @@ open class MockApolloClientV2 : ApolloClientTypeV2 {
override fun createPaymentIntent(createPaymentIntentInput: CreatePaymentIntentInput): io.reactivex.Observable<String> {
return io.reactivex.Observable.empty()
}

override fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): io.reactivex.Observable<Boolean> {
return io.reactivex.Observable.empty()
}
}

open class MockApolloClient : ApolloClientType {
Expand Down Expand Up @@ -537,15 +542,6 @@ open class MockApolloClient : ApolloClientType {
}

override fun triggerThirdPartyEvent(eventInput: TPEventInputData): Observable<Pair<Boolean, String>> {
return Observable.just(
// TriggerThirdPartyEventMutation.Data(
// TriggerThirdPartyEventMutation
// .TriggerThirdPartyEvent(
// "",
// true
// )
// )
Pair(true, "")
)
return Observable.just(Pair(true, ""))
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import com.kickstarter.services.apiresponses.updatesresponse.UpdatesGraphQlEnvel
import com.kickstarter.services.mutations.CreateAttributionEventData
import com.kickstarter.services.mutations.CreateBackingData
import com.kickstarter.services.mutations.CreateCheckoutData
import com.kickstarter.services.mutations.CreateOrUpdateBackingAddressData
import com.kickstarter.services.mutations.PostCommentData
import com.kickstarter.services.mutations.SavePaymentMethodData
import com.kickstarter.services.mutations.UpdateBackingData
Expand All @@ -79,6 +80,7 @@ import com.kickstarter.services.transformers.complexRewardItemsTransformer
import com.kickstarter.services.transformers.decodeRelayId
import com.kickstarter.services.transformers.encodeRelayId
import com.kickstarter.services.transformers.getCreateAttributionEventMutation
import com.kickstarter.services.transformers.getCreateOrUpdateBackingAddressMutation
import com.kickstarter.services.transformers.getTriggerThirdPartyEventMutation
import com.kickstarter.services.transformers.projectTransformer
import com.kickstarter.services.transformers.rewardTransformer
Expand Down Expand Up @@ -192,6 +194,7 @@ interface ApolloClientTypeV2 {
): Observable<Pair<String, Boolean>>

fun createAttributionEvent(eventInput: CreateAttributionEventData): Observable<Boolean>
fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): Observable<Boolean>
}

private const val PAGE_SIZE = 25
Expand Down Expand Up @@ -1630,4 +1633,32 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient
return@defer ps
}
}

override fun createOrUpdateBackingAddress(eventInput: CreateOrUpdateBackingAddressData): Observable<Boolean> {
return Observable.defer {
val ps = PublishSubject.create<Boolean>()

val mutation = getCreateOrUpdateBackingAddressMutation(eventInput)

service.mutate(mutation)
.enqueue(object : ApolloCall.Callback<CreateOrUpdateBackingAddressMutation.Data>() {
override fun onFailure(exception: ApolloException) {
ps.onError(exception)
}

override fun onResponse(response: Response<CreateOrUpdateBackingAddressMutation.Data>) {
if (response.hasErrors()) {
ps.onError(Exception(response.errors?.first()?.message ?: ""))
}

response.data?.let {
val isSuccess = it.createOrUpdateBackingAddress()?.success() ?: false
ps.onNext(isSuccess)
}
ps.onComplete()
}
})
return@defer ps
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kickstarter.services.mutations

/***
* CreateOrUpdateBackingAddressData is the corresponding internal data model to the GraphQL model
* [CreateOrUpdateBackingAddressInput]
*/
data class CreateOrUpdateBackingAddressData(
val backingId: String,
val addressID: String,
val clientMutationId: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kickstarter.services.transformers

import CreateAttributionEventMutation
import CreateOrUpdateBackingAddressMutation
import TriggerThirdPartyEventMutation
import UserPrivacyQuery
import com.google.android.gms.common.util.Base64Utils
Expand Down Expand Up @@ -32,6 +33,7 @@ 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.services.mutations.CreateOrUpdateBackingAddressData
import com.kickstarter.viewmodels.usecases.TPEventInputData
import fragment.FullProject
import fragment.ProjectCard
Expand All @@ -40,6 +42,7 @@ import org.joda.time.DateTime
import type.AppDataInput
import type.CollaboratorPermission
import type.CreateAttributionEventInput
import type.CreateOrUpdateBackingAddressInput
import type.CreditCardPaymentType
import type.CurrencyCode
import type.RewardType
Expand Down Expand Up @@ -886,3 +889,13 @@ fun getCreateAttributionEventMutation(eventInput: CreateAttributionEventData, gs
return CreateAttributionEventMutation.builder().input(graphInput)
.build()
}

fun getCreateOrUpdateBackingAddressMutation(eventInput: CreateOrUpdateBackingAddressData): CreateOrUpdateBackingAddressMutation {
val graphInput =
CreateOrUpdateBackingAddressInput.builder()
.addressId(eventInput.addressID)
.backingId(eventInput.backingId)
.build()

return CreateOrUpdateBackingAddressMutation.builder().input(graphInput).build()
}

0 comments on commit 1a9059c

Please sign in to comment.