Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding filter guide #71

Merged
merged 11 commits into from
Nov 1, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,6 +54,9 @@ open class SDK {
@Inject
lateinit var recommendationManager: RecommendationManager

@Inject
lateinit var productsManager: ProductsManager

@Inject
lateinit var trackEventManager: TrackEventManager

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.personalization.api.managers

import com.personalization.api.OnApiCallbackListener

interface ProductsManager {

fun getProductsList(
brands: String?,
merchants: String?,
categories: String?,
locations: String?,
limit: Int?,
page: Int?,
filters: Map<String, Any>?,
listener: OnApiCallbackListener? = null
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.personalization.api.responses.products.brand

import com.google.gson.annotations.SerializedName

data class Brand(
@SerializedName("name")
val name: String,
@SerializedName("picture")
val picture: String,
@SerializedName("count")
val count: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.personalization.api.responses.products.category

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?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.personalization.api.responses.products.filter

import com.google.gson.annotations.SerializedName

data class Filter(
@SerializedName("filter")
val filter: FilterDetails
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.personalization.api.responses.products.filter

import com.google.gson.annotations.SerializedName

data class FilterDetails(
@SerializedName("count")
val count: Int,
@SerializedName("priority")
val priority: Int,
@SerializedName("ranges")
val ranges: List<Int>?,
@SerializedName("values")
val values: List<FilterValue>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.personalization.api.responses.products.filter

import com.google.gson.annotations.SerializedName

data class FilterValue(
@SerializedName("value")
val value: String,
@SerializedName("count")
val count: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.personalization.api.responses.products.image

data class ImageUrlResized(
val sizeToPath: Map<String, String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.personalization.api.responses.products.price

import com.google.gson.annotations.SerializedName

data class PriceRange(
@SerializedName("min")
val min: Double,
@SerializedName("max")
val max: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.personalization.api.responses.products.price

import com.google.gson.annotations.SerializedName

data class PriceRangeItem(
@SerializedName("to")
val to: Double,
@SerializedName("count")
val count: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.personalization.api.responses.products.product

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<String>,
@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<ProductCategory>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.personalization.api.responses.products.product

data class ProductCategory(
val id: String,
val name: String,
val parent: String?,
val params: List<ProductParam>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.personalization.api.responses.products.product

data class ProductParam(
val key: String,
val values: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.personalization.api.responses.products.product

import com.google.gson.annotations.SerializedName
import com.personalization.api.responses.products.brand.Brand
import com.personalization.api.responses.products.category.Category
import com.personalization.api.responses.products.filter.Filter
import com.personalization.api.responses.products.price.PriceRange
import com.personalization.api.responses.products.price.PriceRangeItem

data class ProductsResponse(
@SerializedName("brands")
val brands: List<Brand>,
@SerializedName("categories")
val categories: List<Category>,
@SerializedName("filters")
val filters: List<Filter>,
@SerializedName("price_range")
val priceRange: PriceRange,
@SerializedName("products")
val products: List<Product>,
@SerializedName("products_total")
val productsTotal: Int,
@SerializedName("price_ranges")
val priceRanges: List<PriceRangeItem>,
@SerializedName("price_median")
val priceMedian: Double
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.personalization.di

import com.personalization.RegisterManager
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
import com.personalization.features.inAppNotification.impl.InAppNotificationManagerImpl
import com.personalization.features.products.impl.ProductsManagerImpl
import com.personalization.features.recommendation.impl.RecommendationManagerImpl
import com.personalization.features.search.impl.SearchManagerImpl
import com.personalization.features.trackEvent.impl.TrackEventManagerImpl
Expand Down Expand Up @@ -51,6 +53,14 @@ class SdkModule {
sendNetworkMethodUseCase = sendNetworkMethodUseCase
)

@Singleton
@Provides
fun provideProductsManager(
sendNetworkMethodUseCase: SendNetworkMethodUseCase
): ProductsManager = ProductsManagerImpl(
sendNetworkMethodUseCase = sendNetworkMethodUseCase
)

@Singleton
@Provides
fun provideTrackEventManager(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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,
) : ProductsManager {

override fun getProductsList(
brands: String?,
merchants: String?,
categories: String?,
locations: String?,
limit: Int?,
page: Int?,
filters: Map<String, Any>?,
listener: OnApiCallbackListener?
) {
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<String, Any>?,
): 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 = ""
}
}
Loading