From 61346e7b4cbd65ad915d7a3af959f14110347531 Mon Sep 17 00:00:00 2001 From: Daniel Green Date: Thu, 31 Oct 2024 13:03:27 +0200 Subject: [PATCH] feat: Added request with handling response --- .../main/kotlin/com/personalization/SDK.kt | 4 ++ .../api/responses/products/Brand.kt | 12 ++++ .../api/responses/products/Category.kt | 20 +++++++ .../api/responses/products/Filter.kt | 8 +++ .../api/responses/products/FilterDetails.kt | 14 +++++ .../api/responses/products/FilterValue.kt | 10 ++++ .../responses}/products/ImageUrlResized.kt | 4 +- .../api/responses/products/PriceRange.kt | 10 ++++ .../api/responses/products/PriceRangeItem.kt | 10 ++++ .../api/responses/products/Product.kt | 55 +++++++++++++++++++ .../responses}/products/ProductCategory.kt | 2 +- .../responses}/products/ProductParam.kt | 2 +- .../responses/products/ProductsResponse.kt | 22 ++++++++ .../products/impl/ProductsManagerImpl.kt | 52 +++++++++++++++++- .../sdk/data/di/RepositoriesModule.kt | 2 - .../sdk/domain/models/products/ApiResponse.kt | 12 ---- .../sdk/domain/models/products/Brand.kt | 7 --- .../sdk/domain/models/products/Category.kt | 11 ---- .../sdk/domain/models/products/Filter.kt | 5 -- .../domain/models/products/FilterDetails.kt | 8 --- .../sdk/domain/models/products/FilterValue.kt | 6 -- .../sdk/domain/models/products/PriceRange.kt | 6 -- .../domain/models/products/PriceRangeItem.kt | 6 -- .../sdk/domain/models/products/Product.kt | 28 ---------- 24 files changed, 219 insertions(+), 97 deletions(-) create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Brand.kt create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Category.kt create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Filter.kt create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterDetails.kt create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterValue.kt rename personalization-sdk/src/main/kotlin/com/personalization/{sdk/domain/models => api/responses}/products/ImageUrlResized.kt (55%) create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRange.kt create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRangeItem.kt create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Product.kt rename personalization-sdk/src/main/kotlin/com/personalization/{sdk/domain/models => api/responses}/products/ProductCategory.kt (70%) rename personalization-sdk/src/main/kotlin/com/personalization/{sdk/domain/models => api/responses}/products/ProductParam.kt (58%) create mode 100644 personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductsResponse.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ApiResponse.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Brand.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Category.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Filter.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterDetails.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterValue.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRange.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRangeItem.kt delete mode 100644 personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Product.kt diff --git a/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt b/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt index 065fc9dc..d2507d12 100644 --- a/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt +++ b/personalization-sdk/src/main/kotlin/com/personalization/SDK.kt @@ -10,6 +10,7 @@ import com.personalization.Params.InternalParameter import com.personalization.Params.TrackEvent import com.personalization.api.OnApiCallbackListener import com.personalization.api.managers.InAppNotificationManager +import com.personalization.api.managers.ProductsManager import com.personalization.api.managers.RecommendationManager import com.personalization.api.managers.SearchManager import com.personalization.api.managers.TrackEventManager @@ -53,6 +54,9 @@ open class SDK { @Inject lateinit var recommendationManager: RecommendationManager + @Inject + lateinit var productsManager: ProductsManager + @Inject lateinit var trackEventManager: TrackEventManager diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Brand.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Brand.kt new file mode 100644 index 00000000..506d0f16 --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Brand.kt @@ -0,0 +1,12 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class Brand( + @SerializedName("name") + val name: String, + @SerializedName("picture") + val picture: String, + @SerializedName("count") + val count: Int +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Category.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Category.kt new file mode 100644 index 00000000..c5bfe6db --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Category.kt @@ -0,0 +1,20 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class Category( + @SerializedName("id") + val id: String, + @SerializedName("name") + val name: String, + @SerializedName("url") + val url: String, + @SerializedName("url_handle") + val urlHandle: String, + @SerializedName("count") + val count: Int, + @SerializedName("parent") + val parent: String?, + @SerializedName("alias") + val alias: String? +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Filter.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Filter.kt new file mode 100644 index 00000000..ddb86ac1 --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Filter.kt @@ -0,0 +1,8 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class Filter( + @SerializedName("filter") + val filter: FilterDetails +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterDetails.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterDetails.kt new file mode 100644 index 00000000..7777e302 --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterDetails.kt @@ -0,0 +1,14 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class FilterDetails( + @SerializedName("count") + val count: Int, + @SerializedName("priority") + val priority: Int, + @SerializedName("ranges") + val ranges: List?, + @SerializedName("values") + val values: List +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterValue.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterValue.kt new file mode 100644 index 00000000..81204359 --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/FilterValue.kt @@ -0,0 +1,10 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class FilterValue( + @SerializedName("value") + val value: String, + @SerializedName("count") + val count: Int +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ImageUrlResized.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ImageUrlResized.kt similarity index 55% rename from personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ImageUrlResized.kt rename to personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ImageUrlResized.kt index 739b04d0..abd1f972 100644 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ImageUrlResized.kt +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ImageUrlResized.kt @@ -1,5 +1,5 @@ -package com.personalization.sdk.domain.models.products +package com.personalization.api.responses.products data class ImageUrlResized( val sizeToPath: Map -) \ No newline at end of file +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRange.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRange.kt new file mode 100644 index 00000000..770cd08f --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRange.kt @@ -0,0 +1,10 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class PriceRange( + @SerializedName("min") + val min: Double, + @SerializedName("max") + val max: Double +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRangeItem.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRangeItem.kt new file mode 100644 index 00000000..e021f9a6 --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/PriceRangeItem.kt @@ -0,0 +1,10 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class PriceRangeItem( + @SerializedName("to") + val to: Double, + @SerializedName("count") + val count: Int +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Product.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Product.kt new file mode 100644 index 00000000..c72b80f0 --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/Product.kt @@ -0,0 +1,55 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName +import com.personalization.api.responses.product.ImageUrlResized + +data class Product( + @SerializedName("brand") + val brand: String, + @SerializedName("currency") + val currency: String, + @SerializedName("id") + val id: String, + @SerializedName("is_new") + val isNew: Boolean? = null, + @SerializedName("name") + val name: String, + @SerializedName("old_price") + val oldPrice: String = "0", + @SerializedName("price") + val price: Double, + @SerializedName("price_formatted") + val priceFormatted: String, + @SerializedName("price_full_formatted") + val priceFullFormatted: String, + @SerializedName("picture") + val picture: String, + @SerializedName("url") + val url: String, + @SerializedName("description") + val description: String, + @SerializedName("category_ids") + val categoryIds: List, + @SerializedName("fashion_feature") + val fashionFeature: String?, + @SerializedName("fashion_gender") + val fashionGender: String?, + @SerializedName("sales_rate") + val salesRate: Int, + @SerializedName("relative_sales_rate") + val relativeSalesRate: Double, + @SerializedName("image_url") + val imageUrl: String, + @SerializedName("image_url_handle") + val imageUrlHandle: String, + @SerializedName("image_url_resized") + val imageUrlResized: ImageUrlResized, + @SerializedName("_id") + val internalId: String, + @SerializedName("group_id") + val groupId: String, + @SerializedName("barcode") + val barcode: String, + @SerializedName("categories") + val categories: List +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ProductCategory.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductCategory.kt similarity index 70% rename from personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ProductCategory.kt rename to personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductCategory.kt index 8fc54780..f6130de5 100644 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ProductCategory.kt +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductCategory.kt @@ -1,4 +1,4 @@ -package com.personalization.sdk.domain.models.products +package com.personalization.api.responses.products data class ProductCategory( val id: String, diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ProductParam.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductParam.kt similarity index 58% rename from personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ProductParam.kt rename to personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductParam.kt index 92a3b6ef..511e256d 100644 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ProductParam.kt +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductParam.kt @@ -1,4 +1,4 @@ -package com.personalization.sdk.domain.models.products +package com.personalization.api.responses.products data class ProductParam( val key: String, diff --git a/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductsResponse.kt b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductsResponse.kt new file mode 100644 index 00000000..2777507d --- /dev/null +++ b/personalization-sdk/src/main/kotlin/com/personalization/api/responses/products/ProductsResponse.kt @@ -0,0 +1,22 @@ +package com.personalization.api.responses.products + +import com.google.gson.annotations.SerializedName + +data class ProductsResponse( + @SerializedName("brands") + val brands: List, + @SerializedName("categories") + val categories: List, + @SerializedName("filters") + val filters: List, + @SerializedName("price_range") + val priceRange: PriceRange, + @SerializedName("products") + val products: List, + @SerializedName("products_total") + val productsTotal: Int, + @SerializedName("price_ranges") + val priceRanges: List, + @SerializedName("price_median") + val priceMedian: Double +) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/features/products/impl/ProductsManagerImpl.kt b/personalization-sdk/src/main/kotlin/com/personalization/features/products/impl/ProductsManagerImpl.kt index acb6c7fe..8afd8dab 100644 --- a/personalization-sdk/src/main/kotlin/com/personalization/features/products/impl/ProductsManagerImpl.kt +++ b/personalization-sdk/src/main/kotlin/com/personalization/features/products/impl/ProductsManagerImpl.kt @@ -1,12 +1,14 @@ package com.personalization.features.products.impl +import com.personalization.Params import com.personalization.api.OnApiCallbackListener import com.personalization.api.managers.ProductsManager import com.personalization.sdk.domain.usecases.network.SendNetworkMethodUseCase import javax.inject.Inject +import org.json.JSONObject internal class ProductsManagerImpl @Inject constructor( - private val sendNetworkMethodUseCase: SendNetworkMethodUseCase + private val sendNetworkMethodUseCase: SendNetworkMethodUseCase, ) : ProductsManager { override fun getProductsList( @@ -19,6 +21,52 @@ internal class ProductsManagerImpl @Inject constructor( filters: Map?, listener: OnApiCallbackListener? ) { - TODO("Not yet implemented") + sendNetworkMethodUseCase.getAsync( + method = GET_PRODUCT_LIST_REQUEST, + params = Params().buildParams( + brands = brands, + merchants = merchants, + categories = categories, + locations = locations, + limit = limit, + page = page, + filters = filters, + ).build(), + listener = listener + ) + } + + private fun Params.buildParams( + brands: String?, + merchants: String?, + categories: String?, + locations: String?, + limit: Int?, + page: Int?, + filters: Map?, + ): Params = this.apply { + limit?.let { put(LIMIT_KEY, it) } + page?.let { put(PAGE_KEY, it) } + locations?.let { put(LOCATION_KEY, it) } + brands?.let { put(BRANDS_KEY, it) } + merchants?.let { put(MERCHANTS_KEY, it) } + categories?.let { put(CATEGORIES_KEY, it) } + + filters?.takeIf { it.isNotEmpty() }?.let { + val filtersJson = JSONObject(it).toString() + put(FILTERS_KEY, filtersJson) + } + } + + companion object { + const val GET_PRODUCT_LIST_REQUEST = "products" + + private const val LIMIT_KEY = "limit" + private const val PAGE_KEY = "page" + private const val LOCATION_KEY = "locations" + private const val BRANDS_KEY = "brands" + private const val MERCHANTS_KEY = "merchants" + private const val CATEGORIES_KEY = "categories" + private const val FILTERS_KEY = "" } } diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/di/RepositoriesModule.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/di/RepositoriesModule.kt index ca89cda9..c4cce075 100644 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/di/RepositoriesModule.kt +++ b/personalization-sdk/src/main/kotlin/com/personalization/sdk/data/di/RepositoriesModule.kt @@ -34,6 +34,4 @@ abstract class RepositoriesModule { @Binds abstract fun bindNotificationRepository(impl: NotificationRepositoryImpl): NotificationRepository -// @Binds -// abstract fun bindProductsRepository(impl: PreferencesRepositoryImpl): PreferencesRepository } diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ApiResponse.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ApiResponse.kt deleted file mode 100644 index fa4ac849..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/ApiResponse.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class ApiResponse( - val brands: List, - val categories: List, - val filters: List, - val priceRange: PriceRange, - val products: List, - val productsTotal: Int, - val priceRanges: List, - val priceMedian: Double -) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Brand.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Brand.kt deleted file mode 100644 index 38b680cd..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Brand.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class Brand( - val name: String, - val picture: String, - val count: Int -) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Category.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Category.kt deleted file mode 100644 index d515e27b..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Category.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class Category( - val id: String, - val name: String, - val url: String, - val urlHandle: String, - val count: Int, - val parent: String?, - val alias: String? -) \ No newline at end of file diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Filter.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Filter.kt deleted file mode 100644 index 5d03f125..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Filter.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class Filter( - val filter: FilterDetails -) \ No newline at end of file diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterDetails.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterDetails.kt deleted file mode 100644 index 5ebd9934..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterDetails.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class FilterDetails( - val count: Int, - val priority: Int, - val ranges: List?, - val values: List -) \ No newline at end of file diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterValue.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterValue.kt deleted file mode 100644 index ade7f007..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/FilterValue.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class FilterValue( - val value: String, - val count: Int -) \ No newline at end of file diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRange.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRange.kt deleted file mode 100644 index 6902a874..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRange.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class PriceRange( - val min: Double, - val max: Double -) \ No newline at end of file diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRangeItem.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRangeItem.kt deleted file mode 100644 index f0b88cad..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/PriceRangeItem.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class PriceRangeItem( - val to: Double, - val count: Int -) diff --git a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Product.kt b/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Product.kt deleted file mode 100644 index 823f389a..00000000 --- a/personalization-sdk/src/main/kotlin/com/personalization/sdk/domain/models/products/Product.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.personalization.sdk.domain.models.products - -data class Product( - val brand: String, - val currency: String, - val id: String, - val isNew: Boolean? = null, - val name: String, - val oldPrice: String = "0", - val price: Double, - val priceFormatted: String, - val priceFullFormatted: String, - val picture: String, - val url: String, - val description: String, - val categoryIds: List, - val fashionFeature: String?, - val fashionGender: String?, - val salesRate: Int, - val relativeSalesRate: Int, - val imageUrl: String, - val imageUrlHandle: String, - val imageUrlResized: ImageUrlResized, - val internalId: String, - val groupId: String, - val barcode: String, - val categories: List -) \ No newline at end of file