-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from rees46/feat/add-get-client-shopping-cart-…
…api-method Feat/add get client shopping cart api method
- Loading branch information
Showing
8 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
personalization-sdk/src/main/kotlin/com/personalization/api/managers/CartManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.personalization.api.managers | ||
|
||
import com.personalization.api.responses.cart.CartContent | ||
|
||
interface CartManager { | ||
|
||
/** | ||
* Request client's shopping cart content | ||
* | ||
* @param onGetCartContent Callback for cart content | ||
* @param onError Callback for error | ||
*/ | ||
fun getClientShoppingCartContent( | ||
onGetCartContent: (CartContent) -> Unit, | ||
onError: (code: Int, msg: String?) -> Unit = { _: Int, _: String? -> } | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
personalization-sdk/src/main/kotlin/com/personalization/api/responses/cart/CartContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.personalization.api.responses.cart | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CartContent( | ||
@SerializedName("items") val content: List<CartItem> | ||
) |
8 changes: 8 additions & 0 deletions
8
...ization-sdk/src/main/kotlin/com/personalization/api/responses/cart/CartContentResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.personalization.api.responses.cart | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CartContentResponse( | ||
@SerializedName("status") val status: String, | ||
@SerializedName("data") val cartContent: CartContent | ||
) |
8 changes: 8 additions & 0 deletions
8
personalization-sdk/src/main/kotlin/com/personalization/api/responses/cart/CartItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.personalization.api.responses.cart | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CartItem( | ||
@SerializedName("uniqid") val id: String, | ||
@SerializedName("quantity") val quantity: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
personalization-sdk/src/main/kotlin/com/personalization/features/cart/CartManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.personalization.features.cart | ||
|
||
import com.google.gson.Gson | ||
import com.personalization.Params | ||
import com.personalization.api.OnApiCallbackListener | ||
import com.personalization.api.managers.CartManager | ||
import com.personalization.api.responses.cart.CartContent | ||
import com.personalization.api.responses.cart.CartContentResponse | ||
import com.personalization.sdk.domain.usecases.network.SendNetworkMethodUseCase | ||
import org.json.JSONObject | ||
import javax.inject.Inject | ||
|
||
private const val GET_CLIENT_SHOPPING_CART = "products/cart" | ||
|
||
internal class CartManagerImpl @Inject constructor( | ||
private val sendNetworkMethodUseCase: SendNetworkMethodUseCase, | ||
) : CartManager { | ||
|
||
override fun getClientShoppingCartContent( | ||
onGetCartContent: (CartContent) -> Unit, | ||
onError: (code: Int, msg: String?) -> Unit | ||
) { | ||
sendNetworkMethodUseCase.getAsync( | ||
method = GET_CLIENT_SHOPPING_CART, | ||
params = Params().build(), | ||
listener = object : OnApiCallbackListener() { | ||
override fun onSuccess(response: JSONObject?) { | ||
response?.let { | ||
val cartContentResponse = Gson().fromJson( | ||
it.toString(), CartContentResponse::class.java | ||
) | ||
onGetCartContent(cartContentResponse.cartContent) | ||
} | ||
} | ||
|
||
override fun onError(code: Int, msg: String?) { | ||
onError(code, msg) | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters